Skip to content

perf(clickhouse): load multiple staged batches per raw table insert - #4996

Open
dtunikov wants to merge 1 commit into
mainfrom
customer-ch-raw-copy-multi-file
Open

dtunikov wants to merge 1 commit into
mainfrom
customer-ch-raw-copy-multi-file

Conversation

@dtunikov

@dtunikov dtunikov commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Normalize copies staged Avro files into the raw table one INSERT per batch. ClickHouse decodes a single Avro file on one stream, so this step is bound to ~1 core (seen in prod: ~55s CPU ≈ 57s wall per 100k-row batch, with max_threads=89). max_insert_threads does not help since the source is the bottleneck.

Adds PEERDB_CLICKHOUSE_RAW_COPY_FILES_PER_INSERT (default 1, current behavior). With N > 1, up to N batch files are loaded by one INSERT ... SELECT * FROM s3(f1) UNION ALL SELECT * FROM s3(f2) ..., so each file gets its own stream. Rows already carry _peerdb_batch_id, so no per-file metadata is needed. Works for both S3 and GCS (signed url()) staging. The raw table checkpoint advances per INSERT.

Default is kept at 1 because a single-file raw insert already peaks at ~15 GB memory for large documents; N files in parallel can multiply that.

🤖 Generated with Claude Code

The S3 -> raw table copy during normalize issued one INSERT per batch file.
ClickHouse decodes a single Avro file on one stream, so each copy was bound
to one core regardless of max_threads/max_insert_threads.

Add PEERDB_CLICKHOUSE_RAW_COPY_FILES_PER_INSERT (default 1) to load N batch
files with a single INSERT ... SELECT ... UNION ALL ..., one branch per file,
letting ClickHouse read and decode them in parallel. The raw table checkpoint
advances per INSERT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dtunikov
dtunikov marked this pull request as ready for review October 30, 2026 12:46
@dtunikov
dtunikov requested a review from a team as a code owner October 30, 2026 12:46

This branch has not been deployed

No deployments
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