]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
server: reduce the worker_pool_status() overhead in the case of many zones
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 19 Jul 2021 11:23:49 +0000 (13:23 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Mon, 19 Jul 2021 11:24:15 +0000 (13:24 +0200)
src/knot/server/server.c

index 61a5157f7da83a18236ea0d30a2e92357d2d5833..d3d031fa455fed65ffa03a048e7d474c575c2e10 100644 (file)
@@ -745,10 +745,18 @@ static void server_free_handler(iohandler_t *h)
 
 static void worker_wait_cb(worker_pool_t *pool)
 {
-       int running, queued;
        systemd_zone_load_timeout_notify();
-       worker_pool_status(pool, true, &running, &queued);
-       systemd_tasks_status_notify(running + queued);
+
+       static uint64_t last_ns = 0;
+       struct timespec now = time_now();
+       uint64_t now_ns = 1000000000 * now.tv_sec + now.tv_nsec;
+       /* Too frequent worker_pool_status() call with many zones is expensive. */
+       if (now_ns - last_ns > 1000000000) {
+               int running, queued;
+               worker_pool_status(pool, true, &running, &queued);
+               systemd_tasks_status_notify(running + queued);
+               last_ns = now_ns;
+       }
 }
 
 int server_start(server_t *server, bool async)