Let's talk about the potential blocking points of AOF in Redis (summary)
What are the potential blocking points of AOF? The following article summarizes some potential blocking points of AOF in Redis. I hope it will be helpful to you!
What are the potential blocking points of AOF
1. When Redis uses the fork child process to rewrite the AOF file, there are potential Blocking risk
1), fork child process
Fork child process, the main thread will definitely be blocked at the moment of fork (note that fork will not be a one-time Copy all memory data to the child process), fork uses the Copy On Write mechanism provided by the operating system, in order to avoid the long-term blocking problem caused by copying a large amount of memory data at once to the child process. [Related recommendations: Redis video tutorial]
But the fork child process needs to copy the necessary data structures of the process, one of which is copying the memory page table (virtual memory and Physical memory mapping index table), this copy process will consume a lot of CPU resources. The entire process will be blocked before the copy is completed. The blocking time depends on the memory size of the entire instance. The larger the instance, the larger the memory page table. The longer the fork blocking time.
After the copy of the memory page table is completed, the child process and the parent process point to the same memory address space. That is to say, although the child process is generated at this time, it does not apply for the same memory size as the parent process.
When will the memory of the father and son processes be truly separated?
"Realistic copy", as the name suggests, actually copies the real data in the memory when writing occurs. During this process, the parent process may also be at risk of blocking, which is the scenario introduced below.
2), The parent process writes during AOF rewriting
The fork child process points to the same memory as the parent process address space, at this time the child process can perform AOF rewriting and write all the data in the memory to the AOF file.
But at this time, the parent process will still have traffic written. If the parent process operates an existing key, then at this time the parent process will actually copy the memory data corresponding to the key and apply for a new one. In this way, gradually, the memory data of the father and son processes begin to separate, and the father and son processes gradually have their own independent memory spaces. Because memory allocation is allocated in units of pages, the default is 4k. If the parent process is operating a bigkey at this time, it will take longer to reapply for a large block of memory, which may cause the risk of blocking.
In addition, if the operating system turns on the huge page memory mechanism (Huge Page, page size 2M), then the probability of blocking when the parent process applies for memory will be greatly increased, so in the Redis machine The Huge Page mechanism needs to be turned off. Every time Redis forks to generate RDB or AOF rewrite is completed, you can see in the Redis log how much memory space the parent process has reapplied for.
3) Why doesn’t AOF rewrite reuse AOF’s own logs?
AOF rewrite doesn’t reuse AOF’s own logs:
One reason is that writing the same file between parent and child processes will inevitably cause competition problems. Controlling competition means that it will affect the performance of the parent process.
The second is that if the AOF rewrite process fails, then the original AOF file is equivalent to being contaminated and cannot be restored and used. Therefore, Redis AOF rewrites a new file. If the rewriting fails, just delete the file directly. It will not affect the original AOF file. After the rewriting is completed, just replace the old file.
For more programming-related knowledge, please visit: Programming Video! !
The above is the detailed content of Let's talk about the potential blocking points of AOF in Redis (summary). For more information, please follow other related articles on the PHP Chinese website!

Redis's core functions include memory storage and persistence mechanisms. 1) Memory storage provides extremely fast read and write speeds, suitable for high-performance applications. 2) Persistence ensures that data is not lost through RDB and AOF, and the choice is based on application needs.

Redis'sServer-SideOperationsofferFunctionsandTriggersforexecutingcomplexoperationsontheserver.1)FunctionsallowcustomoperationsinLua,JavaScript,orRedis'sscriptinglanguage,enhancingscalabilityandmaintenance.2)Triggersenableautomaticfunctionexecutionone

Redisisbothadatabaseandaserver.1)Asadatabase,itusesin-memorystorageforfastaccess,idealforreal-timeapplicationsandcaching.2)Asaserver,itsupportspub/submessagingandLuascriptingforreal-timecommunicationandserver-sideoperations.

Redis is a NoSQL database that provides high performance and flexibility. 1) Store data through key-value pairs, suitable for processing large-scale data and high concurrency. 2) Memory storage and single-threaded models ensure fast read and write and atomicity. 3) Use RDB and AOF mechanisms to persist data, supporting high availability and scale-out.

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

The main difference between Redis and SQL databases is that Redis is an in-memory database, suitable for high performance and flexibility requirements; SQL database is a relational database, suitable for complex queries and data consistency requirements. Specifically, 1) Redis provides high-speed data access and caching services, supports multiple data types, suitable for caching and real-time data processing; 2) SQL database manages data through a table structure, supports complex queries and transaction processing, and is suitable for scenarios such as e-commerce and financial systems that require data consistency.

Redisactsasbothadatastoreandaservice.1)Asadatastore,itusesin-memorystorageforfastoperations,supportingvariousdatastructureslikekey-valuepairsandsortedsets.2)Asaservice,itprovidesfunctionalitieslikepub/submessagingandLuascriptingforcomplexoperationsan

Compared with other databases, Redis has the following unique advantages: 1) extremely fast speed, and read and write operations are usually at the microsecond level; 2) supports rich data structures and operations; 3) flexible usage scenarios such as caches, counters and publish subscriptions. When choosing Redis or other databases, it depends on the specific needs and scenarios. Redis performs well in high-performance and low-latency applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment
