Reference Original: Http://redis.io/topics/latency
More recent data volume, concurrent write operations in many cases, Redis has a slow response situation;
You can use Redis commands to test the response speed of Redis:
redis-cli--latency-h ' xxx '-P ' xxxx '
This command inserts sample data into Redis to check the average delay. CTRL + C can end the test at any time;
Let's make a list of possible delays:
Hardware, System: Hardware problems are the bottom of all problems, if the hardware is slow, such as low CPU, memory, disk IO slow, which will make all the system running in the response is slow, in addition, the use of virtual opportunity to make the system performance is too degraded; Of course, if you have money, the problem is easy to solve; The system resource scheduling of Linux itself also generates some delay. These are generally not very large, negligible;
Network: If the client and Redis are on the same server, using a socket to establish a connection is much faster than listening to the TCP/IP port;
Redis command: Some commands, such as lrem,sort,sunion, which are more complex in time, can take a long time, in addition, a large number of repeated connections can also cause delays, and reuse of connections is a good quality; If you have a lot of write operations, use pipeline Pipeline way (similar to MySQL transaction), a one-time commit, so that the amount of data is less, the number of connections is also less, do not have to return data, the speed will naturally be much faster;
Persistence: Redis persistence needs to fork out a process for persistent operation, which in itself will trigger a delay, if the data changes large, the RDB configuration time is short, then the cost is quite large, plus, hard disk this thing is a bit unreliable, if it is virtual machine on the virtual hard disk, If it's still an NFS shared directory, then this delay will cause you to crash. So, if the system doesn't need to be persisted, turn it off.
Redis provides slowlog can be used to analyze the slow execution of the command, you can analyze the operating system, you can use Iostat to see the speed of the hard disk, using Vmstat to view the memory paging situation;
The overall optimization is good, the system response will be faster;
Troubleshooting Redis Response Latency Issues