Skip to content
Snippets Groups Projects
Commit 46bca619 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

conf: thread calculation helpers

parent 5e358f0b
No related branches found
No related tags found
No related merge requests found
......@@ -960,6 +960,21 @@ char* strcpath(char *path)
return path;
}
size_t conf_udp_threads(const conf_t *conf)
{
if (conf->workers < 1) {
return dt_optimal_size();
}
return conf->workers;
}
size_t conf_tcp_threads(const conf_t *conf)
{
size_t thrcount = conf_udp_threads(conf);
return MAX(thrcount * 2, CONFIG_XFERS);
}
void conf_init_zone(conf_zone_t *zone)
{
if (!zone) {
......
......@@ -407,6 +407,12 @@ static inline conf_t* conf() {
*/
char* strcpath(char *path);
/*! \brief Return the number of UDP threads according to the configuration. */
size_t conf_udp_threads(const conf_t *conf);
/*! \brief Return the number of TCP threads according to the configuration. */
size_t conf_tcp_threads(const conf_t *conf);
/* \brief Initialize zone config. */
void conf_init_zone(conf_zone_t *zone);
......
......@@ -489,10 +489,7 @@ static int reconfigure_threads(const struct conf_t *conf, server_t *server)
{
/* Estimate number of threads/manager. */
int ret = KNOT_EOK;
int tu_size = conf->workers;
if (tu_size < 1) {
tu_size = dt_optimal_size();
}
int tu_size = conf_udp_threads(conf);
if ((unsigned)tu_size != server->tu_size) {
/* Free old handlers */
if (server->tu_size > 0) {
......@@ -502,7 +499,7 @@ static int reconfigure_threads(const struct conf_t *conf, server_t *server)
}
/* Initialize I/O handlers. */
ret = server_init_handler(server, IO_UDP, tu_size,
ret = server_init_handler(server, IO_UDP, conf_udp_threads(conf),
&udp_master, &udp_master_destruct);
if (ret != KNOT_EOK) {
log_server_error("Failed to create UDP threads: %s\n",
......@@ -512,7 +509,7 @@ static int reconfigure_threads(const struct conf_t *conf, server_t *server)
/* Create at least CONFIG_XFERS threads for TCP for faster
* processing of massive bootstrap queries. */
ret = server_init_handler(server, IO_TCP, MAX(tu_size * 2, CONFIG_XFERS),
ret = server_init_handler(server, IO_TCP, conf_tcp_threads(conf),
&tcp_master, &tcp_master_destruct);
if (ret != KNOT_EOK) {
log_server_error("Failed to create TCP threads: %s\n",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment