-
Notifications
You must be signed in to change notification settings - Fork 23.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
redis-cli --keystats and --keystats-samples with --top and --cursor #12826
Conversation
@redis/redis-committers maybe one of you has time to review this one? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i did some cleanup on last commit (hope you don't mind), mainly bool (we don't use bool in the codebase) and format.
then i also tried playing it, the feature look good, just a brief review
I tried this feature briefely on some small dummy data. I think the feature can be useful, but probably the output and other user experience can be improved. (I haven't thought about it much yet.) Here is a text-based "screenshot" for the record:
Then, I tried it again after populating 1M keys (using I've seen an oddity when aborting the scan with Ctrl+C. It prints the results of the keys scanned, along with a message like
During the scan, there is a nice progress bar displayed during the scan. If I abort the scan after 75% and then resume using |
The interactive progress bar and the possibility to resume if interrupted is a nice experience. Can we add those to Maybe even The design of the output (headings and tables) is not similar to the output of the other features like |
You are correct about restarting at a cursor other than 0. It will be nicer to restart at the last percentage, but as you mentioned, I am not sure we can find a way to do so. I guess the user should be ok knowing that using
For the Redis Data Type summary difference, I did the change for readeability purpose.
vs
|
I guess you're right. I don't have a better idea, so I think this is fine.
I think we cannot break the non-interactive output which the creative user can use in scripts, but in interactive mode it's OK to change things like progress bar.
Yes, but my experience says if we postpone it, it will not be done at all. Bigkeys is faster than keystats when I tried, so some users may still want to continue to use it.
Of course. I like the table, but it just the design of the heading and table header row (start with three dashes, pipe between columns) which is not a style we used elsewhere. I think it looks like some kind of markup/down syntax. How about this style? (more graphic, less like a markup syntax)
For headings, instead of three dashes in the beginning of the line (like |
Your table presentation and trailing dashes are indeed looking better. Let me know if the output below is ok, and I can push a commit for that.
To generalize the usage of the progress bar and allowing to use
When redirecting to a file, you would like to still keep some information on the TTY.
And in the file:
If this is what you meant, I need to find out how to do that. |
Yes, that looks good. I'm glad you agree. :)
Well, probably only for For bigkeys/memkeys/hotkeys, I think we can simply use similar logic as you did for keystats, i.e. show the progressbar if STDOUT is a TTY; otherwise hide it. I see you're checking |
I have pushed the new format for the tables and titles. You are right, when redirecting to a file we only need the percentage and not the progress bar. I actually show the progress bar in the file. I will remove it. Good catch on |
…s. Some arguments validation.
@zuiderkwast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine now.
It's a lot of lines added and I didn't read all of them very carefully, but the code is isolated and doesn't affect the basic operation of redis-cli, so I think it's safe to merge.
@enjoy-binbin Any comments? Have you tested it?
Typo Co-authored-by: Viktor Söderqvist <viktor.soderqvist@est.tech>
@enjoy-binbin raised two points:
We should. I added some checks after using
The function returns false if the value we are trying to insert is is negative or larger than the highest_trackable_value. Speaking of not checking a return value, I realized that I do not need to check the return value of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don’t have a very in-depth review, but looking at the output and the modified diff, the code is LGTM.
Speaking of not checking a return value, I realized that I do not need to check the return value of zmalloc() and I did it... let me know if I should remove the check.
yes, i think we can drop the check, it adds some code (which is good in generally) but is a bit overkill i think.
@enjoy-binbin @zuiderkwast |
Thanks for all the fix up! |
@sundb let me know if you have more suggestions. |
@yveslb thanks, I'm now busy in other place, come back later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
Co-authored-by: debing.sun <debing.sun@redis.com>
src/redis-cli.c
Outdated
typedef struct size_dist_entry { | ||
unsigned long long size; | ||
unsigned long long count; | ||
} size_dist_entry; | ||
|
||
typedef struct size_dist { | ||
unsigned long long total_count; | ||
unsigned long long total_size; | ||
unsigned long long max_size; | ||
size_dist_entry *size_dist; | ||
} size_dist; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about adding some comments for these parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in the latest commit.
Co-authored-by: debing.sun <debing.sun@redis.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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:
Comments:
Got some tips and help from @ofirluzon.