|
@@ -3,6 +3,7 @@ package com.tzld.piaoquan.recommend.server.implement;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
|
+import com.google.common.base.Stopwatch;
|
|
import com.google.common.reflect.TypeToken;
|
|
import com.google.common.reflect.TypeToken;
|
|
import com.tzld.piaoquan.recommend.server.common.base.RankItem;
|
|
import com.tzld.piaoquan.recommend.server.common.base.RankItem;
|
|
import com.tzld.piaoquan.recommend.server.framework.candidiate.Candidate;
|
|
import com.tzld.piaoquan.recommend.server.framework.candidiate.Candidate;
|
|
@@ -59,16 +60,21 @@ public class TopRecommendPipeline {
|
|
final int requestIndex,
|
|
final int requestIndex,
|
|
final User userInfo, Boolean logPrint) {
|
|
final User userInfo, Boolean logPrint) {
|
|
// Step 1: Attention extraction
|
|
// Step 1: Attention extraction
|
|
|
|
+ Stopwatch stopwatch = Stopwatch.createStarted();
|
|
|
|
+ stopwatch.start();
|
|
List<RankItem> rankItems = feedByRec(requestData, requestIndex, userInfo, logPrint);
|
|
List<RankItem> rankItems = feedByRec(requestData, requestIndex, userInfo, logPrint);
|
|
if (rankItems == null || rankItems.isEmpty()) {
|
|
if (rankItems == null || rankItems.isEmpty()) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, rankItems = {}", requestData.getRequestId(), JSONUtils.toJson(rankItems));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, feeds rankItems = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(rankItems));
|
|
}
|
|
}
|
|
|
|
+ stopwatch.reset().start();
|
|
List<Video> videos = rankItem2Video(rankItems);
|
|
List<Video> videos = rankItem2Video(rankItems);
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, videos = {}", requestData.getRequestId(), JSONUtils.toJson(videos));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, videos = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(videos));
|
|
}
|
|
}
|
|
return videos;
|
|
return videos;
|
|
}
|
|
}
|
|
@@ -109,32 +115,34 @@ public class TopRecommendPipeline {
|
|
final User userInfo, Boolean logPrint) {
|
|
final User userInfo, Boolean logPrint) {
|
|
int recallNum = 150;
|
|
int recallNum = 150;
|
|
|
|
|
|
- // Step 1: Attention extraction
|
|
|
|
-// long timestamp = System.currentTimeMillis();
|
|
|
|
-// UserAttentionExtractorPipeline attentionExtractorPipeline = UserAttentionExtractorUtils.getAtttentionPipeline(UserAttentionExtractorUtils.BASE_CONF);
|
|
|
|
-// attentionExtractorPipeline.extractAttention(requestData, userInfo);
|
|
|
|
|
|
+ Stopwatch stopwatch = Stopwatch.createStarted();
|
|
|
|
|
|
// Step 2: create top queue
|
|
// Step 2: create top queue
|
|
|
|
+ stopwatch.start();
|
|
StrategyQueue topQueue = MergeUtils.createTopQueue(MERGE_CONF, "top-queue");
|
|
StrategyQueue topQueue = MergeUtils.createTopQueue(MERGE_CONF, "top-queue");
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, topQueue = {}", requestData.getRequestId(), JSONUtils.toJson(topQueue));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, topQueue = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(topQueue));
|
|
}
|
|
}
|
|
|
|
|
|
// Step 3: Candidate
|
|
// Step 3: Candidate
|
|
|
|
+ stopwatch.reset().start();
|
|
Map<String, Candidate> candidates = new HashMap<String, Candidate>();
|
|
Map<String, Candidate> candidates = new HashMap<String, Candidate>();
|
|
topQueue.candidate(candidates, recallNum, userInfo, requestData, 0, 0);
|
|
topQueue.candidate(candidates, recallNum, userInfo, requestData, 0, 0);
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, candidates = {}", requestData.getRequestId(), JSONUtils.toJson(candidates));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, candidates = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(candidates));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
// Step 4: Recalling & Basic Scoring
|
|
// Step 4: Recalling & Basic Scoring
|
|
|
|
+ stopwatch.reset().start();
|
|
RedisBackedQueue queueProvider = new RedisBackedQueue(client, 1000L);
|
|
RedisBackedQueue queueProvider = new RedisBackedQueue(client, 1000L);
|
|
-
|
|
|
|
BaseRecaller recaller = new BaseRecaller(queueProvider);
|
|
BaseRecaller recaller = new BaseRecaller(queueProvider);
|
|
List<RankItem> items = recaller.recalling(requestData, userInfo, requestIndex, new ArrayList<>(candidates.values()));
|
|
List<RankItem> items = recaller.recalling(requestData, userInfo, requestIndex, new ArrayList<>(candidates.values()));
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, items = {}", requestData.getRequestId(), JSONUtils.toJson(items));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, items = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(items));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -146,6 +154,7 @@ public class TopRecommendPipeline {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ stopwatch.reset().start();
|
|
// Step 5: Merger
|
|
// Step 5: Merger
|
|
MergeUtils.distributeItemsToMultiQueues(topQueue, items);
|
|
MergeUtils.distributeItemsToMultiQueues(topQueue, items);
|
|
topQueue.merge(recallNum * 3, userInfo, requestData, requestIndex, 0);
|
|
topQueue.merge(recallNum * 3, userInfo, requestData, requestIndex, 0);
|
|
@@ -158,15 +167,18 @@ public class TopRecommendPipeline {
|
|
duplicate(mergeItems);
|
|
duplicate(mergeItems);
|
|
|
|
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, mergeItems = {}", requestData.getRequestId(), JSONUtils.toJson(mergeItems));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, mergeItems = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(mergeItems));
|
|
}
|
|
}
|
|
// MergeUtils.diversityRerank(mergeItems, SimilarityUtils.getIsSameUserTagOrCategoryFunc(), recallNum, 6, 2);
|
|
// MergeUtils.diversityRerank(mergeItems, SimilarityUtils.getIsSameUserTagOrCategoryFunc(), recallNum, 6, 2);
|
|
|
|
|
|
// Step 6: Global Rank & subList
|
|
// Step 6: Global Rank & subList
|
|
// TODO 前置和后置处理逻辑 hardcode,后续优化
|
|
// TODO 前置和后置处理逻辑 hardcode,后续优化
|
|
|
|
+ stopwatch.reset().start();
|
|
List<RankItem> rovRecallRankNewScore = rankByScore(mergeItems, requestData);
|
|
List<RankItem> rovRecallRankNewScore = rankByScore(mergeItems, requestData);
|
|
if (logPrint) {
|
|
if (logPrint) {
|
|
- log.info("traceId = {}, rovRecallRankNewScore = {}", requestData.getRequestId(), JSONUtils.toJson(rovRecallRankNewScore));
|
|
|
|
|
|
+ log.info("traceId = {}, cost = {}, rovRecallRankNewScore = {}", requestData.getRequestId(),
|
|
|
|
+ stopwatch.elapsed().toMillis(), JSONUtils.toJson(rovRecallRankNewScore));
|
|
}
|
|
}
|
|
|
|
|
|
return rovRecallRankNewScore;
|
|
return rovRecallRankNewScore;
|