Redis commands queue size

核能气质少年 提交于 2021-01-27 04:36:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/15372382/redis-commands-queue-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!