Optimize the lock contentions for ThreadGroupStatus::mutex

The release of ThreadGroupStatus::finished_threads_counters_memory
via the getProfileEventsCountersAndMemoryForThreads method brings
lots of lock contentions for ThreadGroupStatus::mutex and lowers
the overall performance. This commit optimizes this performance
issue by replacing the method call with an equivalent but more
lightweight code block.
This commit is contained in:
Zhiguo Zhou 2022-09-22 15:48:22 +08:00
parent 445446c700
commit 223c1230b6

View File

@ -350,7 +350,10 @@ void ThreadStatus::detachQuery(bool exit_if_already_detached, bool thread_exits)
/// Avoid leaking of ThreadGroupStatus::finished_threads_counters_memory
/// (this is in case someone uses system thread but did not call getProfileEventsCountersAndMemoryForThreads())
thread_group->getProfileEventsCountersAndMemoryForThreads();
{
std::lock_guard guard(thread_group->mutex);
auto stats = std::move(thread_group->finished_threads_counters_memory);
}
thread_group.reset();