@cryptotaxi247 / netdata-1 / commits / 4afc63c85

Remove health_thread_stop (#13948)

* remove health_thread_stop * soft sleeps

Emmanuel Vasilakis committed Nov 10, 2022 at 18:37 UTC 4afc63c85d319c8965ab446af6d167f5e9eb3199
3 files changed +17 -24
database/rrdhost.c
-1
@@ -1112,7 +1112,6 @@ void rrdhost_free(RRDHOST *host, bool force) {
1112
1113 freez(host->exporting_flags);
1114
1115 - health_thread_stop(host);
1115 health_alarm_log_free(host);
1116
1117 #ifdef ENABLE_DBENGINE
health/health.c
+11 -22
@@ -601,20 +601,11 @@ static void health_thread_cleanup(void *ptr) {
601 struct health_state *h = ptr;
602 h->host->health_spawn = 0;
603
604 - netdata_thread_detach(netdata_thread_self());
604 + netdata_thread_cancel(netdata_thread_self());
605 log_health("[%s]: Health thread ended.", rrdhost_hostname(h->host));
606 debug(D_HEALTH, "HEALTH %s: Health thread ended.", rrdhost_hostname(h->host));
607 }
608
609 -void health_thread_stop(RRDHOST *host) {
610 - if(host->health_spawn) {
611 - log_health("[%s]: Signaling health thread to stop...", rrdhost_hostname(host));
612 -
613 - // signal it to cancel
614 - netdata_thread_cancel(host->health_thread);
615 - }
616 -}
617 -
609 static void initialize_health(RRDHOST *host, int is_localhost) {
610 if(!host->health_enabled || rrdhost_flag_check(host, RRDHOST_FLAG_INITIALIZED_HEALTH)) return;
611 rrdhost_flag_set(host, RRDHOST_FLAG_INITIALIZED_HEALTH);
@@ -701,13 +692,15 @@ static void initialize_health(RRDHOST *host, int is_localhost) {
692 health_silencers_init();
693 }
694
704 -static void health_sleep(time_t next_run, unsigned int loop) {
695 +static void health_sleep(time_t next_run, unsigned int loop, RRDHOST *host) {
696 time_t now = now_realtime_sec();
697 if(now < next_run) {
698 worker_is_idle();
699 debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration in %d secs", loop, (int) (next_run - now));
709 - sleep_usec(USEC_PER_SEC * (usec_t) (next_run - now));
710 - now = now_realtime_sec();
700 + while (now < next_run && host->health_enabled && !netdata_exit) {
701 + sleep_usec(USEC_PER_SEC);
702 + now = now_realtime_sec();
703 + }
704 }
705 else {
706 debug(D_HEALTH, "Health monitoring iteration no %u done. Next iteration now", loop);
@@ -886,7 +879,7 @@ void *health_main(void *ptr) {
879 #ifdef ENABLE_ACLK
880 unsigned int marked_aclk_reload_loop = 0;
881 #endif
889 - while(!netdata_exit) {
882 + while(!netdata_exit && host->health_enabled) {
883 loop++;
884 debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
885
@@ -928,13 +921,13 @@ void *health_main(void *ptr) {
921
922 host->health_delay_up_to = now + hibernation_delay;
923 next_run = now + hibernation_delay;
931 - health_sleep(next_run, loop);
924 + health_sleep(next_run, loop, host);
925 }
926
927 if (unlikely(host->health_delay_up_to)) {
928 if (unlikely(now < host->health_delay_up_to)) {
929 next_run = host->health_delay_up_to;
937 - health_sleep(next_run, loop);
930 + health_sleep(next_run, loop, host);
931 continue;
932 }
933
@@ -942,15 +935,11 @@ void *health_main(void *ptr) {
935 host->health_delay_up_to = 0;
936 }
937
945 - if (unlikely(!host->health_enabled)) {
946 - health_thread_stop(host);
947 - }
948 -
938 // wait until cleanup of obsolete charts on children is complete
939 if (host != localhost) {
940 if (unlikely(host->trigger_chart_obsoletion_check == 1)) {
941 log_health("[%s]: Waiting for chart obsoletion check.", rrdhost_hostname(host));
953 - health_sleep(next_run, loop);
942 + health_sleep(next_run, loop, host);
943 continue;
944 }
945 }
@@ -1413,7 +1402,7 @@ void *health_main(void *ptr) {
1402 if(unlikely(netdata_exit))
1403 break;
1404
1416 - health_sleep(next_run, loop);
1405 + health_sleep(next_run, loop, host);
1406
1407 } // forever
1408
ml/Host.cc
+6 -1
@@ -141,7 +141,12 @@ void TrainableHost::train() {
141
142 worker_is_idle();
143 SleepFor = std::min(AllottedDuration - RealDuration, MaxSleepFor);
144 - std::this_thread::sleep_for(SleepFor);
144 + TimePoint Now = SteadyClock::now();
145 + auto Until = Now + SleepFor;
146 + while (Now < Until && !netdata_exit) {
147 + std::this_thread::sleep_for(std::chrono::milliseconds(1000));
148 + Now = SteadyClock::now();
149 + }
150 worker_is_busy(0);
151 }
152 }