Skip to content

Free dispatched record batches off the queue worker - #264

Closed
serprex wants to merge 1 commit into
mainfrom
split/batch-drop
Closed

serprex wants to merge 1 commit into
mainfrom
split/batch-drop

Conversation

@serprex

@serprex serprex commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Queue worker frees pump-allocated record payloads across threads after each batch. Move completed batch destruction onto blocking pool so frees no longer occupy serial dispatch stage.

Extracted from original #228 and based directly on main. Contains no changes from #226 or other extracted PRs.

Validation: cargo fmt --all -- --check, cargo clippy --workspace --all-targets --locked -- -D warnings, and cargo test --locked --lib source::queueing_record_sink (15 passed). Rebuild crate for each isolated diff.

Measured impact (2026-10-22)

Compared f9168a30a0160ec60ee2800ece162953fe7771c2 against shared parent 151fd47cbd75ec7b9bc63ffe7040f049e702ecd0, with each PR built separately.

Workload Base (ns/record) PR (ns/record) Median change
Position-only records 18.60 [17.15, 21.02] 31.37 [24.57, 68.48] +68.6%
Wanted records, 0-byte owned payload 42.26 [40.69, 43.13] 38.92 [30.44, 50.06] -7.9%
Wanted records, 256-byte owned payload 51.10 [49.92, 60.62] 56.84 [51.64, 68.34] +11.2%
Wanted records, 4096-byte owned payload 127.19 [119.30, 134.46] 129.25 [123.49, 148.38] +1.6%
Workload Base (KiB) PR (KiB) Median change
Queue matrix, peak process RSS 62996.00 [28328.00, 75844.00] 107124.00 [77220.00, 108688.00] +70.0%

Workload: 262,144 records per case through production QueueingRecordSink, no-op downstream batch sink, batch size 512, capacity 131,072, two Tokio runtime workers. Timed scope includes record/payload allocation, dispatch, close, and runtime shutdown, which waits for detached blocking frees. RSS covers complete matrix, including skipped-record controls; it is not per-case retained memory.

Result: no consistent dispatch gain in this workload. Position-only cost increased 68.6%; median peak RSS increased 70.0%. Wanted-record timing ranges overlap across revisions.

Detached destruction adds a blocking-pool submission for every completed batch, including empty position-only batches. Queue depth decrements before destruction finishes, so pending free jobs retain memory outside queue accounting. These measurements isolate dispatch/free costs; a decoder-bound production workload may behave differently.

AMD Ryzen 7 7840U; rustc 1.99.1; locked dependencies; optimized release builds; mimalloc 0.1.52. Seven trials per revision, alternating base/PR order, pinned to CPUs 2,4,6 (three physical cores). Values show median [min, max]; negative time changes mean less work or waiting. Local component measurements, without PostgreSQL or ClickHouse services.

Records are parsed and owned on the pump thread, so every block and
main data buffer the serial queue worker dropped was a cross-thread
mimalloc free, about 6% of the worker's cycles on the lifecycle
benchmark. The worker is the stage the pump waits on, so hand each
finished batch to the blocking pool to drop instead; one spawn per 512
records costs far less than the frees it moves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@serprex

serprex commented Oct 22, 2026 •

Copy link
Copy Markdown
Member Author

seems inconclusive, have doubts re overhead of spawning tasks

@serprex serprex closed this Oct 22, 2026
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.

2 participants