summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2024-01-26 13:00:24 +0200
committerGitHub <noreply@github.com>2024-01-26 13:00:24 +0200
commit60c5371d686644ecc409ae68499e4fff7a3547e7 (patch)
tree8fc113e098048cfa6b5f03f111771ccee4721d55
parentc0a944a6ab21fd8c2624fa65c88d36d0726d5333 (diff)
Improve service thread shutdown (#16841)
Shutdown service thread first Service thread sleep 1 sec at a time
-rw-r--r--daemon/main.c12
-rw-r--r--daemon/service.c8
2 files changed, 13 insertions, 7 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 098531f943..b53bace5a3 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -357,6 +357,12 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
| SERVICE_ACLKSYNC
);
+ delta_shutdown_time("stop maintenance thread");
+
+ timeout = !service_wait_exit(
+ SERVICE_MAINTENANCE
+ , 3 * USEC_PER_SEC);
+
delta_shutdown_time("stop replication, exporters, health and web servers threads");
timeout = !service_wait_exit(
@@ -394,12 +400,6 @@ void netdata_cleanup_and_exit(int ret, const char *action, const char *action_re
SERVICE_CONTEXT
, 3 * USEC_PER_SEC);
- delta_shutdown_time("stop maintenance thread");
-
- timeout = !service_wait_exit(
- SERVICE_MAINTENANCE
- , 3 * USEC_PER_SEC);
-
delta_shutdown_time("clear web client cache");
web_client_cache_destroy();
diff --git a/daemon/service.c b/daemon/service.c
index 105d4e3095..895c858707 100644
--- a/daemon/service.c
+++ b/daemon/service.c
@@ -307,12 +307,18 @@ void *service_main(void *ptr)
heartbeat_t hb;
heartbeat_init(&hb);
usec_t step = USEC_PER_SEC * SERVICE_HEARTBEAT;
+ usec_t real_step = USEC_PER_SEC;
netdata_log_debug(D_SYSTEM, "Service thread starts");
while (service_running(SERVICE_MAINTENANCE)) {
worker_is_idle();
- heartbeat_next(&hb, step);
+ heartbeat_next(&hb, USEC_PER_SEC);
+ if (real_step < step) {
+ real_step += USEC_PER_SEC;
+ continue;
+ }
+ real_step = USEC_PER_SEC;
svc_rrd_cleanup_obsolete_charts_from_all_hosts();
svc_rrdhost_cleanup_orphan_hosts(localhost);