Chasing that 32 ms tail latency in ClickHouse
An extra full round trip (~32 ms) on simple SELECTs over ClickHouse's Native protocol came from TCP_NODELAY turning each end-of-query metadata packet (Logs, Progress, ProfileEvents) into its own TCP segment. After 2 seconds idle, Linux had reset the congestion window to initcwnd (8 MSS), so the server stalled waiting for an ACK before it could send EndOfStream. The team reproduced this deterministically with network namespaces, tc netem and a Go client, and weighed workarounds: disabling tcp_slow_start_after_idle, raising initcwnd, or using TCP_CORK. They fixed it by batching non-time-sensitive metadata packets into a single socket write, which roughly halved server-side segments (50 to 25) and cut tail latency from ~32 ms to ~1 ms.
Related posts
- From v0.7 to v0.8: How group commit changed Turso's tail latency
Turso mediumAdeptTurso v0.8 adds group commit to its MVCC write path so that concurrent committers share a single fsync of the logical log instead of each paying for their own. In v0.7 a commit lock was held across pwrite and fsync, so with k concurrent committers the last waited for k flushes. Under a 1,000 TPS Poisson load, tail latency ballooned to seconds (p99.9 up to 157 s at 32 connections). In v0.8 committers enqueue log records and get tickets, and the first to take the lock leads, writing all queued records and fsyncing once while the others park until their ticket is durable. That cuts p50 to about 1 ms and p99.9 to 2.4–14 ms, below SQLite's in every configuration, with tail latency improving as connections increase.
- Kafka, Latency, and You: Minimizing Latency with Kafka & ClickHouse
ClickHouse mediumAdept
End-to-end latency in a Kafka → Kafka Connect → ClickHouse pipeline can be measured by stamping messages with offset, partition, timestamp and topic via single message transforms, recording insert time with a DEFAULT now() column, and charting median/p75/p95 deltas per minute in SQL. Tuning levers include consumer fetch and poll settings (fetch.min/max.bytes, fetch.max.wait.ms, max.poll.records), keeping partitions modest with at least one task per partition, and batching inserts of 10,000–100,000 rows to avoid "Too Many Parts" errors. On the ClickHouse Cloud side, idle-sleep timeouts, instance sizing, and asynchronous inserts can cut latency, with async inserts giving weaker durability guarantees.
- Designing the new async-native ClickHouse Python client
ClickHouse mediumAdept
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.
- 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.
- We’re making Tailscale faster
Tailscale mediumAdept
Tailscale is speeding up its Linux and Android data plane by parsing small packets in place inside the large GRO read buffer instead of copying each into its own 64 KiB buffer, which gave roughly a 5% speed-up. It is also shortening packet queues and using writev to hand scattered packet pieces to the kernel without copying. The freed memory funds a multi-queue pipeline for subnet routers, app connectors and exit nodes, where each flow is pinned to one of several parallel lanes sized to CPU resources, preserving per-stream ordering while using more cores. Netmap caching lets clients start from an on-disk network map when the control plane is slow or unreachable, starting one to two orders of magnitude faster on warm starts, with caveats for huge tailnets and wear-sensitive storage.