ソースを参照

Merge branch 'feature/fixed_predict_timeout' of algorithm/recommend-server into master

jiachanghui 2 週間 前
コミット
4c90e0d9c6

+ 3 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/NorXGBRegressionScorer.java

@@ -111,6 +111,9 @@ public class NorXGBRegressionScorer extends XGBRegressionModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {

+ 3 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/RosXGBRegressionScorer.java

@@ -111,6 +111,9 @@ public class RosXGBRegressionScorer extends XGBRegressionModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {

+ 3 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogRovFMScorer.java

@@ -4,7 +4,6 @@ package com.tzld.piaoquan.recommend.server.service.score;
 import com.tzld.piaoquan.recommend.feature.domain.video.base.UserFeature;
 import com.tzld.piaoquan.recommend.server.common.base.RankItem;
 import com.tzld.piaoquan.recommend.server.service.score.model.FMModel;
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang.exception.ExceptionUtils;
@@ -117,6 +116,9 @@ public class VlogRovFMScorer extends BaseFMModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {

+ 9 - 5
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogShareLRScorer.java

@@ -184,10 +184,11 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
         }
         LOGGER.debug("Ctr Score {}, Total: {}, Cancel: {}", requestContext.getRequest_id(), items.size(), cancel);
     }
+
     @Override
     public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
-                                           final Map<String, String> userFeatureMap,
-                                           final List<RankItem> rankItems){
+                                  final Map<String, String> userFeatureMap,
+                                  final List<RankItem> rankItems) {
         if (CollectionUtils.isEmpty(rankItems)) {
             return rankItems;
         }
@@ -215,12 +216,12 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
         LOGGER.debug("model size: [{}]", model.getModelSize());
         // userBytes
         Map<String, byte[]> userFeatureMapByte = new HashMap<>();
-        for(Map.Entry<String, String> entry: userFeatureMap.entrySet()){
+        for (Map.Entry<String, String> entry : userFeatureMap.entrySet()) {
             userFeatureMapByte.put(entry.getKey(), entry.getValue().getBytes());
         }
         //sceneBytes
         Map<String, byte[]> sceneFeatureMapByte = new HashMap<>();
-        for(Map.Entry<String, String> entry: sceneFeatureMap.entrySet()){
+        for (Map.Entry<String, String> entry : sceneFeatureMap.entrySet()) {
             sceneFeatureMapByte.put(entry.getKey(), entry.getValue().getBytes());
         }
 
@@ -279,6 +280,9 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {
@@ -302,7 +306,7 @@ public class VlogShareLRScorer extends BaseLRModelScorer {
         try {
 
             Map<String, byte[]> itemFeatureByte = new HashMap<>();
-            for (Map.Entry<String, String> entry: item.getFeatureMap().entrySet()){
+            for (Map.Entry<String, String> entry : item.getFeatureMap().entrySet()) {
                 itemFeatureByte.put(entry.getKey(), entry.getValue().getBytes());
             }
             lrSamples = bytesFeatureExtractor.single(userFeatureMapByte, itemFeatureByte, sceneFeatureMapByte);

+ 8 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/VlogShareLRScorer4Ros.java

@@ -184,10 +184,11 @@ public class VlogShareLRScorer4Ros extends BaseLRModelScorer {
         }
         LOGGER.debug("Ctr Score {}, Total: {}, Cancel: {}", requestContext.getRequest_id(), items.size(), cancel);
     }
+
     @Override
     public List<RankItem> scoring(final Map<String, String> sceneFeatureMap,
                                   final Map<String, String> userFeatureMap,
-                                  final List<RankItem> rankItems){
+                                  final List<RankItem> rankItems) {
         if (CollectionUtils.isEmpty(rankItems)) {
             return rankItems;
         }
@@ -215,12 +216,12 @@ public class VlogShareLRScorer4Ros extends BaseLRModelScorer {
         LOGGER.debug("model size: [{}]", model.getModelSize());
         // userBytes
         Map<String, byte[]> userFeatureMapByte = new HashMap<>();
-        for(Map.Entry<String, String> entry: userFeatureMap.entrySet()){
+        for (Map.Entry<String, String> entry : userFeatureMap.entrySet()) {
             userFeatureMapByte.put(entry.getKey(), entry.getValue().getBytes());
         }
         //sceneBytes
         Map<String, byte[]> sceneFeatureMapByte = new HashMap<>();
-        for(Map.Entry<String, String> entry: sceneFeatureMap.entrySet()){
+        for (Map.Entry<String, String> entry : sceneFeatureMap.entrySet()) {
             sceneFeatureMapByte.put(entry.getKey(), entry.getValue().getBytes());
         }
 
@@ -279,6 +280,9 @@ public class VlogShareLRScorer4Ros extends BaseLRModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {
@@ -302,7 +306,7 @@ public class VlogShareLRScorer4Ros extends BaseLRModelScorer {
         try {
 
             Map<String, byte[]> itemFeatureByte = new HashMap<>();
-            for (Map.Entry<String, String> entry: item.getFeatureMap().entrySet()){
+            for (Map.Entry<String, String> entry : item.getFeatureMap().entrySet()) {
                 itemFeatureByte.put(entry.getKey(), entry.getValue().getBytes());
             }
             lrSamples = bytesFeatureExtractor.single(userFeatureMapByte, itemFeatureByte, sceneFeatureMapByte);

+ 3 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/score/XGBoostScorer.java

@@ -115,6 +115,9 @@ public class XGBoostScorer extends BaseXGBoostModelScorer {
                     if (!future.isDone() || future.isCancelled() || future.get() == null) {
                         cancel++;
                     }
+                    if (!future.isDone() && !future.isCancelled()) {
+                        future.cancel(true);
+                    }
                 } catch (InterruptedException e) {
                     LOGGER.error("InterruptedException {},{}", ExceptionUtils.getFullStackTrace(e));
                 } catch (ExecutionException e) {