Skip to content

Commit

Permalink
Improve service thread shutdown (netdata#16841)
Browse files Browse the repository at this point in the history
Shutdown service thread first
Service thread sleep 1 sec at a time
  • Loading branch information
stelfrag authored Jan 26, 2024
1 parent c0a944a commit 60c5371
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 6 additions & 6 deletions daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion daemon/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 60c5371

Please sign in to comment.