Taming query profiler

This commit is contained in:
Alexey Milovidov 2023-10-29 11:15:11 +01:00
parent d6a09a6efa
commit 3142921bb4
2 changed files with 13 additions and 0 deletions

View File

@ -316,6 +316,7 @@ The server successfully detected this situation and will download merged part fr
\
M(CannotWriteToWriteBufferDiscard, "Number of stack traces dropped by query profiler or signal handler because pipe is full or cannot write to pipe.") \
M(QueryProfilerSignalOverruns, "Number of times we drop processing of a query profiler signal due to overrun plus the number of signals that OS has not delivered due to overrun.") \
M(QueryProfilerConcurrencyOverruns, "Number of times we drop processing of a query profiler signal due to too many concurrent query profilers in other threads, which may indicate overload.") \
M(QueryProfilerRuns, "Number of times QueryProfiler had been run.") \
\
M(CreatedLogEntryForMerge, "Successfully created log entry to merge parts in ReplicatedMergeTree.") \

View File

@ -22,6 +22,7 @@ namespace CurrentMetrics
namespace ProfileEvents
{
extern const Event QueryProfilerSignalOverruns;
extern const Event QueryProfilerConcurrencyOverruns;
extern const Event QueryProfilerRuns;
}
@ -40,8 +41,19 @@ namespace
/// to ignore delivered signals after timer_delete().
thread_local bool signal_handler_disarmed = true;
/// Don't permit too many threads be busy inside profiler,
/// which could slow down the system in some environments.
std::atomic<Int64> concurrent_invocations = 0;
void writeTraceInfo(TraceType trace_type, int /* sig */, siginfo_t * info, void * context)
{
SCOPE_EXIT({ concurrent_invocations.fetch_sub(1, std::memory_order_relaxed); });
if (concurrent_invocations.fetch_add(1, std::memory_order_relaxed) > 100)
{
ProfileEvents::incrementNoTrace(ProfileEvents::QueryProfilerConcurrencyOverruns);
return;
}
auto saved_errno = errno; /// We must restore previous value of errno in signal handler.
#if defined(OS_LINUX)