Просмотр исходного кода

[collector]fix 由于链接复用不佳造成创建过多链接监控异常 (#26)

tomsun28 3 лет назад
Родитель
Сommit
790bcc6f16

+ 2 - 0
collector/src/main/java/com/usthe/collector/collect/common/cache/CacheIdentifier.java

@@ -2,6 +2,7 @@ package com.usthe.collector.collect.common.cache;
 
 import lombok.Builder;
 import lombok.Data;
+import lombok.ToString;
 
 /**
  * 缓存key唯一标识符
@@ -10,6 +11,7 @@ import lombok.Data;
  */
 @Data
 @Builder
+@ToString
 public class CacheIdentifier {
 
     private String ip;

+ 4 - 2
collector/src/main/java/com/usthe/collector/collect/common/cache/CommonCache.java

@@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit;
 public class CommonCache {
 
     /**
-     * 默认缓存时间 10minute
+     * 默认缓存时间 800s
      */
-    private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L;
+    private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L;
 
     /**
      * 默认最大缓存数量
@@ -173,9 +173,11 @@ public class CommonCache {
     public Optional<Object> getCache(Object key, boolean refreshCache) {
         Long[] cacheTime = timeoutMap.get(key);
         if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
+            log.warn("[cache] not hit the cache, key {}.", key);
             return Optional.empty();
         }
         if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
+            log.warn("[cache] is timeout, key {}.", key);
             timeoutMap.remove(key);
             cacheMap.remove(key);
             return Optional.empty();

+ 1 - 1
collector/src/main/java/com/usthe/collector/collect/database/JdbcCommonCollect.java

@@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect {
         // 设置查询最大行数1000行
         statement.setMaxRows(1000);
         JdbcConnect jdbcConnect = new JdbcConnect(connection);
-        CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L);
+        CommonCache.getInstance().addCache(identifier, jdbcConnect);
         return statement;
     }