Skip to content

Start writeback of the index as it is written (WithBytesPerSync) - #29

Open
tamirms wants to merge 1 commit into
mainfrom
index-writeback
Open

tamirms wants to merge 1 commit into
mainfrom
index-writeback

Conversation

@tamirms

@tamirms tamirms commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

A build writes the whole index through the page cache and syncs once at the end. For a large index the dirty pages pile up and reach the disk in bursts, and while a burst drains, other writers' fsyncs on the same disk wait behind it.

WithBytesPerSync(n) starts writeback of the file every n bytes written. On Linux that is sync_file_range with SYNC_FILE_RANGE_WRITE, which returns without waiting; elsewhere the option does nothing. The final Sync still makes the file durable, and the index is byte-identical with or without the option: the new test builds on 1 and 4 workers with writeback every 1 KB. The default stays 0, which leaves writeback to the kernel.

In stellar-rpc, ingestion fsyncs a RocksDB WAL for every ledger while the tx-hash index builds on the same NVMe. With a 4.3 billion key (18.6 GB) index building back to back and writeback every 1 MB, the ingestion commit's p99 went from 44.6 ms to 26.3 ms, the same as with no build running, and a ledger's p99 from 103.8 ms to 94.6 ms. The build itself took 153 s, against 151 s without the option.

The unsorted builder's temporary partition files are not covered. They are unlinked while open and never synced, so forced writeback only helps them when they are large enough to reach the disk anyway.

🤖 Generated with Claude Code

A build writes the whole index through the page cache and syncs once at
the end, so a large index's dirty pages pile up and go to disk in bursts
that hold up other writers' fsyncs on the same disk. WithBytesPerSync(n)
starts writeback every n bytes written (sync_file_range without waiting,
on Linux; a no-op elsewhere). The index built is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DjQed1VX9uGU9PWpAjBiz7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant