Przeglądaj źródła

Merge branch 'ljd/feature-grpc-fix' of algorithm/recommend-server into master

liujiandong 4 tygodni temu
rodzic
commit
c70c01dadd

+ 2 - 2
recommend-server-service/pom.xml

@@ -180,7 +180,7 @@
         <dependency>
             <groupId>com.tzld.piaoquan</groupId>
             <artifactId>recommend-feature-client</artifactId>
-            <version>1.1.20</version>
+            <version>1.1.35</version>
         </dependency>
         <dependency>
             <groupId>com.google.protobuf</groupId>
@@ -304,4 +304,4 @@
         </plugins>
     </build>
 
-</project>
+</project>

+ 19 - 2
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/remote/FeatureV2RemoteService.java

@@ -19,6 +19,9 @@ import java.util.Map;
 @Slf4j
 public class FeatureV2RemoteService {
 
+    private static final int INFO_LOG_PROTO_THRESHOLD = 500;
+    private static final long INFO_LOG_COST_THRESHOLD_MS = 200L;
+
     @Autowired
     private FeatureV2Client client;
 
@@ -26,8 +29,22 @@ public class FeatureV2RemoteService {
         if (CollectionUtils.isEmpty(protos)) {
             return Collections.emptyMap();
         }
-        Map<String, String> result = client.multiGetFeature(protos);
-        return result;
+        try {
+            long start = System.currentTimeMillis();
+            Map<String, String> result = client.multiGetFeature(protos);
+            int resultSize = result != null ? result.size() : 0;
+            long costTime = System.currentTimeMillis() - start;
+            if (protos.size() > INFO_LOG_PROTO_THRESHOLD
+                    || costTime > INFO_LOG_COST_THRESHOLD_MS
+                    || resultSize == 0) {
+                log.info("FeatureV2RemoteService.getFeature: protos.size={}, result.size={}, costTime={}",
+                        protos.size(), resultSize, costTime);
+            }
+            return result != null ? result : Collections.emptyMap();
+        } catch (Exception e) {
+            log.error("FeatureV2RemoteService.getFeature: unexpected exception, protos.size={}", protos.size(), e);
+            return Collections.emptyMap();
+        }
     }
 
 

+ 7 - 1
recommend-server-service/src/main/resources/application.yml

@@ -24,6 +24,12 @@ grpc:
   client:
     recommend-feature:
       negotiationType: PLAINTEXT
+      enable-keep-alive: true
+      keep-alive-time: 20s
+      keep-alive-timeout: 5s
+      keep-alive-without-calls: true
+      max-inbound-message-size: 20MB
+      negotiation-type: plaintext
     abtest:
       negotiationType: PLAINTEXT
 
@@ -61,4 +67,4 @@ feign:
         readTimeout: 10000
 model:
   xgboost:
-    path: xgboost
+    path: xgboost