Merge pull request #8837 from ClickHouse/query-profiler-workaround-google-cloud-runner

Added workaround for Google Cloud Run
This commit is contained in:
alexey-milovidov 2020-01-26 21:46:16 +03:00 committed by GitHub
commit 994192080d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -141,7 +141,15 @@ QueryProfilerBase<ProfilerImpl>::QueryProfilerBase(const Int32 thread_id, const
sev._sigev_un._tid = thread_id; sev._sigev_un._tid = thread_id;
#endif #endif
if (timer_create(clock_type, &sev, &timer_id)) if (timer_create(clock_type, &sev, &timer_id))
{
/// In Google Cloud Run, the function "timer_create" is implemented incorrectly as of 2020-01-25.
/// https://mybranch.dev/posts/clickhouse-on-cloud-run/
if (errno == 0)
throw Exception("Failed to create thread timer. The function 'timer_create' returned non-zero but didn't set errno. This is bug in your OS.",
ErrorCodes::CANNOT_CREATE_TIMER);
throwFromErrno("Failed to create thread timer", ErrorCodes::CANNOT_CREATE_TIMER); throwFromErrno("Failed to create thread timer", ErrorCodes::CANNOT_CREATE_TIMER);
}
/// Randomize offset as uniform random value from 0 to period - 1. /// Randomize offset as uniform random value from 0 to period - 1.
/// It will allow to sample short queries even if timer period is large. /// It will allow to sample short queries even if timer period is large.

View File

@ -160,15 +160,23 @@ void ThreadStatus::initQueryProfiler()
const auto & settings = query_context->getSettingsRef(); const auto & settings = query_context->getSettingsRef();
if (settings.query_profiler_real_time_period_ns > 0) try
query_profiler_real = std::make_unique<QueryProfilerReal>( {
/* thread_id */ os_thread_id, if (settings.query_profiler_real_time_period_ns > 0)
/* period */ static_cast<UInt32>(settings.query_profiler_real_time_period_ns)); query_profiler_real = std::make_unique<QueryProfilerReal>(
/* thread_id */ os_thread_id,
/* period */ static_cast<UInt32>(settings.query_profiler_real_time_period_ns));
if (settings.query_profiler_cpu_time_period_ns > 0) if (settings.query_profiler_cpu_time_period_ns > 0)
query_profiler_cpu = std::make_unique<QueryProfilerCpu>( query_profiler_cpu = std::make_unique<QueryProfilerCpu>(
/* thread_id */ os_thread_id, /* thread_id */ os_thread_id,
/* period */ static_cast<UInt32>(settings.query_profiler_cpu_time_period_ns)); /* period */ static_cast<UInt32>(settings.query_profiler_cpu_time_period_ns));
}
catch (...)
{
/// QueryProfiler is optional.
tryLogCurrentException("ThreadStatus", "Cannot initialize QueryProfiler");
}
} }
void ThreadStatus::finalizeQueryProfiler() void ThreadStatus::finalizeQueryProfiler()