fix(flashnode): fix low performance due to traversing keys in fetch status.

close:#22838790

Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
shuqiang-zheng 2024-11-28 17:44:14 +08:00 committed by zhumingze1108
parent cf338f6fa5
commit 1cfd66ec91
2 changed files with 10 additions and 0 deletions

View File

@ -307,6 +307,11 @@ func (c *CacheEngine) Status() *proto.CacheStatus {
return stat
}
func (c *CacheEngine) GetHitRate() float64 {
hitRate := c.lruCache.GetHitRate()
return math.Trunc(hitRate.HitRate*1e4+0.5) * 1e-4
}
func (c *CacheEngine) EvictCacheByVolume(evictVol string) (failedKeys []interface{}) {
stat := c.lruCache.Status()
failedKeys = make([]interface{}, 0)

View File

@ -33,6 +33,7 @@ type LruCache interface {
EvictAll()
Close() error
Status() *Status
GetHitRate() RateStat
Len() int
GetRateStat() RateStat
}
@ -147,6 +148,10 @@ func (c *fCache) Status() *Status {
}
}
func (c *fCache) GetHitRate() RateStat {
return *c.recent
}
func GenerateRandTime(expiration time.Duration) time.Duration {
if expiration <= 0 {
return expiration