Merge pull request #43307 from ClickHouse/cpu-progress-protocol-fix

fix CPU load indication on client
This commit is contained in:
Sergei Trifonov 2022-11-22 14:09:55 +01:00 committed by GitHub
commit 3177ed050f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -27,6 +27,14 @@ public:
/// NOTE: Adding events into distant past (further than `period`) must be avoided.
void add(double now, double count)
{
// Remove data for initial heating stage that can present at the beginning of a query.
// Otherwise it leads to wrong gradual increase of average value, turning algorithm into not very reactive.
if (count != 0.0 && ++data_points < 5)
{
start = events.time;
events = ExponentiallySmoothedAverage();
}
if (now - period <= start) // precise counting mode
events = ExponentiallySmoothedAverage(events.value + count, now);
else // exponential smoothing mode
@ -51,6 +59,7 @@ public:
{
start = now;
events = ExponentiallySmoothedAverage();
data_points = 0;
}
private:
@ -58,6 +67,7 @@ private:
const double half_decay_time;
double start; // Instant in past without events before it; when measurement started or reset
ExponentiallySmoothedAverage events; // Estimated number of events in the last `period`
size_t data_points = 0;
};
}

View File

@ -90,7 +90,7 @@ private:
bool write_progress_on_update = false;
EventRateMeter cpu_usage_meter{static_cast<double>(clock_gettime_ns()), 3'000'000'000 /*ns*/}; // average cpu utilization last 3 second
EventRateMeter cpu_usage_meter{static_cast<double>(clock_gettime_ns()), 2'000'000'000 /*ns*/}; // average cpu utilization last 2 second
HostToThreadTimesMap thread_data;
/// In case of all of the above:
/// - clickhouse-local