diff options
author | Huang Zhw <huang_zhw@126.com> | 2021-07-26 15:07:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-26 10:07:20 +0300 |
commit | 17511df59b96bfeab8b46d474c19ec929e605bb9 (patch) | |
tree | db5e4c40c058419632bd4ef2c3bdb17d85f036a3 /src/evict.c | |
parent | 8d00493485ed4015c846b7cf694bfae03e133f0a (diff) | |
download | redis-17511df59b96bfeab8b46d474c19ec929e605bb9.tar.gz |
Add INFO stat total_eviction_exceeded_time and current_eviction_exceeded_time (#9031)
Add two INFO metrics:
```
total_eviction_exceeded_time:69734
current_eviction_exceeded_time:10230
```
`current_eviction_exceeded_time` if greater than 0, means how much time current used memory is greater than `maxmemory`. And we are still over the maxmemory. If used memory is below `maxmemory`, this metric is reset to 0.
`total_eviction_exceeded_time` means total time used memory is greater than `maxmemory` since server startup.
The units of these two metrics are ms.
Co-authored-by: Oran Agra <oran@redislabs.com>
Diffstat (limited to 'src/evict.c')
-rw-r--r-- | src/evict.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/evict.c b/src/evict.c index 5fdcd4134..7a2befdd2 100644 --- a/src/evict.c +++ b/src/evict.c @@ -510,6 +510,8 @@ static unsigned long evictionTimeLimitUs() { * EVICT_FAIL - memory is over the limit, and there's nothing to evict * */ int performEvictions(void) { + /* Note, we don't goto update_metrics here because this check skips eviction + * as if it wasn't triggered. it's a fake EVICT_OK. */ if (!isSafeToPerformEvictions()) return EVICT_OK; int keys_freed = 0; @@ -520,11 +522,15 @@ int performEvictions(void) { int slaves = listLength(server.slaves); int result = EVICT_FAIL; - if (getMaxmemoryState(&mem_reported,NULL,&mem_tofree,NULL) == C_OK) - return EVICT_OK; + if (getMaxmemoryState(&mem_reported,NULL,&mem_tofree,NULL) == C_OK) { + result = EVICT_OK; + goto update_metrics; + } - if (server.maxmemory_policy == MAXMEMORY_NO_EVICTION) - return EVICT_FAIL; /* We need to free memory, but policy forbids. */ + if (server.maxmemory_policy == MAXMEMORY_NO_EVICTION) { + result = EVICT_FAIL; /* We need to free memory, but policy forbids. */ + goto update_metrics; + } unsigned long eviction_time_limit_us = evictionTimeLimitUs(); @@ -705,6 +711,16 @@ cant_free: latencyEndMonitor(latency); latencyAddSampleIfNeeded("eviction-cycle",latency); + +update_metrics: + if (result == EVICT_RUNNING || result == EVICT_FAIL) { + if (server.stat_last_eviction_exceeded_time == 0) + elapsedStart(&server.stat_last_eviction_exceeded_time); + } else if (result == EVICT_OK) { + if (server.stat_last_eviction_exceeded_time != 0) { + server.stat_total_eviction_exceeded_time += elapsedUs(server.stat_last_eviction_exceeded_time); + server.stat_last_eviction_exceeded_time = 0; + } + } return result; } - |