|
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.xm.Similarity;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -48,6 +49,11 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
@ApolloJsonValue("${rank.score.neg_sample_rate:0.01}")
|
|
|
Double negSampleRate;
|
|
|
|
|
|
+ @PostConstruct
|
|
|
+ public void afterInit() {
|
|
|
+ this.readBucketFile();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<AdRankItem> adItemRank(RankRecommendRequestParam request, ScoreParam scoreParam) {
|
|
|
|
|
@@ -185,7 +191,6 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
|
|
|
long time3 = System.currentTimeMillis();
|
|
|
// 分桶
|
|
|
- this.readBucketFile();
|
|
|
userFeatureMap = this.featureBucket(userFeatureMap);
|
|
|
CountDownLatch cdl4 = new CountDownLatch(adRankItems.size());
|
|
|
for (AdRankItem adRankItem : adRankItems) {
|
|
@@ -603,9 +608,9 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
if (MapUtils.isNotEmpty(bucketsMap)) {
|
|
|
return;
|
|
|
}
|
|
|
- // TODO(zhoutian): do not load file in each request, load once on init
|
|
|
synchronized (this) {
|
|
|
- InputStream resourceStream = RankStrategyBy683.class.getClassLoader().getResourceAsStream("20250113_ad_bucket_688.txt");
|
|
|
+ String bucketFile = "20250113_ad_bucket_688.txt";
|
|
|
+ InputStream resourceStream = RankStrategyBy683.class.getClassLoader().getResourceAsStream(bucketFile);
|
|
|
if (resourceStream != null) {
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
|
|
|
Map<String, double[]> bucketsMap = new HashMap<>();
|
|
@@ -628,8 +633,9 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
this.bucketsMap = bucketsMap;
|
|
|
this.bucketsLen = bucketsLen;
|
|
|
} catch (IOException e) {
|
|
|
- log.error("something is wrong in parse bucket file:", e);
|
|
|
+ log.error("something is wrong in parse bucket file: ", e);
|
|
|
}
|
|
|
+ log.info("load bucket file success: {}", bucketFile);
|
|
|
} else {
|
|
|
log.error("no bucket file");
|
|
|
}
|