优化缓存命中率统计采样时长和数量

This commit is contained in:
刘祥超
2023-10-13 08:28:13 +08:00
parent 3aa68b5ffc
commit 5b93b28690

View File

@@ -11,7 +11,7 @@ import (
"time" "time"
) )
const countSamples = 10_000 const countSamples = 100_000
type Item struct { type Item struct {
countHits uint64 countHits uint64
@@ -138,7 +138,7 @@ func (this *Stat) IsGood(category string) bool {
return true return true
} }
if item.countCached > countSamples { if item.countCached > countSamples && item.timestamp < fasttime.Now().Unix()-600 /** 10 minutes ago **/ {
var isGood = item.countHits*100/item.countCached >= this.goodRatio var isGood = item.countHits*100/item.countCached >= this.goodRatio
if isGood { if isGood {
item.isGood = true item.isGood = true