---
title: "Chasing that 32 ms tail latency in ClickHouse"
description: "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."
url: "https://swe.quest/articles/chasing-that-32-ms-tail-latency-in-clickhouse-e6423f2da8a7c8b8"
canonical: "https://clickhouse.com/blog/chasing-32ms-tail-latency-clickhouse"
source: "ClickHouse"
published: "2026-10-13"
difficulty: "hard"
kind: "Case study"
reading_minutes: 11
tags: ["networking","performance","linux","databases","debugging"]
---

# Chasing that 32 ms tail latency in ClickHouse

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-10-13, 11 min read, Case study. Original: [https://clickhouse.com/blog/chasing-32ms-tail-latency-clickhouse](https://clickhouse.com/blog/chasing-32ms-tail-latency-clickhouse)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Networking](https://swe.quest/tags/networking.md) (Infrastructure)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Databases](https://swe.quest/tags/databases.md) (Data & databases)
- [Debugging](https://swe.quest/tags/debugging.md) (Engineering practices)

## Prerequisites

- TCP congestion control basics ([easy posts on Networking](https://swe.quest/tags/networking.md?difficulty=easy))
- Nagle's algorithm and TCP\_NODELAY ([easy posts on Algorithms](https://swe.quest/tags/algorithms.md?difficulty=easy))
- Linux network namespaces and tc ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))

## Keywords

ClickHouse, ClickHouse Native protocol, TCP\_NODELAY, initcwnd, TCP\_CORK, netem, tshark

## Related posts

- [From v0.7 to v0.8: How group commit changed Turso's tail latency](https://swe.quest/articles/from-v0-7-to-v0-8-how-group-commit-changed-turso-s-tail-latency-395b8a8a61113276.md): Turso · 2026-09-29 · Medium · 13 min read · Storage engines, SQLite, Performance engineering, Concurrency, Databases
  Turso 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.
- [Kafka, Latency, and You: Minimizing Latency with Kafka & ClickHouse](https://swe.quest/articles/kafka-latency-and-you-minimizing-latency-with-kafka-clickhouse-89c71c2fc7e4578d.md): ClickHouse · 2023-09-13 · Medium · 8 min read · Queues & messaging, Analytics & OLAP, Performance engineering, Data pipelines
  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.
- [Designing the new async-native ClickHouse Python client](https://swe.quest/articles/designing-the-new-async-native-clickhouse-python-client-686db4668ab2ae45.md): ClickHouse · 2026-03-16 · Medium · 12 min read · Python, Concurrency, Performance engineering, Databases
  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.
- [Asynchronous Data Inserts in ClickHouse](https://swe.quest/articles/asynchronous-data-inserts-in-clickhouse-7e5b81fdcf244f48.md): ClickHouse · 2023-08-01 · Medium · 19 min read · Analytics & OLAP, Storage engines, Performance engineering, Observability
  ClickHouse asynchronous inserts move batching from the client to the server.
- [We’re making Tailscale faster](https://swe.quest/articles/we-re-making-tailscale-faster-039902ebbb2b850c.md): Tailscale · 2026-09-22 · Medium · 8 min read · Networking, Performance engineering, Linux
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
