The computing world is not ideal and it is common to face issues and performance problems in Redis, which require troubleshooting techniques. In this section, let us discuss about commands that help in debugging and also about how to troubleshoot memory issues in Redis.
Redis is a simple piece of software that does not require complex debugging tools to identify the issues. Most of the time the issues in Redis are either due to wrong configuration or bad application design.
We have a couple of tools inbuilt into Redis that can help us identify what is really going on inside Redis. Let us see how to use the monitor
command.
Tip
Warning
The monitor
command adds a lot of overhead to the server and should be used strictly for debugging, and as rarely as possible. The command can reduce the performance of the server significantly.
The
monitor
command, like any other command, issues through redis-cli or Telnet. So open redis-cli or Telnet to connect to Redis.This command streams every command issued to the Redis server back to the client, which helps us to see what our server is going through.
Issue the following command:
redis-cli monitor
After you issue this command, open another redis-cli and issue the following command:
SET Google Android
In our monitor's command-line interface, we can see this command as follows:
1356217734.180621 [0 127.0.0.1:62544] "set" "Google" "Android"
To stop the
monitor
command in redis-cli, you need to use Ctrl + C (SIGINT). Themonitor
command can be used by clients connected through Telnet too, in which case theQUIT
command needs to be used to stop the command.
A software without bugs does not exist. There might be situations when Redis does not behave as it should. Redis has got a solution to provide as much information as possible to the developers to fix the issues.
The Redis Slow log is a system to log queries. The slowlog
command is used to view the commands that exceeded the configured time in our configuration file. This command points out the queries that are running slowly, which can help us design the system better. Using this command, we can read the slow queries and also reset the queue. The Slow log is stored strictly in the memory, and provides quite rapid logging with little to no performance hit at the cost of extra memory to store the log.
To get the current length of the Slow log, use slowlog len
. To read the Slow log, the slowlog get
command should be used. This command returns the complete contents of the log. If you want only the latest N number of entries, pass the number to the command as follows:
slowlog get 2
The output format for the log will be:
1)1) (integer) 7 2) (integer) 1356248799 3) 15 4) 1) "SUNIONSTORE" 2) "Set1" 3) "set2" 4) "set3" 2) 1) (integer) 6 2) (integer) 1356248815 3) 12 4) 1) "SINTER" 2) "Set1" 3) "set2" 4) "set3"
The preceding log output has two entries. Every entry consists of four fields, as follows:
A unique auto-incrementing identifier for every log. The identifier will be reset on server restart.
The Unix timestamp at which the logged command was executed.
The amount of time needed for its execution, in microseconds.
The arguments of the command in the form of an array.
To reset the Slow log, use the slowlog reset
command. Once the command is executed, the log information is lost forever.
In the latest version (v2.6.13) of Redis, a new debugging tool for developers has been introduced, watchdog. It is designed to track latency problems that could escape analysis using normal tools. This feature is still experimental and should be used in production with caution as a last resort when all other means of debugging fail. It is not advisable to keep the watchdog running for an extended period of time. The output is logged into a logfile that contains low-level reports about the server component. The log can be sent to the Redis community to figure out what caused the block in the server and fix the problem, if any, in the server.
To enable the watchdog, you need to use the CONFIG SET
command as follows:
CONFIG SET watchdog-period 700
The preceding command will log any latency issues if the delay is more than 700 milliseconds. The minimum time that can be mentioned is 200 milliseconds.