Home  >  Article  >  Database  >  What are the problems with redis performance?

What are the problems with redis performance?

(*-*)浩
(*-*)浩Original
2019-06-18 13:59:382161browse

The following are the common performance problems of Redis?

What are the problems with redis performance?

Master writes a memory snapshot and the save command schedules the rdbSave function, which will block the work of the main thread and affect performance when the snapshot is relatively large. It is very large and will suspend services intermittently, so it is best not for the Master to write memory snapshots. (Recommended learning: Redis video tutorial)

Master AOF persistence, if the AOF file is not rewritten, this persistence method has the smallest impact on performance. However, the AOF file will continue to grow. If the AOF file is too large, it will affect the recovery speed of Master restart.

Master calls BGREWRITEAOF to rewrite the AOF file. AOF will occupy a large amount of CPU and memory resources during rewriting, resulting in excessive service load and brief service suspension.

The following is the situation of one of my actual projects. The general situation is as follows:

One Master, 4 Slaves, no Sharding mechanism, just Reading and writing are separated. The Master is responsible for writing operations and AOF log backup. The AOF file is about 5G, and the Slave is responsible for reading operations. When the Master calls BGREWRITEAOF, the load on the Master and Slave will suddenly increase sharply, and the Master's write requests will basically not respond. , lasted for about 5 minutes, and the Slave was unable to respond in time to more than half of the read requests. The above situation would not and should not happen, because the Master's machine used to be a Slave, and there was a shell scheduled task on it every morning. At 10 o'clock, BGREWRITEAOF was called to rewrite the AOF file. Later, because the Master machine was down, the backup Slave was changed to Master. However, this scheduled task was forgotten to be deleted, which led to the above tragic situation. It took several days to find the reason. Just found it.

Set the no-appendfsync-on-rewrite configuration to yes to alleviate this problem. Setting it to yes means that new write operations will not be fsyncd during rewrite and will be temporarily stored in the memory until rewrite is completed before writing. It is best not to enable the AOF backup function of the Master.

Performance issues of Redis master-slave replication, the first implementation of Slave synchronization to Master is: Slave sends a synchronization request to Master, Master first dumps the rdb file, and then dumps the entire rdb file Transmit to the slave, and then the master forwards the cached command to the slave, and the initial synchronization is completed. The second and subsequent synchronization implementation is: Master sends snapshots of variables directly to each Slave in real time. No matter what causes the Slave and Master to disconnect and reconnect, the above process will be repeated. Redis's master-slave replication is based on the persistence of memory snapshots. As long as there is a Slave, there will be a memory snapshot. Although Redis claims that master-slave replication is non-blocking, due to disk IO limitations, if the Master snapshot file is relatively large, the dump will take a long time. During this process, the Master may not be able to respond to the request, which means that the service will be interrupted. For critical Service, the consequences of this are also terrible.

The reasons for the above 1.2.3.4 fundamental problems are all inseparable from the system io bottleneck problem, that is, the hard disk read and write speed is not fast enough, and the main process fsync()/write() operation is blocked.

Single point of failure problem Since the current master-slave replication of Redis is not mature enough, there is an obvious single point of failure problem. Currently, we can only solve this problem by ourselves, such as active replication. , Proxy implements Slave's replacement of Master, etc. This is also one of the current priority tasks of the Redis author.

For more Redis-related technical articles, please visit the Introduction to Using Redis Database Tutorial column to learn!

The above is the detailed content of What are the problems with redis performance?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn