|
@@ -12,6 +12,7 @@ import com.tzld.piaoquan.recommend.feature.domain.ad.base.AdRankItem;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.math3.util.Pair;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.xm.Similarity;
|
|
@@ -57,10 +58,11 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
}
|
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
- // 特征处理
|
|
|
- // feature1
|
|
|
+ // 特征获取
|
|
|
Feature feature = this.getFeature(scoreParam, request);
|
|
|
+ long time1 = System.currentTimeMillis();
|
|
|
|
|
|
+ // 特征处理
|
|
|
Map<String, Map<String, String>> userFeature = feature.getUserFeature();
|
|
|
Map<String, Map<String, String>> videoFeature = feature.getVideoFeature();
|
|
|
Map<String, Map<String, Map<String, String>>> allAdVerFeature = feature.getAdVerFeature();
|
|
@@ -82,13 +84,13 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
Map<String, String> e2Feature = userFeature.getOrDefault("alg_mid_feature_share_tags", new HashMap<>());
|
|
|
|
|
|
Map<String, String> sceneFeatureMap = this.handleSceneFeature(ts);
|
|
|
- long time1 = System.currentTimeMillis();
|
|
|
-
|
|
|
List<AdRankItem> adRankItems = new ArrayList<>();
|
|
|
Random random = new Random();
|
|
|
List<Callable<AdRankItem>> task1s = new ArrayList<>();
|
|
|
+ long minCost = 200; // ms
|
|
|
for (AdPlatformCreativeDTO dto : request.getAdIdList()) {
|
|
|
task1s.add(() -> {
|
|
|
+ long deadline = minCost +System.currentTimeMillis();
|
|
|
AdRankItem adRankItem = new AdRankItem();
|
|
|
adRankItem.setAdId(dto.getCreativeId());
|
|
|
adRankItem.setCreativeCode(dto.getCreativeCode());
|
|
@@ -115,12 +117,49 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
this.handleC1UIFeature(midTimeDiffMap, actionStaticMap, cidFeatureMap, cidStr);
|
|
|
this.handleD1Feature(d1Feature, cidFeatureMap);
|
|
|
this.handleD2Feature(vidRankMaps, cidFeatureMap, cidStr);
|
|
|
+
|
|
|
+
|
|
|
+ String title = b1Feature.getOrDefault("cidtitle", "");
|
|
|
+
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(title)) {
|
|
|
+ long remain = deadline - System.currentTimeMillis();
|
|
|
+ if (remain > 0) {
|
|
|
+ List<Tuple2<Map<String, String>, String>> tuple2List = Arrays.asList(new Tuple2<>(e1Feature, "e1"), new Tuple2<>(e2Feature, "e2"));
|
|
|
+ List<String> tagsFieldList = Arrays.asList("tags_3d", "tags_7d", "tags_14d");
|
|
|
+ List<Callable<String>> tasks = new ArrayList<>();
|
|
|
+ for (Tuple2<Map<String, String>, String> tuple2 : tuple2List) {
|
|
|
+ Map<String, String> featureTemp = tuple2.f1;
|
|
|
+ String prefix = tuple2.f2;
|
|
|
+ if (MapUtils.isEmpty(featureTemp)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (String tagsField : tagsFieldList) {
|
|
|
+ String tags = featureTemp.get(tagsField);
|
|
|
+ if (StringUtils.isNotEmpty(tags)) {
|
|
|
+ tasks.add(() -> {
|
|
|
+ Double[] doubles = ExtractorUtils.funcC34567ForTags(tags, title);
|
|
|
+ cidFeatureMap.put(prefix + "_" + tagsField + "_matchnum", String.valueOf(doubles[0]));
|
|
|
+ cidFeatureMap.put(prefix + "_" + tagsField + "_maxscore", String.valueOf(doubles[1]));
|
|
|
+ cidFeatureMap.put(prefix + "_" + tagsField + "_avgscore", String.valueOf(doubles[2]));
|
|
|
+ return "";
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tasks.add(() -> {
|
|
|
+ this.handleD3AndB1Feature(d3Feature, title, cidFeatureMap);
|
|
|
+ return "";
|
|
|
+ });
|
|
|
+ ThreadPoolFactory.defaultPool().invokeAll(tasks, remain, TimeUnit.MILLISECONDS);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
return adRankItem;
|
|
|
});
|
|
|
}
|
|
|
try {
|
|
|
- List<Future<AdRankItem>> futures = ThreadPoolFactory.feature().invokeAll(task1s, 100,
|
|
|
- TimeUnit.MILLISECONDS);
|
|
|
+ List<Future<AdRankItem>> futures = ThreadPoolFactory.feature().invokeAll(task1s, minCost, TimeUnit.MILLISECONDS);
|
|
|
for (Future<AdRankItem> future : futures) {
|
|
|
try {
|
|
|
if (future.isDone()) {
|
|
@@ -134,47 +173,9 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
log.error("handle feature error", e);
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
long time2 = System.currentTimeMillis();
|
|
|
- // feature3
|
|
|
- List<Future<String>> futures = new ArrayList<>();
|
|
|
- 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", "");
|
|
|
- futures.add(ThreadPoolFactory.defaultPool().submit(() -> {
|
|
|
- try {
|
|
|
- this.handleE1AndE2Feature(e1Feature, e2Feature, title, item.getFeatureMap());
|
|
|
- return "";
|
|
|
- } finally {
|
|
|
- cdl2.countDown();
|
|
|
- }
|
|
|
- }));
|
|
|
- futures.add(ThreadPoolFactory.defaultPool().submit(() -> {
|
|
|
- try {
|
|
|
- this.handleD3AndB1Feature(d3Feature, title, item.getFeatureMap());
|
|
|
- return "";
|
|
|
- } finally {
|
|
|
- cdl2.countDown();
|
|
|
- }
|
|
|
- }));
|
|
|
- }
|
|
|
- try {
|
|
|
- cdl2.await(150, TimeUnit.MILLISECONDS);
|
|
|
- for (Future<String> future : futures) {
|
|
|
- if (!future.isDone()) {
|
|
|
- future.cancel(true);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
|
|
|
- }
|
|
|
|
|
|
- long time3 = System.currentTimeMillis();
|
|
|
- // 分桶
|
|
|
+ // 特征分桶
|
|
|
this.readBucketFile();
|
|
|
userFeatureMap = this.featureBucket(userFeatureMap);
|
|
|
CountDownLatch cdl4 = new CountDownLatch(adRankItems.size());
|
|
@@ -193,12 +194,10 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
} catch (Exception e) {
|
|
|
log.error("handleE1AndE2Feature and handleD3AndB1Feature wait timeout", e);
|
|
|
}
|
|
|
- long time4 = System.currentTimeMillis();
|
|
|
+ long time3 = System.currentTimeMillis();
|
|
|
// 打分排序
|
|
|
- // getScorerPipeline
|
|
|
List<AdRankItem> result = ScorerUtils.getScorerPipeline(ScorerUtils.XGBOOST_SCORE_CONF_20240909).scoring(sceneFeatureMap, userFeatureMap, adRankItems);
|
|
|
- long time5 = System.currentTimeMillis();
|
|
|
- // loop
|
|
|
+ long time4 = System.currentTimeMillis();
|
|
|
for (AdRankItem item : result) {
|
|
|
item.setScore(item.getLrScore() * item.getCpa());
|
|
|
item.getScoreMap().put("cpa", item.getCpa());
|
|
@@ -238,10 +237,8 @@ public class RankStrategyXGBAutoUpdateModel688 extends RankStrategyXGBBasic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.info("cost={}, feature1={}, feature2={}, feature3={}, feature4={}, getScorerPipeline={}, " +
|
|
|
- "adIdSize={}, adRankItemsSize={}",
|
|
|
- time5 - start, time1 - start, time2 - time1, time3 - time2, time4 - time3,
|
|
|
- time5 - time4, request.getAdIdList().size(), adRankItems.size());
|
|
|
+ log.info("cost={}, 特征获取={}, 特征处理={}, 特征分桶={}, 排序打分={}, adIdSize={}, adRankItemsSize={}",
|
|
|
+ time4 - start, time1 - start, time2 - time1, time3 - time2, time4 - time3, request.getAdIdList().size(), adRankItems.size());
|
|
|
|
|
|
result.sort(ComparatorUtil.equalsRandomComparator());
|
|
|
|