REQ-2453: 添加日志, 看一下分类统计的命中率
This commit is contained in:
parent
255f5df11a
commit
686179e8b5
@ -2,6 +2,7 @@ package cn.axzo.msg.center.message.service.todo.cache;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@ -13,6 +14,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
class CacheMetric {
|
||||
|
||||
private final String name;
|
||||
private final DateTime createAt = DateTime.now();
|
||||
private final AtomicLong hitCount = new AtomicLong();
|
||||
private final AtomicLong missCount = new AtomicLong();
|
||||
|
||||
@ -28,12 +30,18 @@ class CacheMetric {
|
||||
* 大概统计一下, 不是100%准确
|
||||
*/
|
||||
void print() {
|
||||
DateTime printAt = DateTime.now();
|
||||
String pattern = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
long hitCount = this.hitCount.get();
|
||||
long missCount = this.missCount.get();
|
||||
long totalAccesses = hitCount + missCount;
|
||||
double hitRate = totalAccesses == 0 ? 0 : ((double) hitCount / totalAccesses) * 100;
|
||||
log.info("CacheMetric[{}]: hitCount={}, missCount={}, hitRate={}%",
|
||||
name, hitCount, missCount, String.format("%.2f", hitRate));
|
||||
|
||||
log.info("CacheMetric[{}]: {}-{}, hitCount={}, missCount={}, hitRate={}%",
|
||||
name,
|
||||
createAt.toString(pattern), printAt.toString(pattern),
|
||||
hitCount, missCount, String.format("%.2f", hitRate));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user