Commit 0782d247 authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

ctl: add to server status info how bg workers are busy

parent 89b84da2
......@@ -1405,9 +1405,12 @@ static int server_status(ctl_args_t *args)
if (strcasecmp(type, "version") == 0) {
ret = snprintf(buff, sizeof(buff), "Version: %s", PACKAGE_VERSION);
} else if (strcasecmp(type, "workers") == 0) {
int running_bkg_wrk, wrk_queue;
worker_pool_status(args->server->workers, &running_bkg_wrk, &wrk_queue);
ret = snprintf(buff, sizeof(buff), "UDP workers: %zu, TCP workers %zu, "
"background workers: %zu", conf_udp_threads(conf()),
conf_tcp_threads(conf()), conf_bg_threads(conf()));
"background workers: %zu (running: %d, pending: %d)",
conf_udp_threads(conf()), conf_tcp_threads(conf()),
conf_bg_threads(conf()), running_bkg_wrk, wrk_queue);
} else if (strcasecmp(type, "configure") == 0) {
ret = snprintf(buff, sizeof(buff), "%s", CONFIGURE_SUMMARY);
} else {
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -227,3 +227,16 @@ void worker_pool_clear(worker_pool_t *pool)
worker_queue_init(&pool->tasks);
pthread_mutex_unlock(&pool->lock);
}
void worker_pool_status(worker_pool_t *pool, int *running, int *queued)
{
if (!pool) {
*running = *queued = 0;
return;
}
pthread_mutex_lock(&pool->lock);
*running = pool->running;
*queued = worker_queue_length(&pool->tasks);
pthread_mutex_unlock(&pool->lock);
}
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -75,3 +75,8 @@ void worker_pool_assign(worker_pool_t *pool, struct task *task);
* \brief Clear all tasks enqueued in pool processing queue.
*/
void worker_pool_clear(worker_pool_t *pool);
/*!
* \brief Obtain info regarding how the pool is busy.
*/
void worker_pool_status(worker_pool_t *pool, int *running, int *queued);
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -60,3 +60,8 @@ task_t *worker_queue_dequeue(worker_queue_t *queue)
return task;
}
size_t worker_queue_length(worker_queue_t *queue)
{
return queue ? list_size(&queue->list) : 0;
}
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -58,3 +58,8 @@ void worker_queue_enqueue(worker_queue_t *queue, task_t *task);
* \return Task or NULL if the queue is empty.
*/
task_t *worker_queue_dequeue(worker_queue_t *queue);
/*!
* \brief Return number of tasks in worker queue.
*/
size_t worker_queue_length(worker_queue_t *queue);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment