Skip to content

perf(bench): parallelize sample gzip, receipt collection, and ClickHouse inserts - #368

Open
shekhirin wants to merge 5 commits into
mainfrom
perf/faster-bench-postprocessing
Open

shekhirin wants to merge 5 commits into
mainfrom
perf/faster-bench-postprocessing

Conversation

@shekhirin

Copy link
Copy Markdown
Member

Summary

Speeds up post-run benchmark processing in bench-core and bench-cli:

  • Parallel multi-member gzip for sample archives (crates/bench-core/src/reporter.rs): Replaces single-threaded GzEncoder with ParallelGzipWriter (up to 16 threads, 4 MiB chunks, level-6 Compression::default(), valid RFC 1952 multi-member gzip). Cuts .samples.ndjson.gz writing from ~31s to ~6.4s on multi-region runs while preserving ~146 MiB output size.
  • Lightweight work-stealing block receipt collection (crates/bench-core/src/receipt_metrics.rs, crates/bench-cli/src/send.rs):
    • Adds BlockReceiptCollector::finish_with_providers to fan out eth_getBlockReceipts across all configured RPC endpoints using a dynamic AtomicU64 work queue (so low-RTT validators absorb most blocks instead of stalling behind high-RTT regions).
    • Deserializes only the 7 fields needed for gas metrics via MinimalBlockReceipt (skipping logs, logsBloom, and extra network fields).
    • Uses HashMap/HashSet for tracked-tx deduplication and avoids cloning label maps per record during aggregation.
    • Cuts post-run receipt collection for ~180 blocks (~800k receipts) from ~37s to ~6s.
  • Gzipped & concurrent ClickHouse inserts (crates/bench-core/src/clickhouse.rs, crates/bench-core/src/receipt_clickhouse.rs, crates/bench-core/src/reporter.rs):
    • Compresses ClickHouse JSONEachRow payloads >= 4 KiB with Content-Encoding: gzip.
    • Filters metric samples before batching into full sample_batch_size chunks and sends up to 6 batches concurrently for both metric samples and txgen_receipt_gas inserts.

Verification

  • cargo test -p bench-core --lib (174 passed, including minimal_block_receipt_ignores_logs_and_extra_fields, gzips_large_clickhouse_payloads, and parallel_gzip_writer_produces_valid_multi_member_gzip)
  • cargo test -p bench-cli --bins (48 passed)
  • cargo test -p bench-core --test sender_auth -- --test-threads=2 (29 passed)
  • Verified end-to-end on 10-validator multi-region GCP benchmarks (100 GiB bloat, public-mix, 90s).

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's remaining monthly code review budget is too low to start another review, so this review was not started.

An organization admin can view or raise the monthly spending cap at claude.ai/admin-settings/usage, on the Claude Code Review row under Services. The cap resets at the start of the next billing period.

Once the cap resets or is raised, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Comment thread crates/bench-cli/src/send.rs Resolved
Comment thread crates/bench-core/src/reporter.rs Resolved
Comment thread crates/bench-core/src/reporter.rs Resolved

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest push brings back an issue flagged in an earlier review; replied in that comment's thread.

Still open from earlier reviews (1):

  • 🔴 crates/bench-cli/src/send.rs:81 — Multi-validator bench send runs can now fail at the end with "failed to collect block receipts" when any validator lags…

If you have decided not to act on one of these findings, resolve its thread (a reply alone leaves it open) and the next review stops counting it. To review this commit again now, use Re-run on its "Claude Code Review" check.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I re-reviewed the latest push and found no new bugs. The PR hand-rolls a deflate/gzip writer with a CRC-32 combine port and adds concurrent RPC and ClickHouse paths, so a human look is still worthwhile.

What was reviewed:

  • Receipt fan-out: when a secondary provider returns null or errors, the block is now fetched from providers[0], and a secondary that errors stops taking blocks. A lagging validator no longer fails the run.
  • ParallelGzipWriter: it now writes a single gzip member (sync-flushed raw deflate chunks, then an empty final block and the combined CRC/ISIZE trailer), and an empty input still produces a valid gzip file.
  • ClickHouse: receipt rows are built lazily inside the bounded buffer_unordered stream, and only bodies of 4 KiB or more get gzip with Content-Encoding.
Extended reasoning...

The change touches five files in bench-core and bench-cli: receipt collection across RPC providers, a custom parallel gzip encoder for the samples sidecar, and concurrent gzipped ClickHouse inserts. No auth, crypto or permission surface is involved. The ClickHouse credential headers are passed through unchanged. Later commits appear to address the earlier inline findings (lagging providers, multi-member and empty gzip, eager receipt row building). I deferred because the change is about 700 lines and includes a hand-written deflate framing and CRC-32 combine whose correctness rests on a few unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant