Group Commit and fsync Latency Under NVMe Queue Depth

Synchronous durability is rarely bound by sequential NVMe bandwidth. Under high concurrency, cache-flush serialization turns small commits into a queue-depth bottleneck unless writers coordinate through a group-commit barrier.

Every transactional storage engine eventually faces the same physical constraint: write(2) places dirty pages in the page cache, while fdatasync(2) sends an explicit cache-flush or Forced Unit Access (FUA) command down to the controller. Even when a PCIe 4.0 drive sustains 5 GB/s of streaming throughput, individual flush barriers cost between 180 microseconds and 1.2 milliseconds once write queues saturate.

If sixty-four client goroutines independently append 512-byte WAL frames and each calls fdatasync() under a mutex, sixty-three threads stall behind every single metadata update. Even without an application-level lock, the filesystem journal (ext4 JBD2 or XFS CIL) serializes overlapping durability barriers.

Why naive pipelining hits a wall

Replacing individual flushes with a single leader thread fixes lock contention only halfway. When the leader drains the pending batch immediately, writes that arrive two microseconds after the flush starts are forced to wait an entire disk round-trip before entering the next batch.

Minimal Go group-commit coordinator batching pending WAL entries behind a single fdatasync barrier:
commit_group.go
type pendingWrite struct {
    payload []byte
    done    chan error
}

func (w *WAL) runCommitLoop(flushWindow time.Duration) {
    batch := make([]pendingWrite, 0, 128)
    for {
        first := <-w.queue
        batch = append(batch[:0], first)

        timer := time.NewTimer(flushWindow)
    collect:
        for len(batch) < 128 {
            select {
            case next := <-w.queue:
                batch = append(batch, next)
            case <-timer.C:
                break collect
            }
        }
        timer.Stop()

        err := w.writeVectoredAndSync(batch)
        for _, item := range batch {
            item.done <- err
        }
    }
}

Choosing a delay ceiling on modern NVMe

Intuitively, adding an artificial timer of 250 microseconds looks harmful to p50 latency. At low concurrency (1–2 writers), it genuinely adds a quarter millisecond. At 32 or 64 concurrent writers, however, amortizing one fdatasync() over forty buffered entries shrinks the queue backlog inside the block layer so p99 falls sharply.

Batch Window Writers P50 Latency P99 Latency Commits / sec
0 us (Immediate) 64 1.95 ms 4.82 ms 31,400
100 us 64 1.22 ms 2.61 ms 52,100
250 us 64 0.84 ms 1.41 ms 74,800
1,000 us 64 1.31 ms 2.15 ms 79,200

Notice the inflection around 250 microseconds: pushing the timer up to 1 millisecond increases throughput only marginally (from 74.8k to 79.2k commits/s) while forcing every light-load transaction to wait nearly a full millisecond even when the drive is idle.

Adaptive triggers beat static timers

Instead of unconditionally sleeping for the full batch window when traffic drops, only arm the short delay when queue depth shows active contention—for instance, when at least two callers were already waiting at the previous sync return. Under single-writer bursts, flushing immediately preserves sub-250 microsecond p50 latency while automatically switching into 250 us coalescing whenever concurrency climbs.

Setting a small commit delay allows multiple transactions committing close together to share a single disk flush whenever active backends exceed the configured sibling threshold.

Before tuning storage durability timers in production, always capture baseline biolatency histograms on the target NVMe namespace: consumer drives without power-loss protection can exhibit 15–40 ms cache-flush spikes that completely dominate a sub-millisecond application timer.