summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2023-06-29 15:02:13 +0300
committerGitHub <noreply@github.com>2023-06-29 15:02:13 +0300
commitc62dcb2a9bd8ca6ec0c483bb3506c733d96648c6 (patch)
tree15f9e27879cfb951fa853fcb4f570066cb7f54a6 /daemon
parenta1503807bb57399eae83606146281036da25e610 (diff)
Optimizations part 2 (#15280)
* make all pluginsd functions inline, instead of function pointers * dynamic MRG partitions based on the number of CPUs * report the right size of the MRG * prevent invalid read on pluginsd exit * faster service_running() check; fix compiler warnings; shutdown replication after streaming to prevent crash on shutdown * sender is now using a spinlock * rrdcontext uses spinlock * replace select() with poll() * signed calculation of threads * disable read-ahead on jnfv2 files during scan
Diffstat (limited to 'daemon')
-rw-r--r--daemon/common.c3
-rw-r--r--daemon/main.c35
2 files changed, 20 insertions, 18 deletions
diff --git a/daemon/common.c b/daemon/common.c
index d189713051..9e1c9b9c63 100644
--- a/daemon/common.c
+++ b/daemon/common.c
@@ -58,6 +58,9 @@ long get_netdata_cpus(void) {
processors = cores_user_configured;
+ if(processors < 1)
+ processors = 1;
+
return processors;
}
diff --git a/daemon/main.c b/daemon/main.c
index 71a570d781..eb8e70d2a9 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -35,6 +35,7 @@ typedef struct service_thread {
SERVICE_THREAD_TYPE type;
SERVICE_TYPE services;
char name[NETDATA_THREAD_NAME_MAX + 1];
+ bool stop_immediately;
bool cancelled;
union {
@@ -48,11 +49,9 @@ typedef struct service_thread {
} SERVICE_THREAD;
struct service_globals {
- SERVICE_TYPE running;
SPINLOCK lock;
Pvoid_t pid_judy;
} service_globals = {
- .running = ~0,
.pid_judy = NULL,
};
@@ -110,20 +109,12 @@ bool service_running(SERVICE_TYPE service) {
if(unlikely(!sth))
sth = service_register(SERVICE_THREAD_TYPE_NETDATA, NULL, NULL, NULL, false);
- if(unlikely(netdata_exit))
- __atomic_store_n(&service_globals.running, 0, __ATOMIC_RELAXED);
-
- if(unlikely(service == 0))
- service = sth->services;
-
sth->services |= service;
- return ((__atomic_load_n(&service_globals.running, __ATOMIC_RELAXED) & service) == service);
+ return !(sth->stop_immediately || netdata_exit);
}
void service_signal_exit(SERVICE_TYPE service) {
- __atomic_and_fetch(&service_globals.running, ~(service), __ATOMIC_RELAXED);
-
spinlock_lock(&service_globals.lock);
Pvoid_t *PValue;
@@ -132,11 +123,14 @@ void service_signal_exit(SERVICE_TYPE service) {
while((PValue = JudyLFirstThenNext(service_globals.pid_judy, &tid, &first))) {
SERVICE_THREAD *sth = *PValue;
- if((sth->services & service) && sth->request_quit_callback) {
- spinlock_unlock(&service_globals.lock);
- sth->request_quit_callback(sth->data);
- spinlock_lock(&service_globals.lock);
- continue;
+ if((sth->services & service)) {
+ sth->stop_immediately = true;
+
+ if(sth->request_quit_callback) {
+ spinlock_unlock(&service_globals.lock);
+ sth->request_quit_callback(sth->data);
+ spinlock_lock(&service_globals.lock);
+ }
}
}
@@ -358,8 +352,7 @@ void netdata_cleanup_and_exit(int ret) {
delta_shutdown_time("stop replication, exporters, health and web servers threads");
timeout = !service_wait_exit(
- SERVICE_REPLICATION
- | SERVICE_EXPORTERS
+ SERVICE_EXPORTERS
| SERVICE_HEALTH
| SERVICE_WEB_SERVER
| SERVICE_HTTPD
@@ -372,6 +365,12 @@ void netdata_cleanup_and_exit(int ret) {
| SERVICE_STREAMING
, 3 * USEC_PER_SEC);
+ delta_shutdown_time("stop replication threads");
+
+ timeout = !service_wait_exit(
+ SERVICE_REPLICATION // replication has to be stopped after STREAMING, because it cleans up ARAL
+ , 3 * USEC_PER_SEC);
+
delta_shutdown_time("disable ML detection and training threads");
ml_stop_threads();