소스 검색

增加日志

gufengshou1 1 년 전
부모
커밋
edcc445a2f

+ 1 - 1
ad-engine-commons/src/main/java/com/tzld/piaoquan/ad/engine/commons/util/TimerWatchUtil.java

@@ -8,6 +8,6 @@ public class TimerWatchUtil {
     private final static Logger log = LoggerFactory.getLogger(TimerWatchUtil.class);
 
     public static void printCost(String method,int step,long begin){
-        log.info("svc={}_byTimerWatchUtil step={} cost={}",method,step,System.currentTimeMillis()-begin);
+        log.info("svc={}_byTimerWatchUtil step={} begin={} cost={}",method,step,begin,System.currentTimeMillis()-begin);
     }
 }

+ 11 - 12
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/impl/PredictModelServiceImpl.java

@@ -65,9 +65,6 @@ public class PredictModelServiceImpl implements PredictModelService {
     private String withoutAdVideoIds;
 
     public Map<String, Object> adPredict(ThresholdPredictModelRequestParam requestParam) {
-        long startTime=System.currentTimeMillis();
-        String methodName="adPredictNew";
-        int step=1;
 
         String[] withoutAdVideoIdsArr=withoutAdVideoIds.split(",");
         for(String videoId:withoutAdVideoIdsArr){
@@ -84,7 +81,7 @@ public class PredictModelServiceImpl implements PredictModelService {
                 }
             }
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
         //不出广告时间判定
         Map<String,Object> result=new HashMap<>();
@@ -104,7 +101,7 @@ public class PredictModelServiceImpl implements PredictModelService {
                 isHit = true;
             }
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         int hourOfDay= DateUtils.getCurrentHour();
         Boolean condition1=abTestConfigContainer.inAdTimeTest(requestParam.getAbExpInfo());
         Boolean condition2=abTestConfigContainer.containsCode(configMap,requestParam.getAbTestCode());
@@ -124,7 +121,7 @@ public class PredictModelServiceImpl implements PredictModelService {
             result.put("no_ad_strategy", "no_ad_time_with_fixed_time");
             return result;
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //人群选择算法判定-570
 //        try {
 //            JSONObject object = requestParam.getAbExpInfo();
@@ -145,7 +142,7 @@ public class PredictModelServiceImpl implements PredictModelService {
 //        } catch (Exception e) {
 //            log.error("adPredict hit error", e);
 //        }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         String[] abParamArr = abConfig.getAbParams(requestParam.getAbTestCode(), requestParam.getAbExpInfo());
         if (abParamArr == null) {
             result.put("msg", "abConfig_error");
@@ -169,7 +166,7 @@ public class PredictModelServiceImpl implements PredictModelService {
         //市-中文
         requestParam.setRegion(requestParam.getRegion().replace("省", ""));
         requestParam.setCity(requestParam.getCity().replace("市", ""));
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         // Determine the group to which mid belongs
         String groupClassKey = (String) abtestParam.get("group_class_key");
         String midGroupKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_MID_GROUP + groupClassKey + ":" + requestParam.getMid();
@@ -180,7 +177,7 @@ public class PredictModelServiceImpl implements PredictModelService {
             midGroup = "mean_group";
             shareType="noShare";
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         String[] noAdMidGroupList = new String[0];
         noAdMidGroupList = ((JSONArray) abtestParam.get("no_ad_mid_group_list")).toArray(noAdMidGroupList);
 
@@ -199,7 +196,7 @@ public class PredictModelServiceImpl implements PredictModelService {
             result.put("no_ad_strategy", "no_ad_mid_group_with_video");
             return result;
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //top1广告不出视频
         Map<String, List<String>> noAdGroupWithVideoMapping = (Map) abtestParam.getOrDefault("no_ad_group_with_video_mapping", new HashMap<>());
         if (noAdGroupWithVideoMapping.keySet().contains(midGroup)
@@ -211,7 +208,7 @@ public class PredictModelServiceImpl implements PredictModelService {
             result.put("no_ad_strategy", "no_ad_mid_group_with_video");
             return result;
         }
-        TimerWatchUtil.printCost(methodName,step++,startTime);
+
         //设置信息
         ThresholdPredictModelParam modelParam = ThresholdPredictModelParam.builder()
                 .build();
@@ -224,7 +221,9 @@ public class PredictModelServiceImpl implements PredictModelService {
         modelParam.setExtraParam(new HashMap<>());
         modelParam.addUserExtraFuture("shareType",shareType);
         setExtraParam(modelParam);
-
+        long startTime=System.currentTimeMillis();
+        String methodName="adPredictNew";
+        int step=1;
         if (adPredictBreakSwitch || isHit) {
             if(expCodes.contains(adPredictNoShareUserExpCode)&&"noShare".equals(shareType)){
                 result = ThresholdModelContainer.

+ 11 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/AddThresholdPredictModel.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.helper.RuleParamHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdCalculateParam;
@@ -30,13 +31,20 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
     }
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
         Map<String, Object> result = new HashMap<>();
         // Get group and video share rates
         Double groupShareRate = paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(), modelParam.getMidGroup());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Double videoShareRate = paramHelper.getVideoShareRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // Get group and video out rates
         Double groupOutRate = paramHelper.getGroupOutRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Double videoOutRate = paramHelper.getVideoOutRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
 
         // Calculate mid-video prediction result
         if (groupShareRate == null || videoShareRate == null || groupOutRate == null || videoOutRate == null) {
@@ -51,6 +59,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
                 .videoShareRate(videoShareRate)
                 .shareWeight(shareWeight).outWeight(outWeight).build();
         double midVideoPredictRes = ThresholdPredictCalculator.addWeightCalculate(calculateParam);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
 
         // Get the threshold
         double threshold = paramHelper.getThreshold(
@@ -61,6 +70,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // Threshold check
         int adPredict=midVideoPredictRes > threshold?2:1;
         result.put("mid_group", modelParam.getMidGroup());
@@ -74,6 +84,7 @@ public class AddThresholdPredictModel extends ThresholdPredictModel {
         result.put("mid_video_predict_res", midVideoPredictRes);
         result.put("threshold", threshold);
         result.put("ad_predict", adPredict);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         return result;
     }
 }

+ 10 - 2
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/BasicThresholdPredictModel.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.helper.RuleParamHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdCalculateParam;
@@ -30,12 +31,16 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
 
     public Map<String, Object> predictWithRateProcess(ThresholdPredictModelParam modelParam,String midGroup){
 
-
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
 
 //        Double groupShareRate=paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
         Double groupShareRate=paramHelper.getGroupShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),midGroup);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
 //        Double videoShareRate=paramHelper.getVideoShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
         Double videoShareRate=paramHelper.getVideoShareRateForBasic(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getVideoId());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         double threshold = paramHelper.getThreshold(
                 modelParam.getAbtestId(),
                 modelParam.getAbTestConfigTag(),
@@ -44,11 +49,13 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         ThresholdCalculateParam calculateParam=ThresholdCalculateParam.builder()
                 .groupShareRate(groupShareRate)
                 .videoShareRate(videoShareRate).build();
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Double midVideoPredictRes=ThresholdPredictCalculator.basicCalculate(calculateParam);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         int adPredict=midVideoPredictRes > threshold?2:1;
         Map<String, Object> result=new HashMap<>();
         result.put("mid_group", midGroup);
@@ -57,6 +64,7 @@ public class BasicThresholdPredictModel extends ThresholdPredictModel{
         result.put("mid_video_predict_res", midVideoPredictRes);
         result.put("threshold", threshold);
         result.put("ad_predict", adPredict);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         return result;
     }
 }

+ 9 - 1
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/MultiplyThresholdPredictModel.java

@@ -1,6 +1,7 @@
 package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.calculator.ThresholdPredictCalculator;
 import com.tzld.piaoquan.ad.engine.service.predict.helper.RuleParamHelper;
 import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdCalculateParam;
@@ -29,15 +30,21 @@ public class MultiplyThresholdPredictModel  extends ThresholdPredictModel{
 
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
         Map<String, Object> result = new HashMap<>();
 
         // Get group and video share rates
         Double groupShareRate = paramHelper.getGroupShareRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Double videoShareRate = paramHelper.getVideoShareRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // Get group and video out rates
         Double groupOutRate = paramHelper.getGroupOutRate(modelParam.getAbtestParam(),modelParam.getDate(),modelParam.getMidGroup());
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Double videoOutRate = paramHelper.getVideoOutRate(modelParam.getAbtestParam(), modelParam.getDate(),modelParam.getVideoId());
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // Calculate mid-video prediction result
         if (groupShareRate == null || videoShareRate == null || groupOutRate == null || videoOutRate == null) {
             return null;
@@ -58,6 +65,7 @@ public class MultiplyThresholdPredictModel  extends ThresholdPredictModel{
                 modelParam.getCareModelStatus(),
                 modelParam.getAbtestParam()
         );
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // Threshold check
         int adPredict=midVideoPredictRes > threshold?2:1;
 //            if (midVideoPredictRes > threshold) {

+ 3 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/RoiThresholdPredictModel.java

@@ -37,6 +37,9 @@ public class RoiThresholdPredictModel extends ThresholdPredictModel{
     RoiModelConfig roiModelConfig;
     @Override
     public <T extends ThresholdPredictModelParam> Map<String, Object> predict(T param) {
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
         RoiThresholdPredictModelParam modelParam=(RoiThresholdPredictModelParam)param;
         Date previousDate = new Date(modelParam.getDate().getTime() - (24 * 60 * 60 * 1000)); // Subtract one day
         String nowDt = new SimpleDateFormat("yyyyMMdd").format(modelParam.getDate());

+ 14 - 5
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/ScoreThresholdPredictModel.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;
 
 import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.config.AdOutV1OnlineWeightConfig;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
@@ -30,13 +31,17 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
         Map<String, Object> result;
-
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
         String modelKey = (String) modelParam.getAbtestParam().getOrDefault("model_key", "ad_out_v1");
         String userKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_USER + modelKey + ":" + modelParam.getMid();
         String itemKeyName = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_SCORE_ITEM + modelKey + ":" + modelParam.getVideoId();
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         String userScore = redisHelper.get(userKeyName);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         String itemScore = redisHelper.get(itemKeyName);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
 
         //加载配置数据
         String configKeyNamePrefix = RuleRedisKeyConst.KEY_NAME_PREFIX_AD_OUT_MODEL_CONFIG
@@ -45,6 +50,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                 + modelParam.getAbtestParam().get("abtest_config_tag");
         String configKey = configKeyNamePrefix + ":config";
         String configStr = redisHelper.get(configKey);
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Map<String, Object> configMap = new HashMap<>();
         String hitStrategy="model";
         if (configStr != null) {
@@ -65,7 +71,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
 
         boolean useBackup = Boolean.valueOf((String)configMap.getOrDefault("use_backup_key","false"));
 
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         //有数据为空且开启兜底策略
         if (
                 (StringUtils.isBlank(userScore) || StringUtils.isBlank(itemScore))
@@ -79,7 +85,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
             result.put("hit_strategy",hitStrategy);
             return result;
         }
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         double offlineScore ;
         //处理空值逻辑
         double threshold=(double)configMap.getOrDefault("threshold",0);
@@ -97,6 +103,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                     (double)configMap.getOrDefault("user_threshold", 0);
             hitStrategy=isUserScoreBlank?"item":"user";
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         //获取计算参数
         SimpleDateFormat hourFormat = new SimpleDateFormat("HH");
         SimpleDateFormat weekDayFormat = new SimpleDateFormat("u");
@@ -114,6 +121,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
                 rankScore = Double.parseDouble(rankScoreStr);
             }
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         offlineScore=Double.parseDouble(userScore) + Double.parseDouble(itemScore);
         double onlineScore=getOlineScore(onlineFeatures);
         double rankScoreBias = (double)configMap.getOrDefault("rank_score_bias", 0.0);
@@ -122,7 +130,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
         double rankScoreW = (double)configMap.getOrDefault("rank_score_w", 1.0);
         double finalScoreW = (double)configMap.getOrDefault("final_score_w", 1.0);
         double mergeScore = finalScoreW * finalScore + rankScoreW * (rankScore + rankScoreBias);
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         int adPredict;
         if (mergeScore < threshold) {
             // If final score is below threshold, show the ad
@@ -131,6 +139,7 @@ public class ScoreThresholdPredictModel extends ThresholdPredictModel{
             // Otherwise, do not show the ad
             adPredict = 1;
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         result=new HashMap<>();
         result.put("user_score", userScore);
         result.put("item_score", itemScore);

+ 9 - 5
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/predict/model/threshold/ScoreV2ThresholdPredictModel.java

@@ -6,6 +6,7 @@ import com.tzld.piaoquan.ad.engine.commons.score.AdConfig;
 import com.tzld.piaoquan.ad.engine.commons.score.ScoreParam;
 import com.tzld.piaoquan.ad.engine.commons.score.ScorerUtils;
 import com.tzld.piaoquan.ad.engine.commons.util.CommonCollectionUtils;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.container.PredictPidContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.container.ThresholdModelContainer;
 import com.tzld.piaoquan.ad.engine.service.predict.impl.PredictModelServiceImpl;
@@ -46,13 +47,15 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
 
     @Override
     public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
-
+        long startTime=System.currentTimeMillis();
+        String methodName=initName();
+        int step=1;
         UserAdFeature userAdFeature = featureRemoteService.getUserAdFeature(modelParam.getMid());
         if (userAdFeature == null) {
             userAdFeature = new UserAdFeature();
         }
         List<AdRankItem> rankItems = featureRemoteService.getAllAdFeatureList(CommonCollectionUtils.toList(AdConfig.getAdIds(), id -> id.toString()));
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // scoreParam
         AdRequestContext context = new AdRequestContext();
         context.setApptype(modelParam.getAppType().toString());
@@ -79,7 +82,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
         List<AdRankItem> scoreResult = ScorerUtils
                 .getScorerPipeline(BREAK_CONFIG)
                 .scoring(scoreParam, userAdFeature, rankItems);
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         // 找出ctr*cvr最大的
         double max = -1;
         AdRankItem maxItem = null;
@@ -91,6 +94,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
                 maxItem = item;
             }
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         double realThreshold=Double.parseDouble(
                 scoreParam.getExtraParam().getOrDefault("ScoreV2ThresholdPredict_"+modelParam.getAppType(),threshold).toString()
         );
@@ -103,7 +107,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
             realThreshold=PredictPidContainer.getLatestThreshold(
                     scoreParam.getExtraParam().getOrDefault("predict_test_id","default")+"_"+modelParam.getAppType());
         }
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
 
         if (maxItem != null && maxItem.getScore() < realThreshold) {
             // If final score is below threshold, do not show the ad
@@ -121,7 +125,7 @@ public class ScoreV2ThresholdPredictModel extends ThresholdPredictModel {
             log.info("svc=ScoreV2ThresholdPredictModel_predict modelName=ScoreV2ThresholdPredictModel maxItem={} extraParam={} app_type={} realThreshold={}",
                     JSONObject.toJSONString(maxItem), JSONObject.toJSONString(scoreParam.getExtraParam()),modelParam.getAppType(),realThreshold);
         }
-
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         Map<String, Object> result = new HashMap<>();
         result.put("threshold", realThreshold);
         result.put("score", maxItem == null ? -1 : maxItem.getScore());