Bladeren bron

增加日志

gufengshou1 1 jaar geleden
bovenliggende
commit
a82558a2b8

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

@@ -0,0 +1,13 @@
+package com.tzld.piaoquan.ad.engine.commons.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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);
+    }
+}

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

@@ -8,6 +8,7 @@ import com.tzld.piaoquan.ad.engine.commons.enums.AppTypeEnum;
 import com.tzld.piaoquan.ad.engine.commons.redis.AlgorithmRedisHelper;
 import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
 import com.tzld.piaoquan.ad.engine.commons.util.JSONUtils;
+import com.tzld.piaoquan.ad.engine.commons.util.TimerWatchUtil;
 import com.tzld.piaoquan.ad.engine.service.predict.config.RoiModelConfig;
 import com.tzld.piaoquan.ad.engine.service.predict.constant.RuleRedisKeyConst;
 import com.tzld.piaoquan.ad.engine.service.predict.PredictModelService;
@@ -64,6 +65,10 @@ 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){
             if(videoId.equals(requestParam.getVideoId()+"")){
@@ -79,6 +84,7 @@ public class PredictModelServiceImpl implements PredictModelService {
                 }
             }
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         //先判断是否开启实验 和是否不出广告时间 而后判断默认0-8
         //不出广告时间判定
         Map<String,Object> result=new HashMap<>();
@@ -98,6 +104,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());
@@ -117,7 +124,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();
@@ -138,7 +145,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");
@@ -162,7 +169,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();
@@ -173,7 +180,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);
 
@@ -192,7 +199,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)
@@ -204,7 +211,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();
@@ -238,6 +245,7 @@ public class PredictModelServiceImpl implements PredictModelService {
                     getThresholdPredictModel(thresholdMixFunc.toString())
                     .predict(modelParam);
         }
+        TimerWatchUtil.printCost(methodName,step++,startTime);
         return result;
     }