丁云鹏 7 months ago
parent
commit
ca678b5bc8

+ 26 - 49
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/RankStrategyXGBAutoUpdateModel688.java

@@ -157,42 +157,29 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
 
         long time2 = System.currentTimeMillis();
         // feature3
-        CountDownLatch cdl2 = new CountDownLatch(adRankItems.size());
+        CountDownLatch cdl2 = new CountDownLatch(adRankItems.size() * 2);
         for (AdRankItem item : adRankItems) {
+            String cidStr = String.valueOf(item.getAdId());
+            Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
+            Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
+            String title = b1Feature.getOrDefault("cidtitle", "");
             ThreadPoolFactory.defaultPool().submit(() -> {
                 try {
-                    String cidStr = String.valueOf(item.getAdId());
-                    Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
-                    Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
-                    String title = b1Feature.getOrDefault("cidtitle", "");
                     this.handleE1AndE2Feature(e1Feature, e2Feature, title, item.getFeatureMap());
                 } finally {
                     cdl2.countDown();
                 }
             });
-        }
-        try {
-            cdl2.await(100, TimeUnit.MILLISECONDS);
-        } catch (Exception e) {
-            log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
-        }
-        long time31 = System.currentTimeMillis();
-        CountDownLatch cdl3 = new CountDownLatch(adRankItems.size());
-        for (AdRankItem item : adRankItems) {
             ThreadPoolFactory.defaultPool().submit(() -> {
                 try {
-                    String cidStr = String.valueOf(item.getAdId());
-                    Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
-                    Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
-                    String title = b1Feature.getOrDefault("cidtitle", "");
                     this.handleD3AndB1Feature(d3Feature, title, item.getFeatureMap());
                 } finally {
-                    cdl3.countDown();
+                    cdl2.countDown();
                 }
             });
         }
         try {
-            cdl3.await(100, TimeUnit.MILLISECONDS);
+            cdl2.await(150, TimeUnit.MILLISECONDS);
         } catch (Exception e) {
             log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
         }
@@ -200,33 +187,23 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
         // feature4
         long time3 = System.currentTimeMillis();
         // 分桶
-        if (similarityConcurrent) {
-            this.readBucketFile();
-            userFeatureMap = this.featureBucket(userFeatureMap);
-            CountDownLatch cdl4 = new CountDownLatch(adRankItems.size());
-            for (AdRankItem adRankItem : adRankItems) {
-                ThreadPoolFactory.feature().submit(() -> {
-                    try {
-                        Map<String, String> featureMap = adRankItem.getFeatureMap();
-                        adRankItem.setFeatureMap(this.featureBucket(featureMap));
-                    } finally{
-                        cdl4.countDown();
-                    }
-                });
-            }
-            try {
-                cdl4.await(100, TimeUnit.MILLISECONDS);
-            } catch (Exception e) {
-                log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
-            }
-
-        } else {
-            this.readBucketFile();
-            userFeatureMap = this.featureBucket(userFeatureMap);
-            for (AdRankItem adRankItem : adRankItems) {
-                Map<String, String> featureMap = adRankItem.getFeatureMap();
-                adRankItem.setFeatureMap(this.featureBucket(featureMap));
-            }
+        this.readBucketFile();
+        userFeatureMap = this.featureBucket(userFeatureMap);
+        CountDownLatch cdl4 = new CountDownLatch(adRankItems.size());
+        for (AdRankItem adRankItem : adRankItems) {
+            ThreadPoolFactory.feature().submit(() -> {
+                try {
+                    Map<String, String> featureMap = adRankItem.getFeatureMap();
+                    adRankItem.setFeatureMap(this.featureBucket(featureMap));
+                } finally {
+                    cdl4.countDown();
+                }
+            });
+        }
+        try {
+            cdl4.await(100, TimeUnit.MILLISECONDS);
+        } catch (Exception e) {
+            log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
         }
         long time4 = System.currentTimeMillis();
         // 打分排序
@@ -274,9 +251,9 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
         }
 
         long time6 = System.currentTimeMillis();
-        log.info("cost={}, feature1={}, feature2={}, feature31={}, feature32={}, feature4={}, getScorerPipeline={}, " +
+        log.info("cost={}, feature1={}, feature2={}, feature3={}, feature4={}, getScorerPipeline={}, " +
                         "loop={}, adIdSize={}, adRankItemsSize={}",
-                time6 - start, time1 - start, time2 - time1, time31 - time2, time3 - time31, time4 - time3,
+                time6 - start, time1 - start, time2 - time1, time3 - time2, time4 - time3,
                 time5 - time4, time6 - time5, request.getAdIdList().size(), adRankItems.size());
 
         result.sort(ComparatorUtil.equalsRandomComparator());