Unverified Commit 6801a3ce authored by Yves LeBras's avatar Yves LeBras Committed by GitHub
Browse files

redis-cli --keystats and --keystats-samples with --top and --cursor (#12826)



Added `--keystats` and `--keystats-samples <n>` commands.

The new commands combines memkeys and bigkeys with additional
distribution data.
We often run memkeys and bigkeys one after the other. It will be
convenient to just have one command.
Distribution and top 10 key sizes are useful when we have multiple keys
taking a lot of memory.

Like for memkeys and bigkeys, we can use `-i <n>` and Ctrl-C to
interrupt the scan loop. It will still show the statistics on the keys
sampled so far.
We can use two new optional parameters:
- `--cursor <n>` to continue from the last cursor after an interruption
of the scan.
- `--top <n>` to change the number of top key sizes (10 by default).

Implemented a fix for the `--memkeys-samples 0` issue in order to use
`--keystats-samples 0`.

Used hdr_histogram for the key size distribution.

For key length, hdr_histogram seemed overkill and preset ranges were
used.

The memory used by keystats with hdr_histogram is around 7MB (compared
to 3MB for memkeys or bigkeys).

Execution time is somewhat equivalent to adding memkeys and bigkeys
time. Each scan loop is having more commands (key type, key size, key
length/cardinality).

We can redirect the output to a file. In that case, no color or text
refresh will happen.

Limitation:
- As the information printed during the loop is refreshed (moving cursor
up), stderr and information not fitting in the terminal window (width or
height) might create some refresh issues.

Comments:
- config.top_sizes_limit could be used globally like config.count, but
it is passed as parameter to be consistent with config.memkeys_samples.
- Not sure if we should move some utility functions to cli-common.c.

Got some tips and help from @ofirluzon.

---------
Co-authored-by: default avatarBinbin <binloveplay1314@qq.com>
Co-authored-by: default avatarViktor Söderqvist <viktor.soderqvist@est.tech>
Co-authored-by: default avatardebing.sun <debing.sun@redis.com>
parent e92363e2
......@@ -429,7 +429,7 @@ $(TLS_MODULE_NAME): $(REDIS_SERVER_NAME)
# redis-cli
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS) $(TLS_CLIENT_LIBS)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o ../deps/hdr_histogram/libhdrhistogram.a $(FINAL_LIBS) $(TLS_CLIENT_LIBS)
# redis-benchmark
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment