Skip to content

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

ClickHouse 12 min read Deep dive mediumAdept

Designing the new async-native ClickHouse Python client

The new async-native clickhouse-connect client replaces the legacy thread-pool wrapper with aiohttp for network I/O and a half-sync/half-async design: an async producer streams response chunks into a bounded queue (10 chunks of up to 1MB) while the existing synchronous Native-format parser consumes them in an executor thread, with the same queue reversed for inserts. This caps buffered memory at about 10MB, pipelines download and parsing, and propagates errors across the boundary. Benchmarks against ClickHouse Cloud show parity at concurrency 1 and a 1.16x geometric-mean speedup overall, up to 1.51x on mixed workloads. P95 latency is also far more stable than with the legacy client. The release candidate v0.12.0rc1 is available for testing.

Assumes: Python asyncioGIL and thread poolsHTTP streaming

Related posts

  • ClickHouse v21.11 Released

    ClickHouse mediumAdept

    ClickHouse 21.11 adds asynchronous inserts, which buffer many small concurrent INSERTs server-side and flush them as a single batch. This removes the need for Kafka or buffer tables in high-rate ingestion, and it is tunable via async_insert, wait_for_async_insert, async_insert_threads, async_insert_max_data_size and async_insert_busy_timeout_ms. The release also brings an interactive clickhouse-local CLI that needs no server, executable UDFs written in any language, named predefined connections to external sources such as MySQL and S3, and automatic compression handling for INTO OUTFILE and FROM INFILE.

  • 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.

  • Introducing the (blazing fast!) native TCP client for .NET

    ClickHouse mediumAdept

    ClickHouse's new experimental .NET client in the ClickHouse.Driver package speaks the native TCP protocol and the columnar Native format. This removes the row/column conversions that HTTP with RowBinary forces on both server and client. It is built on zero-copy, pooled buffers and MemoryMarshal reinterpretation, with compiled expression-tree mappers for POCOs and SIMD where wire and .NET layouts differ (e.g. UUID). The result is 1.5-2x faster reads and inserts than HTTP, up to 1.1M rows/s on a single stream, and allocations for a 1M-row read cut from 1.6 GB to 6 MB. The tradeoffs: no ADO.NET/ORM support, text-only JSON, borrowed blocks valid for one iteration, and little gain on the object[] tier.

  • How InMobi achieved 20x faster queries and 80% cost savings with ClickHouse

    ClickHouse mediumAdept

    InMobi moved its publisher-facing real-time ad reporting APIs from a serverless warehouse on blob storage to ClickHouse. P99 latency at peak dropped from over 60s to under 3s, and monthly cost fell from $40K to $8K. The workload is 400K+ daily queries over 10 TB of uncompressed data, which compresses to about 500 GB. Key engineering choices include: - hourly Spark ingestion into staging tables, validated and then promoted atomically via MOVE PARTITION to avoid duplicates from retries - isolated reader and ephemeral writer compute over shared storage - gevent-based async connection handling to fix OOMs caused by per-session memory overhead - automatic fallback to the old platform when failures exceed 2% in a 5-minute window Cost now scales in steps with added replicas, each adding about 30% capacity, rather than linearly with traffic.

  • 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.

The quest for software engineering knowledge.

Look:
Layout: