How to log/measure the size of Redis command's queue.
The Redis is single-threaded, so it runs commands sequentially, as I guess there is command queue there, where the incoming commands are stored, and executed one by one. The SLOWLOG command only shows the execution time, so the question is, is there a way to get how long the command was in queue before starting of execution.
AFAIK, there is no command queue in Redis.
The event loop is notified when there is something to read on a socket. Redis reads the socket, parses the input buffer and execute commands as they are decoded from the input buffer. If multiple commands are received at the same time (on different sockets), they are just processed in sequence as part as the same event loop iteration.
There is no way to evaluate the exact number of pending commands. However, there is a way to evaluate the amount of data still to be processed in the input buffer by using the CLIENT LIST command. It corresponds to the qbuf statistic.
You can also evaluate the amount of data still to be processed in the socket buffers (data not read yet by Redis). On Linux, you can use statistics found in /proc/net/tcp for this. Here is an example of a Python script using this strategy.
https://gist.github.com/dspezia/2344181
You may have to adapt the script to your system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With