ClickHouse Thread Performance Analysis with eBPF


eBPF (extended Berkeley Packet Filter) is a powerful tool for tracing and profiling various aspects of a running Linux system, including applications like ClickHouse. Leveraging eBPF for monitoring ClickHouse’s thread performance provides deep insights into the system’s behavior, aiding in performance optimization. In this article, we’ll explore how to use eBPF to analyze ClickHouse thread performance effectively.

Installing Required Tools

  1. Install BCC (BPF Compiler Collection): BCC is a set of tools that provide a user-friendly interface to work with eBPF. Install it on your system.
  • eBPF for ClickHouse Thread Analysis
  1. Identify ClickHouse Process: Use tools like pidof or pgrep to identify the process ID of the ClickHouse instance you want to monitor.
  2. Inspect Thread Activity with biolatency: The biolatency tool from BCC can be used to analyze the latency distribution of I/O operations. Run it with the -p flag followed by the ClickHouse process ID.
sudo biolatency -p <ClickHouse_PID>

3. Thread-Level Analysis with toplev: The toplev tool allows you to profile CPU performance counters at the thread level. Install it using BCC and run it with the -p flag followed by the ClickHouse process ID.

sudo toplev -p <ClickHouse_PID>

4. Analyze Context Switches with offcputime: The offcputime tool tracks how much time each thread spends off the CPU, indicating potential context switch issues. Run it with the -p flag followed by the ClickHouse process ID.

sudo offcputime -p <ClickHouse_PID>

Interpreting Results

  • Latency Distribution: The biolatency tool’s output shows the latency distribution of I/O operations, helping identify potential performance bottlenecks related to disk I/O.
  • CPU Profiling: toplev provides insights into CPU usage at the thread level. Analyze the output to identify threads consuming excessive CPU resources and optimize their usage.
  • Context Switches: The offcputime tool reveals the time threads spend off the CPU due to context switches. High context switch counts could indicate inefficiencies in thread scheduling.


Using eBPF tools like biolatency, toplev, and offcputime provides a comprehensive way to analyze ClickHouse’s thread performance. These tools help pinpoint performance issues, enabling administrators and developers to optimize ClickHouse’s resource usage, improve efficiency, and enhance overall system performance.

To know more about using eBPF with ClickHouse, do visit the following articles:

About Shiv Iyer 216 Articles
Open Source Database Systems Engineer with a deep understanding of Optimizer Internals, Performance Engineering, Scalability and Data SRE. Shiv currently is the Founder, Investor, Board Member and CEO of multiple Database Systems Infrastructure Operations companies in the Transaction Processing Computing and ColumnStores ecosystem. He is also a frequent speaker in open source software conferences globally.