|
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
+import java.util.concurrent.Future;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -79,67 +80,141 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
|
|
|
List<AdRankItem> adRankItems = new ArrayList<>(request.getAdIdList().size());
|
|
|
Random random = new Random();
|
|
|
- for (AdPlatformCreativeDTO dto : request.getAdIdList()) {
|
|
|
- AdRankItem adRankItem = new AdRankItem();
|
|
|
- adRankItem.setAdId(dto.getCreativeId());
|
|
|
- adRankItem.setCreativeCode(dto.getCreativeCode());
|
|
|
- adRankItem.setAdVerId(dto.getAdVerId());
|
|
|
- adRankItem.setVideoId(request.getVideoId());
|
|
|
- adRankItem.setCpa(dto.getCpa());
|
|
|
- adRankItem.setId(dto.getAdId());
|
|
|
- adRankItem.setCampaignId(dto.getCampaignId());
|
|
|
- adRankItem.setCpm(ObjUtil.nullOrDefault(dto.getCpm(), 90).doubleValue());
|
|
|
- adRankItem.setRandom(random.nextInt(1000));
|
|
|
+ long time2 = 0;
|
|
|
+ if (similarityConcurrent) {
|
|
|
+ for (AdPlatformCreativeDTO dto : request.getAdIdList()) {
|
|
|
+ AdRankItem adRankItem = new AdRankItem();
|
|
|
+ adRankItem.setAdId(dto.getCreativeId());
|
|
|
+ adRankItem.setCreativeCode(dto.getCreativeCode());
|
|
|
+ adRankItem.setAdVerId(dto.getAdVerId());
|
|
|
+ adRankItem.setVideoId(request.getVideoId());
|
|
|
+ adRankItem.setCpa(dto.getCpa());
|
|
|
+ adRankItem.setId(dto.getAdId());
|
|
|
+ adRankItem.setCampaignId(dto.getCampaignId());
|
|
|
+ adRankItem.setCpm(ObjUtil.nullOrDefault(dto.getCpm(), 90).doubleValue());
|
|
|
+ adRankItem.setRandom(random.nextInt(1000));
|
|
|
|
|
|
- String cidStr = dto.getCreativeId().toString();
|
|
|
- Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
|
- 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 cidStr = dto.getCreativeId().toString();
|
|
|
+ Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
|
+ Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
|
|
|
+ Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
|
|
|
|
- Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(dto.getAdVerId(), new HashMap<>());
|
|
|
+ Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(dto.getAdVerId(), new HashMap<>());
|
|
|
|
|
|
- Map<String, String> d1Feature = cidFeature.getOrDefault("alg_cid_feature_vid_cf", new HashMap<>());
|
|
|
+ Map<String, String> d1Feature = cidFeature.getOrDefault("alg_cid_feature_vid_cf", new HashMap<>());
|
|
|
|
|
|
- this.handleB1Feature(b1Feature, cidFeatureMap, cidStr);
|
|
|
+ this.handleB1Feature(b1Feature, cidFeatureMap, cidStr);
|
|
|
|
|
|
- this.handleB2ToB5AndB8ToB9Feature(cidFeature, adVerFeature, cidFeatureMap);
|
|
|
+ this.handleB2ToB5AndB8ToB9Feature(cidFeature, adVerFeature, cidFeatureMap);
|
|
|
|
|
|
- this.handleB6ToB7Feature(cidFeature, cidFeatureMap);
|
|
|
+ this.handleB6ToB7Feature(cidFeature, cidFeatureMap);
|
|
|
|
|
|
- this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
|
|
|
+ this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
|
|
|
|
|
|
- this.handleD1Feature(d1Feature, cidFeatureMap);
|
|
|
+ this.handleD1Feature(d1Feature, cidFeatureMap);
|
|
|
|
|
|
- this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
|
|
|
+ this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
|
|
|
|
|
|
- // adRankItem.setFeatureMap(cidFeatureMap);
|
|
|
+ // adRankItem.setFeatureMap(cidFeatureMap);
|
|
|
|
|
|
- adRankItems.add(adRankItem);
|
|
|
+ adRankItems.add(adRankItem);
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ time2 = System.currentTimeMillis();
|
|
|
+ CountDownLatch cdl = 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.handleE1AndE2Feature(e1Feature, e2Feature, title, item.getFeatureMap());
|
|
|
+ this.handleD3AndB1Feature(d3Feature, title, item.getFeatureMap());
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ cdl.await(200, TimeUnit.MILLISECONDS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ List<Future<AdRankItem>> futures = new ArrayList<>();
|
|
|
+ for (AdPlatformCreativeDTO dto : request.getAdIdList()) {
|
|
|
+ Future<AdRankItem> future = ThreadPoolFactory.defaultPool().submit(() -> {
|
|
|
+ AdRankItem adRankItem = new AdRankItem();
|
|
|
+ adRankItem.setAdId(dto.getCreativeId());
|
|
|
+ adRankItem.setCreativeCode(dto.getCreativeCode());
|
|
|
+ adRankItem.setAdVerId(dto.getAdVerId());
|
|
|
+ adRankItem.setVideoId(request.getVideoId());
|
|
|
+ adRankItem.setCpa(dto.getCpa());
|
|
|
+ adRankItem.setId(dto.getAdId());
|
|
|
+ adRankItem.setCampaignId(dto.getCampaignId());
|
|
|
+ adRankItem.setCpm(ObjUtil.nullOrDefault(dto.getCpm(), 90).doubleValue());
|
|
|
+ adRankItem.setRandom(random.nextInt(1000));
|
|
|
+
|
|
|
+ String cidStr = dto.getCreativeId().toString();
|
|
|
+ Map<String, String> cidFeatureMap = adRankItem.getFeatureMap();
|
|
|
+ Map<String, Map<String, String>> cidFeature = allCidFeature.getOrDefault(cidStr, new HashMap<>());
|
|
|
+ Map<String, String> b1Feature = cidFeature.getOrDefault("alg_cid_feature_basic_info", new HashMap<>());
|
|
|
+
|
|
|
+ Map<String, Map<String, String>> adVerFeature = allAdVerFeature.getOrDefault(dto.getAdVerId(), new HashMap<>());
|
|
|
+
|
|
|
+ Map<String, String> d1Feature = cidFeature.getOrDefault("alg_cid_feature_vid_cf", new HashMap<>());
|
|
|
+
|
|
|
+ this.handleB1Feature(b1Feature, cidFeatureMap, cidStr);
|
|
|
+
|
|
|
+ this.handleB2ToB5AndB8ToB9Feature(cidFeature, adVerFeature, cidFeatureMap);
|
|
|
|
|
|
- long time2 = System.currentTimeMillis();
|
|
|
+ this.handleB6ToB7Feature(cidFeature, cidFeatureMap);
|
|
|
|
|
|
+ this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
|
|
|
|
|
|
- CountDownLatch cdl = new CountDownLatch(adRankItems.size());
|
|
|
- for (AdRankItem item : adRankItems) {
|
|
|
- ThreadPoolFactory.defaultPool().submit(() -> {
|
|
|
+ this.handleD1Feature(d1Feature, cidFeatureMap);
|
|
|
+
|
|
|
+ this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
|
|
|
+
|
|
|
+ // adRankItem.setFeatureMap(cidFeatureMap);
|
|
|
+
|
|
|
+ return adRankItem;
|
|
|
+ });
|
|
|
+ futures.add(future);
|
|
|
+ }
|
|
|
+ for (Future<AdRankItem> future : futures) {
|
|
|
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());
|
|
|
- this.handleD3AndB1Feature(d3Feature, title, item.getFeatureMap());
|
|
|
- } finally {
|
|
|
- cdl.countDown();
|
|
|
+ adRankItems.add(future.get(200, TimeUnit.MILLISECONDS));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Feature handle time out >200ms", e);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
- try {
|
|
|
- cdl.await(200, TimeUnit.MILLISECONDS);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ time2 = System.currentTimeMillis();
|
|
|
+
|
|
|
+ CountDownLatch cdl = 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.handleE1AndE2Feature(e1Feature, e2Feature, title, item.getFeatureMap());
|
|
|
+ this.handleD3AndB1Feature(d3Feature, title, item.getFeatureMap());
|
|
|
+ } finally {
|
|
|
+ cdl.countDown();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ cdl.await(200, TimeUnit.MILLISECONDS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
long time3 = System.currentTimeMillis();
|
|
@@ -194,8 +269,9 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
}
|
|
|
|
|
|
long time6 = System.currentTimeMillis();
|
|
|
- log.info("cost={}, feature1={}, feature2={}, feature3={}, feature4={}, getScorerPipeline={}, loop={}",
|
|
|
- time4 - start, time1 - start, time2 - time1, time3 - time2, time4 - time3,time5 - time4, time6 - time5);
|
|
|
+ log.info("cost={}, feature1={}, feature={}, feature3={}, feature4={}, getScorerPipeline={}, loop={}",
|
|
|
+ time6 - start, time1 - start, time2 - time1, time3 - time2, time4 - time3, time5 - time4,
|
|
|
+ time6 - time5);
|
|
|
|
|
|
result.sort(ComparatorUtil.equalsRandomComparator());
|
|
|
|