Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 10 min read How-to mediumAdept

Supercharging your large ClickHouse data loads - Part 2: Tuning a large data load for speed

Tuning insert block size and insert parallelism lets a 65-billion-row (~14 TiB raw) PyPI load into ClickHouse run almost 3x faster than with default settings on the same hardware. On servers with 59 cores and 236 GiB RAM, the sweet spot was 32 insert threads with 10-million-row blocks. Larger blocks exhaust memory at higher thread counts, while using all cores for inserts starves background merges. A rule of thumb follows: set max_insert_threads to about half the cores, and set min_insert_block_size_bytes to target peak memory / (~3 × threads). With SharedMergeTree in ClickHouse Cloud, ingest throughput scales linearly as servers are added.

Assumes: ClickHouse MergeTree parts and mergesINSERT INTO SELECT

Related posts

  • Supercharging your large ClickHouse data loads - Part 1: Performance and resource usage factors

    ClickHouse mediumAdept

    ClickHouse ingest performance and resource usage for large loads into MergeTree tables are governed by three factors: insert block size, insert parallelism, and hardware size. Larger insert blocks use more memory but produce fewer initial parts and so fewer background merges. Block size is controlled by min_insert_block_size_rows/bytes when the server pulls data, and by max_insert_block_size when clients push data or async inserts are used. Parallelism comes from max_insert_threads, s3/url glob reads, cluster table functions like s3Cluster, and parallel clients, while more CPU and RAM raise part size limits, parallelism and merge throughput.

  • ClickHouse Newsletter October 2022: A cloud has arrived

    ClickHouse mediumAdept

    ClickHouse Cloud entered public beta, storing data on shared object storage reachable by all nodes, so users no longer configure replication, sharding or rebalancing, and storage costs less than on block storage. Version 22.9 adds an experimental `annoy` ANN vector index, a KeeperMap table engine, `insert_quorum = auto`, INTERSECT/EXCEPT DISTINCT and an official TypeScript Node.js client. The query-of-the-month section shows that more threads can hurt. An S3 insert with `max_threads = 100` exhausts memory, while 4 threads beat autodetection by 33%. Under concurrent load, `max_threads = 1` tripled throughput from 3.8 to 13.1 QPS.

  • How we configure huge pages in ClickHouse Managed Postgres

    ClickHouse mediumAdept

    ClickHouse Managed Postgres runs every server's shared_buffers on 2MB huge pages, which avoids per-backend page-table bloat and improves TLB reach. The setup has three parts. A quarter of RAM is reserved as huge pages before Postgres starts, after dropping caches and compacting memory. Postgres is pinned to huge_pages='on' so it fails at boot instead of silently falling back to 4KB pages. shared_buffers is sized in two passes using `postgres -C shared_memory_size` so the full segment, including roughly 750MB of overhead, fits the pool. On an r7i.4xlarge with 32GB shared_buffers, page tables grew 31MB per connection with 4KB pages (6.1GB at 200 connections) versus 111MB total with huge pages, and select-only pgbench throughput rose 12%.

  • Supercharging your large ClickHouse data loads - Part 3: Making a large data load resilient

    ClickHouse mediumAdept

    Multi-day loads of billions to trillions of rows into ClickHouse can survive transient failures by splitting the input into retryable tasks. ClickPipes covers managed ingestion from Kafka. For other sources, the open ClickLoad script loads Parquet files from object storage. Stateless workers claim file-chunk tasks from a KeeperMap-backed table and insert each chunk into a per-worker staging table via INSERT INTO SELECT. On failure they truncate and retry; on success they move partitions to the target table, giving exactly-once storage without costly mutations or deduplication. The design scales roughly linearly with workers and servers (3→6 servers doubled throughput from 4M to 8M rows/s on a 600B-row load), works with any partition key, and also covers projections and materialized views through cloned staging tables.

  • Asynchronous Data Inserts in ClickHouse

    ClickHouse mediumAdept

    ClickHouse asynchronous inserts move batching from the client to the server. Insert data goes into in-memory buffers, one per query shape and settings on each node, and is flushed as larger parts, which avoids the 'Too many parts' error that frequent small synchronous inserts trigger. In a benchmark with a serverless uptime-monitoring app (UpClick), 200 cloud functions inserting every 10 seconds pushed a 3-node ClickHouse Cloud service to the 300-active-part limit within 5 minutes using synchronous inserts. The post then covers buffer flush semantics, deduplication for idempotent retries, errors that only surface at flush time, how asynchronous inserts compare to Buffer tables, and how to tune return behavior and flush settings.

The quest for software engineering knowledge.

Look:
Layout: