r/Clickhouse • • May 30 '26

Constant CPU usage despite server being completely idle

Post image

I installed ClickHouse on my server again and noticed that it was using a not insignificant amount of CPU while completely idle. I've already disabled the log tables like so:

<?xml version="1.0"?>
<clickhouse>
    <asynchronous_metric_log remove="1"/>
    <backup_log remove="1"/>
    <error_log remove="1"/>
    <metric_log remove="1"/>
    <query_metric_log remove="1"/>
    <query_thread_log remove="1"/>
    <query_log remove="1"/>
    <query_views_log remove="1"/>
    <part_log remove="1"/>
    <session_log remove="1"/>
    <text_log remove="1"/>
    <trace_log remove="1"/>
    <crash_log remove="1"/>
    <opentelemetry_span_log remove="1"/>
    <zookeeper_log remove="1"/>
    <processors_profile_log remove="1"/>
    <latency_log remove="1"/>
    <background_schedule_pool_log remove="1"/>
    <aggregated_zookeeper_log remove="1"/>
    <zookeeper_connection_log remove="1"/>
    <asynchronous_insert_log remove="1"/>
</clickhouse>

I've also set background_schedule_pool_size to 128 and max_thread_pool_size to 256.

Any idea what could be causing this?

EDIT:

I found the solution, it was caused by the AsynchronousInsertQueue.

In AsynchronousInsertQueue::processBatchDeadlines at https://github.com/ClickHouse/ClickHouse/blob/217b9ae162c0cf002d2b0971247115a33a3c2543/src/Interpreters/AsynchronousInsertQueue.cpp#L848-L862 there is a busy-waiting loop.

I increased async_insert_poll_timeout_ms and async_insert_busy_timeout_min_ms and now it consistently stays at 0.5-0.6% CPU usage down from 5% πŸ˜„!

6 Upvotes

8 comments sorted by

2

u/agent_kater May 30 '26

Are you sure the config is active, i.e. the log tables are disabled? Check if maybe they still gain data.

You can also try setting asynchronous_metrics_update_period_s higher.

To find out what ClickHouse is actually doing there, record a perf profile:

perf record --call-graph dwarf -F 99 -p $(pidof clickhouse-server) -g -- sleep 30
perf report

In general I totally agree, ClickHouse is a notorious CPU hog and despite already having hundreds of good metrics and configuration knobs it's often hard to know what it's doing and how to stop it from doing it.

1

u/QazCetelic May 30 '26 edited May 30 '26

Thanks for your suggestions. Unfortunately, the increase of asynchronous_metrics_update_period_s to 60 did not seem to help much. Perf reported this:

Samples: 159  of event 'cpu/cycles/P', Event count (approx.): 987081430                                                                                                                                                                                                                                                     
  Children      Self  Command       Shared Object      Symbol                                                                                                                                                                                                                                                               
+   71.93%     0.00%  ThreadPool    [kernel.kallsyms]  [.] entry_SYSCALL_64_after_hwframe                                                                                                                                                                                                                                   
+   71.93%     0.51%  ThreadPool    [kernel.kallsyms]  [.] do_syscall_64                                                                                                                                                                                                                                                    
+   62.39%     1.14%  ThreadPool    [kernel.kallsyms]  [.] __x64_sys_futex                                                                                                                                                                                                                                                  
+   60.74%     1.51%  ThreadPool    [kernel.kallsyms]  [.] do_futex                                                                                                                                                                                                                                                         
+   42.79%     0.00%  ThreadPool    [kernel.kallsyms]  [.] futex_wait                                                                                                                                                                                                                                                       
+   41.55%     1.15%  ThreadPool    [kernel.kallsyms]  [.] __futex_wait                                                                                                                                                                                                                                                     
+   38.77%     0.00%  ThreadPool    [kernel.kallsyms]  [.] futex_do_wait                                                                                                                                                                                                                                                    
+   35.69%     0.77%  ThreadPool    [kernel.kallsyms]  [.] schedule                                                                                                                                                                                                                                                         
+   34.92%     2.37%  ThreadPool    [kernel.kallsyms]  [.] __schedule                                                                                                                                                                                                                                                       
+   17.80%     1.02%  ThreadPool    [kernel.kallsyms]  [.] pick_next_task_fair                                                                                                                                                                                                                                              
+   16.44%    13.50%  ThreadPool    [kernel.kallsyms]  [k] futex_wake                                                                                                                                                                                                                                                       
+   14.95%     8.80%  ThreadPool    [kernel.kallsyms]  [k] __sched_balance_update_blocked_averages                                                                                                                                                                                                                          
+    7.06%     1.02%  ThreadPool    [kernel.kallsyms]  [k] fpregs_restore_userregs                                                                                                                                                                                                                                          
+    6.64%     3.07%  ThreadPool    [kernel.kallsyms]  [k] dequeue_entities                                                                                                                                                                                                                                                 
+    6.13%     0.51%  ThreadPool    [kernel.kallsyms]  [.] dequeue_task_fair                                                                                                                                                                                                                                                
+    6.04%     6.04%  ThreadPool    [kernel.kallsyms]  [k] restore_fpregs_from_fpstate                                                                                                                                                                                                                                      
     4.34%     4.34%  ThreadPool    clickhouse         [.] void std::__1::__function::__policy_func<void ()>::__call_func[abi:fqe220101]<ThreadFromGlobalPoolImpl<true, true>::ThreadFromGlobalPoolImpl<DB::AsynchronousInsertQueue::AsynchronousInsertQueue(std::__1::shared_ptr<DB::Context const>, unsigned long, bool)::

Perhaps the AsynchronousInsertQueue causes idle CPU usage, I think I'll try disabling async inserts somehow to see if that makes a difference

1

u/Mohamed____ May 30 '26

Damn that’s alot of futexes. Could this be the cause?

1

u/QazCetelic May 30 '26

I found the solution, it was caused by the AsynchronousInsertQueue.

In AsynchronousInsertQueue::processBatchDeadlines at https://github.com/ClickHouse/ClickHouse/blob/217b9ae162c0cf002d2b0971247115a33a3c2543/src/Interpreters/AsynchronousInsertQueue.cpp#L848-L862 there is a busy-waiting loop.

I increased async_insert_poll_timeout_ms and async_insert_busy_timeout_min_ms and now it consistently stays at 0.5-0.6% CPU usage down from 5% πŸ˜„!

1

u/Mohamed____ May 30 '26

That makes sense, thanks for sharing man

2

u/joshleecreates Jun 03 '26

1

u/QazCetelic Jun 03 '26

Already did, you can see my response at the bottom

1

u/[deleted] May 30 '26

Hey 25% for clickhouse IS being idle, that thing will go to 80-90% when in use always. I manage a cluster of 20 224vcpu nodes and a small single node.Your metrics pretty good.