Преглед изворни кода

Merge branch 'master' into pre-master

yaodaoseng пре 4 месеци
родитељ
комит
adb01b63f0

+ 13 - 0
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/thread/ThreadPoolFactory.java

@@ -26,6 +26,14 @@ public final class ThreadPoolFactory {
             new ThreadFactoryBuilder().setNameFormat("Feature-%d").build(),
             new ThreadPoolExecutor.AbortPolicy());
 
+    private final static ExecutorService SCORE = new CommonThreadPoolExecutor(
+            512,
+            512,
+            0L, TimeUnit.SECONDS,
+            new LinkedBlockingQueue<>(5000),
+            new ThreadFactoryBuilder().setNameFormat("SCORE-%d").build(),
+            new ThreadPoolExecutor.AbortPolicy());
+
     public static ExecutorService defaultPool() {
         return DEFAULT;
     }
@@ -34,4 +42,9 @@ public final class ThreadPoolFactory {
         return FEATURE;
     }
 
+    public static ExecutorService score() {
+        return SCORE;
+    }
+
+
 }

+ 12 - 2
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/v2/PredictStrategyBy673.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
@@ -13,6 +14,9 @@ import java.util.*;
 @Slf4j
 @Service
 public class PredictStrategyBy673 extends ThresholdPredictStrategy {
+
+    @Value("${filter.with.region:1}")
+    private String filterWithRegion;
     @Override
     Map<String, Double> thresholdConfig(PredictContext ctx) {
 
@@ -22,7 +26,14 @@ public class PredictStrategyBy673 extends ThresholdPredictStrategy {
 
         try {
             JSONObject json = ctx.getExpConfigMap().getOrDefault("673", new JSONObject());
-            JSONObject configJson = json.getJSONObject(String.format("%s:%s", ctx.getUserExternalSource(), ctx.getShareLayer()));
+            String configKey = String.format("%s:%s", ctx.getUserExternalSource(), ctx.getShareLayer());
+            if("1".equals(filterWithRegion) && StringUtils.isNotBlank(configKey)) {
+                String region = StringUtils.isBlank(ctx.getRegion()) ? "未知地区" : ctx.getRegion();
+                String city = StringUtils.isBlank(ctx.getCity()) ? "未知地区" : ctx.getCity();
+                configKey = configKey + ":" + region + "_" + city;
+                log.info( "PredictStrategyBy673 configKey: {}", configKey);
+            }
+            JSONObject configJson = json.getJSONObject(configKey);
             if (MapUtils.isEmpty(configJson)) {
                 return Collections.emptyMap();
             }
@@ -57,7 +68,6 @@ public class PredictStrategyBy673 extends ThresholdPredictStrategy {
                 break;
             }
         }
-
         Map<String, Object> rtnMap = new HashMap<>();
         if (score < threshold) {
             rtnMap.putAll(rtnAdPredict(ctx));

+ 1 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/scorer/PAIScorer.java

@@ -94,7 +94,7 @@ public class PAIScorer extends AbstractScorer {
             batches.add(new ArrayList<>(items.subList(i, Math.min(i + batchSize, items.size()))));
         }
 
-        ExecutorService executor = ThreadPoolFactory.defaultPool();
+        ExecutorService executor = ThreadPoolFactory.score();
         List<Future<List<AdRankItem>>> futures = new ArrayList<>();
 
         for (List<AdRankItem> batch : batches) {

+ 1 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/scorer/PAIScorerV2.java

@@ -94,7 +94,7 @@ public class PAIScorerV2 extends AbstractScorer {
             batches.add(new ArrayList<>(items.subList(i, Math.min(i + batchSize, items.size()))));
         }
 
-        ExecutorService executor = ThreadPoolFactory.defaultPool();
+        ExecutorService executor = ThreadPoolFactory.score();
         List<Future<List<AdRankItem>>> futures = new ArrayList<>();
 
         for (List<AdRankItem> batch : batches) {