Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Asynchronous Append-Only File (AOF) writes are integral to Redis, a popular in-memory data structure storage that supports different types of data structures such as strings, lists, maps, sets, and sorted sets. Redis can replicate the data in its memory to disk enabling durability and data persistence through AOF persistence method.
Understanding Asynchronous AOF fsync
In Redis, the AOF persistence works by logging every write operation received by the server, that will change the dataset, to a file. This AOF file can be used to reconstruct the data upon a server restart. To ensure data integrity, the file needs to be synchronized from time to time using fsync(), a system call that flushes the file's state back to disk.
When fsync() is set to run asynchronously (appendfsync everysec), Redis issues the fsync() operation in a separate thread once every second. This is generally effective for balancing between performance and data safety. However, this asynchronous operation can encounter issues, particularly when the disk is under heavy load or is unable to cope with the volume of data Redis is attempting to write.
Common Issues with Asynchronous fsync Taking Too Long
The message, "Asynchronous AOF fsync is taking too long (disk is busy?). Writing the AOF buffer without waiting for fsync to complete, this may slow down Redis," typically indicates heavy disk usage or sub-optimal disk performance. Essentially, this warning suggests that the disk cannot perform the fsync() frequently enough (at least once per second as expected), leading to potential latency issues as the input buffer continues to fill.
Here’s how this impacts Redis:
- Increased latency: Because the disk can’t catch up with the rate of
fsync()operations, command processing can become slower. - Data safety risks: In scenarios where the disk is unable to
fsync()frequently enough, there is a risk of losing more data during an unexpected shutdown. - Backpressure: When Redis continues to write to the AOF buffer without the completion of
fsync(), it can lead to increased memory usage – affecting instance stability and performance.
Solutions and Optimizations
1. Disk Performance Analysis
Begin by analyzing the disk performance using tools like iostat, vmstat, or atop to monitor I/O utilization and throughput. Look for metrics on average service time and queue length, which can indicate bottlenecks.
2. Hardware Improvements
For load-intensive applications, consider using faster SSDs or NVMe drives which offer better I/O performance and lower latency compared to traditional mechanical disks.
3. Configuration Adjustments
- Adjust the frequency of the
fsyncoperations based on your workload characteristics and tolerance for data loss. - Consider splitting the AOF onto different physical disks to distribute the load.
4. Redis Tuning
- Increase
auto-aof-rewrite-percentageandauto-aof-rewrite-min-sizesettings, so Redis rewrites the AOF file less frequently, enlarging the AOF file gradually rather than in spurts. - Employ the
no-appendfsync-on-rewriteoption, which if set, avoids callingfsync()during AOF rewrites if anotherfsync()operation is still in progress.
Conclusion
Disk-related delays in asynchronous AOF synchronization impact performance and data durability in Redis. Through proper system monitoring, hardware enhancements, thoughtful configuration, and Redis-specific optimizations, these issues can be managed to ensure smoother, more reliable operations.
Summary Table
| Metric or Issue | Optimization Strategy |
| Disk Latency and Throughput | Use iostat and atop for measurement. Opt for faster SSDs. |
| fsync() Frequency | Adjust appendfsync settings based on data loss tolerance. |
| Redis Configuration | Optimize AOF rewrite and fsync() integration settings. |
| Memory Usage and Backpressure | Monitor and adjust Redis memory allocation settings. |
This comprehensive approach will help mitigate the risks associated with asynchronous AOF fsync delays, potentially boosting both the performance and reliability of Redis in production environments.

