@cryptotaxi247 / netdata-1 / commits / 97d6793f9

Improve global statistics thread shutdown (#18018)

Stelios Fragkakis committed Jun 27, 2024 at 19:46 UTC 97d6793f90d17dfc0d4eb9c9bce0c0e63530623e
1 file changed +14 -2
src/daemon/global_statistics.c
+14 -2
@@ -4229,6 +4229,7 @@ void *global_statistics_main(void *ptr)
4229 usec_t step = update_every * USEC_PER_SEC;
4230 heartbeat_t hb;
4231 heartbeat_init(&hb);
4232 + usec_t real_step = USEC_PER_SEC;
4233
4234 // keep the randomness at zero
4235 // to make sure we are not close to any other thread
@@ -4236,7 +4237,12 @@ void *global_statistics_main(void *ptr)
4237
4238 while (service_running(SERVICE_COLLECTORS)) {
4239 worker_is_idle();
4239 - heartbeat_next(&hb, step);
4240 + heartbeat_next(&hb, USEC_PER_SEC);
4241 + if (real_step < step) {
4242 + real_step += USEC_PER_SEC;
4243 + continue;
4244 + }
4245 + real_step = USEC_PER_SEC;
4246
4247 worker_is_busy(WORKER_JOB_GLOBAL);
4248 global_statistics_charts();
@@ -4279,10 +4285,16 @@ void *global_statistics_extended_main(void *ptr)
4285 usec_t step = update_every * USEC_PER_SEC;
4286 heartbeat_t hb;
4287 heartbeat_init(&hb);
4288 + usec_t real_step = USEC_PER_SEC;
4289
4290 while (service_running(SERVICE_COLLECTORS)) {
4291 worker_is_idle();
4285 - heartbeat_next(&hb, step);
4292 + heartbeat_next(&hb, USEC_PER_SEC);
4293 + if (real_step < step) {
4294 + real_step += USEC_PER_SEC;
4295 + continue;
4296 + }
4297 + real_step = USEC_PER_SEC;
4298
4299 worker_is_busy(WORKER_JOB_HEARTBEAT);
4300 update_heartbeat_charts();