Skip to content

Seal a bulk table's remainder once its input idles - #268

Closed
serprex wants to merge 1 commit into
mainfrom
split/bulk-idle-flush
Closed

serprex wants to merge 1 commit into
mainfrom
split/bulk-idle-flush

Conversation

@serprex

@serprex serprex commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Final partial batch after bulk input waits for full flush timeout, delaying acknowledgement. Seal bulk remainder after input idles for one tenth of timeout. Preserve full timeout for subsequent trickle batches.

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 emit::pipeline::batcher (17 passed). Rebuild crate for each isolated diff.

Measured impact (2026-10-22)

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

Workload Base (ms) PR (ms) Median change
Bulk remainder after three rows at row budget 2 501.43 [501.04, 501.87] 51.48 [51.33, 51.67] -89.7%
Following single trickle row 500.70 [500.61, 501.68] 500.85 [500.60, 501.65] +0.0%

Workload: production batcher, one table, 500 ms flush timeout, row budget 2. Send three rows; consume full batch and time final one-row remainder. Then send one additional row and time its seal. Verify both partial batches contain one row and batcher exits without fatal error. Uses real timers. Measures batch sealing latency before inserter/ClickHouse acknowledgement; concurrent traffic to other tables was not measured.

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.

A table's partial batch waits for its row or byte budget or for
flush_timeout (1 s by default) after its first row. When a burst or a
catch-up ends, its last partial batch therefore sits a full timeout
before it reaches ClickHouse, and every acknowledgement behind it
waits with it: about 1 s of the write-heavy repro's tail, where every
earlier batch had sealed by budget.

A table whose last batch sealed by budget is taking rows in bulk, so
seal its partial batch as soon as the batcher has had no input for a
tenth of flush_timeout. Its next partial batch is not bulk and waits
out the full timeout again, so a trickle still coalesces as before,
and at most one short batch follows each full one. ClickHouse still
acknowledges each row before the resume-safe position passes it.

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

serprex commented Nov 9, 2026

Copy link
Copy Markdown
Member Author

I don't think this is a good change. Our focus should be on consistency: trying to maintain throughput with a given latency target. If latency target is 500ms there's no need to try get bursty workload to send in 50ms. Maybe bursty workload hits every 100ms so you end up sending 5 inserts now with 50ms latency instead of 500ms latency, but 500ms might've been chosen to avoid too many parts. I'm already unsure 500ms will play nice with parts. This same argument only applies more if walshadow configured with 10s flush timeout

@serprex serprex closed this Nov 9, 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