mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 08:23:34 +01:00
lib/workingsetcache: randomize interval for swapping curr and prev caches
This should make CPU usage smoother over time, since different caches will be swapped at different times.
This commit is contained in:
parent
0126ea31e7
commit
f22bea242f
@ -129,7 +129,8 @@ func (c *Cache) runWatchers(expireDuration time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) expirationWatcher(expireDuration time.Duration) {
|
func (c *Cache) expirationWatcher(expireDuration time.Duration) {
|
||||||
t := time.NewTicker(expireDuration / 2)
|
expireDuration += timeJitter(expireDuration / 10)
|
||||||
|
t := time.NewTicker(expireDuration)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-c.stopCh:
|
case <-c.stopCh:
|
||||||
@ -155,7 +156,9 @@ func (c *Cache) expirationWatcher(expireDuration time.Duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) cacheSizeWatcher() {
|
func (c *Cache) cacheSizeWatcher() {
|
||||||
t := time.NewTicker(1500 * time.Millisecond)
|
checkInterval := 1500 * time.Millisecond
|
||||||
|
checkInterval += timeJitter(checkInterval / 10)
|
||||||
|
t := time.NewTicker(checkInterval)
|
||||||
defer t.Stop()
|
defer t.Stop()
|
||||||
|
|
||||||
var maxBytesSize uint64
|
var maxBytesSize uint64
|
||||||
@ -375,3 +378,8 @@ func (c *Cache) SetBig(key, value []byte) {
|
|||||||
curr := c.curr.Load().(*fastcache.Cache)
|
curr := c.curr.Load().(*fastcache.Cache)
|
||||||
curr.SetBig(key, value)
|
curr.SetBig(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func timeJitter(d time.Duration) time.Duration {
|
||||||
|
n := float64(time.Now().UnixNano()%1e9) / 1e9
|
||||||
|
return time.Duration(float64(d) * n)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user