You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, when AOF is enabled, write() to the AOF file is performed in the main thread. Disk IO can block if the disk is slow and in some other circumstances, which can cause latency spikes. Disk IO can't use non-blocking IO in the same way as we do for sockets. (A disk write() never yields E_AGAIN.)
Even when it doesn't block, a write syscall is still heavy, when all the socket IO syscalls are offloaded to IO threads, leading to lower throughput compared to when AOF is disabled.
Description of the feature
Offload the AOF file writes to the AOF BIO thread that already does the periodic fsync(). There is already a mutexQueue for queuing up multiple jobs to each BIO thread, so it's very strait-forward to queue up writes. Just transfer the owership of the AOF buffer instead of writing it directly to the fd. This happens once per each event loop cycle if are any write commands have been executed.
The offload should be used for all appendfsync modes (always/everysec/no). Whenever the BIO thread does a write, it should attemt to include all queued writes and use writev.
@sumitk163 If we offload write + fsync, we don't gain much with O_DIRECT, do we? I don't understand why O_DIRECT would be beneficial acutally. Can you explain that?
@sumitk163 If we offload write + fsync, we don't gain much with O_DIRECT, do we? I don't understand why O_DIRECT would be beneficial acutally. Can you explain that?
The main benefit is that we bypass the page cache. Since we are already buffering in memory, buffering again in page cache doesn't provide much value, especially given that we call fsync right after every write().
I believe I saw ~5-10% higher throughput with O_DIRECT (the improvement was more significant with write-only workloads using larger payload size like 10KB). However, the test setup was different - I was pre-initilalizing the files with zeroes and using a worker pool instead of a single worker (I tried both io_uring and a bio worker pool) that were performing concurrent pwrite().
We have implemented a similar feature in one of our versions and it has been running in production for years. Its core value lies in optimization for slow storage like cloud disks. It effectively prevents user latency jitter caused by system-wide I/O bursts, such as I/O pressure from multi-process RDB or service unavailability due to cloud disk read-only issues. Performance gain is not our main goal here, as modern SSDs are already performant enough.
Activity
zuiderkwast commentedon May 25, 2026
@sumitk163 If we offload write + fsync, we don't gain much with O_DIRECT, do we? I don't understand why O_DIRECT would be beneficial acutally. Can you explain that?
sumitk163 commentedon May 26, 2026
The main benefit is that we bypass the page cache. Since we are already buffering in memory, buffering again in page cache doesn't provide much value, especially given that we call fsync right after every write().
I believe I saw ~5-10% higher throughput with O_DIRECT (the improvement was more significant with write-only workloads using larger payload size like 10KB). However, the test setup was different - I was pre-initilalizing the files with zeroes and using a worker pool instead of a single worker (I tried both io_uring and a bio worker pool) that were performing concurrent pwrite().
artikell commentedon May 27, 2026
We have implemented a similar feature in one of our versions and it has been running in production for years. Its core value lies in optimization for slow storage like cloud disks. It effectively prevents user latency jitter caused by system-wide I/O bursts, such as I/O pressure from multi-process RDB or service unavailability due to cloud disk read-only issues. Performance gain is not our main goal here, as modern SSDs are already performant enough.