jlecour
jlecour

Reputation: 3035

Reset Redis "used_memory_peak" stat

I'm using Redis (2.4.2) and with the INFO command I can read stats about my Redis server.

There are many stats, including some about how much memory is used. And one is "used_memory_peak" that seems to hold the maximum amount of memory Redis has ever taken.

I've deleted a bunch of key, and I'd like to reset this stat since it affects the scale of my Munin graphs.

There is a CONFIG RESETSTAT command, but it doesn't seem to affect this particular stat.

Any idea how I could do this, without having to export/delete/import my dataset ?

EDIT :

According to @antirez himself (issue 369 on GitHub), this is an intended behavior, but it this feature could be improved to be more useful in a future release.

Upvotes: 6

Views: 4367

Answers (2)

Rahul Gojame
Rahul Gojame

Reputation: 21

Simple trick to clear peal memory::

Step 1:

/home/logproc/redis/bin/redis-cli BGREWRITEAOF

wait till it finish rewriting aof file.

Step 2:

restart redis db

Done. Thats It.

Upvotes: 2

Didier Spezia
Didier Spezia

Reputation: 73246

The implementation of CONFIG RESETSTAT is quite simple:

} else if (!strcasecmp(c->argv[1]->ptr,"resetstat")) {
    if (c->argc != 2) goto badarity;
    server.stat_keyspace_hits = 0;
    server.stat_keyspace_misses = 0;
    server.stat_numcommands = 0;
    server.stat_numconnections = 0;
    server.stat_expiredkeys = 0;
    addReply(c,shared.ok);

So it does not initialize the server.stat_peak_memory field used to store the maximum amount of memory ever used by Redis. I don't know if it is a bug or a feature.

Here is a hack to reset the value without having to stop Redis. The idea is to use gdb in batch mode to just change the value of the variable (which is part of a static structure). Normally Redis is compiled with debugging symbols.

# Here we have plenty of things in this instance
> ./redis-cli info  | grep peak
used_memory_peak:1363052184
used_memory_peak_human:1.27G

# Let's do some cleaning: everything is wiped out
# don't do this in production !!!
> ./redis-cli flushdb
OK

# Again the same values, while some memory has been freed
> ./redis-cli info  | grep peak
used_memory_peak:1363052184
used_memory_peak_human:1.27G

# Here is the magic command: reset the parameter with gdb (output and warnings to be ignored)
> gdb -batch -n -ex 'set variable server.stat_peak_memory = 0' ./redis-server `pidof redis-server`
Missing separate debuginfo for /lib64/libm.so.6
Missing separate debuginfo for /lib64/libdl.so.2
Missing separate debuginfo for /lib64/libpthread.so.0
[Thread debugging using libthread_db enabled]
[New Thread 0x41001940 (LWP 22837)]
[New Thread 0x40800940 (LWP 22836)]
Missing separate debuginfo for /lib64/libc.so.6
Missing separate debuginfo for /lib64/ld-linux-x86-64.so.2

warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff51ff000
0x00002af0b5eef218 in epoll_wait () from /lib64/libc.so.6

# And now, result is different: great !
> ./redis-cli info  | grep peak
used_memory_peak:718768
used_memory_peak_human:701.92K

This is a hack: think twice before applying this trick on a production instance.

Upvotes: 4

Related Questions