本地缓存 优化 增加各种统计信息

This commit is contained in:
2025-02-12 16:44:34 +08:00
parent 3667ff7715
commit 2e59537866

View File

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -59,6 +60,9 @@ public class LocalCacheService {
@Resource
PMMLExecutor pmmlExecutor;
private static final String VERSION = "2025-02-12 16:30";
private final String startTime = LocalDateTime.now().toString();
@@ -86,6 +90,9 @@ public class LocalCacheService {
public Map<String,Object> getInfo(){
Map<String,Object> info = new HashMap<>();
info.put("VERSION",VERSION);
info.put("startTime",startTime);
info.put("runCount",runCount.longValue());
info.put("info",infoMap);
@@ -149,6 +156,7 @@ public class LocalCacheService {
updateFieldsCache();
}catch(Throwable e){
error = true;
infoMap.put("updateFieldsCache_error",LocalDateTime.now()+":"+e);
logger.error("updateFieldsCache_error",e);
}
@@ -156,6 +164,7 @@ public class LocalCacheService {
updateModelCache();
}catch(Throwable e){
error = true;
infoMap.put("updateModelCache_error",LocalDateTime.now()+":"+e);
logger.error("updateModelCache_error",e);
}
if(throwsError && error){
@@ -188,11 +197,19 @@ public class LocalCacheService {
}
CommUtil.doSleep(UPDATE_SLEEP_TIME_MS);
runCount.getAndIncrement();
long start = System.currentTimeMillis();
updateAllCache(false);
long end = System.currentTimeMillis();
long time = end - start;
infoMap.put("updateAllCache_use_time",time+"MS");
infoMap.put("updateAllCache_time",LocalDateTime.now().toString());
}
}
}
}