丁云鹏 1 year ago
parent
commit
4dcda92c78

+ 9 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/WarmUpService.java

@@ -18,11 +18,19 @@ public class WarmUpService {
     @Autowired
     @Qualifier("redisTemplate")
     private RedisTemplate<String, String> redisTemplate;
-    
+    @Autowired
+    @Qualifier("featureRedisTemplate")
+    private RedisTemplate<String, String> featureRedisTemplate;
+    @Autowired
+    @Qualifier("longVideoRedisTemplate")
+    private RedisTemplate<String, String> longVideoRedisTemplate;
+
 
     @PostConstruct
     public void warmup() {
         redisTemplate.opsForValue().get("");
+        featureRedisTemplate.opsForValue().get("");
+        longVideoRedisTemplate.opsForValue().get("");
         ScorerUtils.warmUp();
     }
 }

+ 6 - 0
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/AbstractFilterService.java

@@ -1,5 +1,6 @@
 package com.tzld.piaoquan.recommend.server.service.filter;
 
+import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.service.PreViewedService;
 import com.tzld.piaoquan.recommend.server.service.ServiceBeanFactory;
@@ -143,8 +144,13 @@ public abstract class AbstractFilterService {
         List<Future<List<Long>>> futures = new ArrayList<>();
         for (final FilterStrategy strategy : strategies) {
             Future<List<Long>> future = pool.submit(() -> {
+                Stopwatch stopwatch = Stopwatch.createStarted();
                 List<Long> result = strategy.filter(param);
                 cdl.countDown();
+                log.info("{} param {} result {} cost {} ms", strategy.getClass().getSimpleName(),
+                        JSONUtils.toJson(param.getVideoIds()),
+                        JSONUtils.toJson(result),
+                        stopwatch.elapsed().toMillis());
                 return result;
             });
             futures.add(future);

+ 0 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/AllowListStrategy.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
-import com.google.common.base.Stopwatch;
 import com.google.common.collect.Lists;
 import com.google.common.hash.Hashing;
 import com.tzld.piaoquan.recommend.server.common.enums.AppTypeEnum;
@@ -35,7 +34,6 @@ public class AllowListStrategy implements FilterStrategy {
     @Override
     // TODO 未找到优化方法 暂时保留原代码
     public List<Long> filter(FilterParam param) {
-        Stopwatch stopwatch = Stopwatch.createStarted();
         if (param == null
                 || CollectionUtils.isEmpty(param.getVideoIds())) {
             return Collections.emptyList();
@@ -68,7 +66,6 @@ public class AllowListStrategy implements FilterStrategy {
                 }
             }
         }
-        log.info("AllowListStrategy cost {} ms", stopwatch.elapsed().toMillis());
         if (CollectionUtils.isEmpty(retainVideoIds)) {
             return Collections.emptyList();
         }

+ 0 - 3
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/RecommendStatusStrategy.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
-import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoStatus;
 import com.tzld.piaoquan.recommend.server.repository.WxVideoStatusRepository;
@@ -41,7 +40,6 @@ public class RecommendStatusStrategy implements FilterStrategy {
 
     @Override
     public List<Long> filter(FilterParam param) {
-        Stopwatch stopwatch = Stopwatch.createStarted();
         if (param == null
                 || CollectionUtils.isEmpty(param.getVideoIds())) {
             return Collections.emptyList();
@@ -90,7 +88,6 @@ public class RecommendStatusStrategy implements FilterStrategy {
             }
         }
 
-        log.info("recommendStatusStrategy filter cost: {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
         return param.getVideoIds().stream()
                 .filter(id -> recommendStatusMap.containsKey(id) && recommendStatusMap.get(id) == RECOMMEND_STATUS)
                 .collect(Collectors.toList());

+ 0 - 1
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/TagStrategy.java

@@ -94,7 +94,6 @@ public class TagStrategy implements FilterStrategy {
             }
         }
 
-
         if (CollectionUtils.isEmpty(retainVideoIds)) {
             return Collections.emptyList();
         }

+ 1 - 4
recommend-server-service/src/main/java/com/tzld/piaoquan/recommend/server/service/filter/strategy/ViewedStrategy.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.recommend.server.service.filter.strategy;
 
-import com.google.common.base.Stopwatch;
 import com.tzld.piaoquan.recommend.server.common.ThreadPoolFactory;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterParam;
 import com.tzld.piaoquan.recommend.server.service.filter.FilterStrategy;
@@ -41,7 +40,6 @@ public class ViewedStrategy implements FilterStrategy {
 
     @Override
     public List<Long> filter(FilterParam param) {
-        Stopwatch stopwatch = Stopwatch.createStarted();
         String user = StringUtils.isNotBlank(param.getUid()) ? param.getUid() : param.getMid();
         if (StringUtils.isBlank(user)) {
             return param.getVideoIds();
@@ -77,11 +75,10 @@ public class ViewedStrategy implements FilterStrategy {
                 });
             }
         }
-        log.info("ViewedStrategy filter cost: {}", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
+
         if (CollectionUtils.isEmpty(viewedVideoIds)) {
             return param.getVideoIds();
         }
-
         return param.getVideoIds().stream()
                 .filter(vid -> !viewedVideoIds.contains(String.valueOf(vid)))
                 .collect(Collectors.toList());

+ 3 - 4
recommend-server-service/src/main/resources/application-dev.yml

@@ -55,9 +55,9 @@ spring:
       password: lv@2018
       replicaSetName: dds-bp1de4fc73029b241978.mongodb.rds.aliyuncs.com:3717,dds-bp1de4fc73029b242144.mongodb.rds.aliyuncs.com:3717
       # 连接池
-      maxConnectionIdleTime: 30000
-      maxConnectionLifeTime: 30000
-      maxWaitTime: 30000
+      maxConnectionIdleTime: 180000
+      # maxConnectionLifeTime: 30000
+      maxWaitTime: 3000
       minSize: 5
       maxSize: 10
   datasource:
@@ -75,7 +75,6 @@ spring:
     hibernate:
       ddl-auto: validate
     database: mysql
-
 xxl:
   job:
     admin:

+ 28 - 0
recommend-server-service/src/main/resources/application-pre.yml

@@ -46,6 +46,34 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  data:
+    mongodb:
+      host: dds-bp1982ea69508a541455.mongodb.rds.aliyuncs.com
+      port: 3717
+      database: longvideo
+      username: lv
+      password: lv@2018
+      # 连接池
+      maxConnectionIdleTime: 180000
+      # maxConnectionLifeTime: 30000
+      maxWaitTime: 5000
+      minSize: 5
+      maxSize: 100
+  datasource:
+    url: jdbc:mysql://rm-bp1jjv3jv98133plv285-vpc-rw.mysql.rds.aliyuncs.com:3306/longvideo?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
+    username: wx2016_longvideo
+    password: wx2016_longvideoP@assword1234
+    driver-class-name: com.mysql.jdbc.Driver
+    hikari:
+      connection-timeout: 30000
+      minimum-idle: 5
+      maximum-pool-size: 10
+      auto-commit: true
+      idle-timeout: 30000
+  jpa:
+    hibernate:
+      ddl-auto: validate
+    database: mysql
 xxl:
   job:
     admin:

+ 28 - 0
recommend-server-service/src/main/resources/application-prod.yml

@@ -46,6 +46,34 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  data:
+    mongodb:
+      host: dds-bp1982ea69508a541455.mongodb.rds.aliyuncs.com
+      port: 3717
+      database: longvideo
+      username: lv
+      password: lv@2018
+      # 连接池
+      maxConnectionIdleTime: 180000
+      # maxConnectionLifeTime: 30000
+      maxWaitTime: 5000
+      minSize: 5
+      maxSize: 100
+  datasource:
+    url: jdbc:mysql://rm-bp1jjv3jv98133plv285-vpc-rw.mysql.rds.aliyuncs.com:3306/longvideo?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
+    username: wx2016_longvideo
+    password: wx2016_longvideoP@assword1234
+    driver-class-name: com.mysql.jdbc.Driver
+    hikari:
+      connection-timeout: 30000
+      minimum-idle: 5
+      maximum-pool-size: 100
+      auto-commit: true
+      idle-timeout: 30000
+  jpa:
+    hibernate:
+      ddl-auto: validate
+    database: mysql
 xxl:
   job:
     admin:

+ 29 - 0
recommend-server-service/src/main/resources/application-test.yml

@@ -46,6 +46,35 @@ spring:
         max-wait: -1
         max-idle: 8
         min-idle: 0
+  data:
+    mongodb:
+      host: dds-bp1de4fc73029b241978.mongodb.rds.aliyuncs.com
+      port: 3717
+      database: longvideo
+      username: lv
+      password: lv@2018
+      replicaSetName: dds-bp1de4fc73029b241978.mongodb.rds.aliyuncs.com:3717,dds-bp1de4fc73029b242144.mongodb.rds.aliyuncs.com:3717
+      # 连接池
+      maxConnectionIdleTime: 180000
+      # maxConnectionLifeTime: 30000
+      maxWaitTime: 3000
+      minSize: 5
+      maxSize: 10
+  datasource:
+    url: jdbc:mysql://rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/longvideo?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
+    username: wx2016_longvideo
+    password: wx2016_longvideoP@assword1234
+    driver-class-name: com.mysql.jdbc.Driver
+    hikari:
+      connection-timeout: 30000
+      minimum-idle: 5
+      maximum-pool-size: 10
+      auto-commit: true
+      idle-timeout: 30000
+  jpa:
+    hibernate:
+      ddl-auto: validate
+    database: mysql
 xxl:
   job:
     admin: