Skip to content

events: batch fetched payload copies into arenas - #1047

Draft
tamirms wants to merge 1 commit into
mainfrom
tamirms/events-fetch-arenas-fanout
Draft

tamirms wants to merge 1 commit into
mainfrom
tamirms/events-fetch-arenas-fanout

Conversation

@tamirms

@tamirms tamirms commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Hot fetch: the batched read's options are built once at open, the key list is cut from one buffer, each pinned value is read once, and the values are copied into one arena per batch.
  • Cold fetch: payloads are copied into arenas. Each callback takes one from a per-call pool, so concurrent reads never share an arena and no lock is needed.

Why

  • Allocations: a hot fetch now makes two heap allocations per event id, both inside grocksdb, which TestHotStore_FetchEventsAllocationBudget pins. A cold 1,000-event page makes about 50 instead of 1,025.
  • Throughput: with warm caches, eight concurrent fetchers move 10% more hot pages and 17% more cold pages per second, and cold p99 is 21% lower.
  • The pool: a single arena behind a lock made a cold fetch with 8 reads in flight 38% slower. With the pool a fetch costs what it did without arenas. The fan-out test forces an 8-way read and compares whole payloads.

Split out of #968. The cold read concurrency this PR used to set is now #1083, in the getEvents stack.

Known limitations

  • The gains show when reads are CPU-bound: the hot store, or cold chunks in the page cache or on NVMe. On EBS a cold page fetch spends milliseconds on reads, so they would not show there.

🤖 Generated with Claude Code

@tamirms
tamirms force-pushed the tamirms/events-fetch-arenas-fanout branch from e3e8c07 to 918ee23 Compare October 5, 2026 13:36
@tamirms tamirms changed the title events: batch fetched payload copies into arenas, and fan cold reads out events: batch fetched payload copies into arenas Oct 5, 2026
Hot fetch: the batched read's options are built once, at open; the key
list is cut from one buffer; each pinned value is read once; and the
values are copied into one arena per batch instead of one allocation
each. A fetch now makes two heap allocations per event id, both inside
grocksdb, which TestHotStore_FetchEventsAllocationBudget pins.

Cold fetch: payload copies go into arenas instead of one allocation
each. A cold reader with a concurrency above one makes packfile's
ReadItems call back from several goroutines, so each callback takes an
arena from a per-call pool for its copy and no two share one. A single
shared arena behind a lock made a fetch with 8 reads in flight 38%
slower; with the pool it costs what the unpooled copies did.

With warm caches, a 1,000-event page now makes 2,010 allocations
instead of 4,008 hot and about 50 instead of 1,025 cold, and eight
concurrent fetchers move 10% more hot pages and 17% more cold pages per
second, with cold p99 21% lower.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JCzMKKrK3NstGKvaxsHhL2
@tamirms
tamirms force-pushed the tamirms/events-fetch-arenas-fanout branch from 918ee23 to c3db605 Compare October 5, 2026 15:58
Base automatically changed from feature/full-history to main October 22, 2026 19:31
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