libunwind is reentrant and signal safe, and works faster then then
gcc_eh (plus it has some custom patches for problems that have been
found during it's usage in ClickHouse).
gcc_eh may be missing in the system (if gcc was not installed), and
even if it exists clickhouse uses -nodefaultlibs, so some care should be
made to make it work.
Also this library is tiny and there shouln't be any problem to require
it always (there is already tendency to require some contrib libraries,
i.e. poco).
Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
* Maintain per-thread timer_id rather than create/delete frequently
The QueryProfiler will frequently create/delete timer_id globally, which
will result in heavy kernel lock contention.
The idea is to maintain thread-local timer_id. Before create the
timer_id, it should check whether there is a timer_id already. And we
could stop the timer by timer_settime() rather than delete the timer_id
with timer_delete().
Apply the patch and run clickbench on latest 65d671b7c7 ClickHouse with
SPR 112 x 2 vCPUs. Query 4, 0, 5, 3, 15, 32 have 17.5%, 14.4%, 8.3%, 7.9%,
7.1%, 5.8% performance gain. The overall geomean has got 2.5%
performance gain.
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
* Pack the timer and delete the timer_id when thread terminates
Pack the timer and related methods into the class. Delete the timer_id
when the thread terminates.
According to the issue (ClickHouse#49965),
all of the SSB queries benefit from this optimization, some have even got
improved by ~30% and the overall QPS could be significantly improved by ~18%.
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
* Update src/Common/QueryProfiler.cpp
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
* Update src/Common/QueryProfiler.cpp
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
* Fix the review issue of QueryProfiler Timer from PR
https://github.com/ClickHouse/ClickHouse/pull/48778.
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
* Update src/Common/QueryProfiler.cpp
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
* Add two separate CurrentMetrics for created and active timers
in QueryProfiler.
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
---------
Signed-off-by: Jiebin Sun <jiebin.sun@intel.com>
Co-authored-by: Azat Khuzhin <a3at.mail@gmail.com>
Co-authored-by: Nikita Taranov <nikita.taranov@clickhouse.com>
This makes the target location consistent with other auto-generated
files like config_formats.h, config_core.h, and config_functions.h and
simplifies the build of clickhouse_common.
Before there was two incorrect checks:
- timer_id != nullptr, but first timer is 0x0 and the comparison does
not work
- previous_handler should also be reseted regardless it was nullptr or
not, plus it also incorrectly uses 'sigaction * previous_handler'
before.
Which leads to permanent query profiler enabled for particular thread,
this is especially visible if you have query profiler disabled and you
are running some query with profiler enabled, i.e.:
select 1 settings query_profiler_real_time_period_ns=1
After, QueryPipelineEx will eat lots of CPU due because of profiler.