From 1599b8036090edbf85d8c08f0da4c54dfd7f9343 Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Thu, 24 May 2018 18:59:04 +0200 Subject: [PATCH] MINOR: tasks: Make the number of tasks to run at once configurable. Instead of hardcoding 200, make the number of tasks to be run configurable using tune.runqueue-depth. 200 is still the default. --- doc/configuration.txt | 6 ++++++ include/common/defaults.h | 5 +++++ include/types/global.h | 1 + src/cfgparse.c | 16 ++++++++++++++++ src/haproxy.c | 3 +++ src/task.c | 4 ++-- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 67b4b3ab87..e27d66627f 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -648,6 +648,7 @@ The following keywords are supported in the "global" section : - tune.rcvbuf.client - tune.rcvbuf.server - tune.recv_enough + - tune.runqueue-depth - tune.sndbuf.client - tune.sndbuf.server - tune.ssl.cachesize @@ -1627,6 +1628,11 @@ tune.recv_enough may be changed by this setting to better deal with workloads involving lots of short messages such as telnet or SSH sessions. +tune.runqueue-depth + Sets the maxinum amount of task that can be processed at once when running + tasks. The default value is 200. Increasing it may incur latency when + dealing with I/Os, making it too small can incur extra overhead. + tune.sndbuf.client tune.sndbuf.server Forces the kernel socket send buffer size on the client or the server side to diff --git a/include/common/defaults.h b/include/common/defaults.h index f53c611e27..f5c74dbfe5 100644 --- a/include/common/defaults.h +++ b/include/common/defaults.h @@ -135,6 +135,11 @@ #define MAX_POLL_EVENTS 200 #endif +// the max number of tasks to run at once +#ifndef RUNQUEUE_DEPTH +#define RUNQUEUE_DEPTH 200 +#endif + // cookie delimitor in "prefix" mode. This character is inserted between the // persistence cookie and the original value. The '~' is allowed by RFC6265, // and should not be too common in server names. diff --git a/include/types/global.h b/include/types/global.h index bd7761cd6f..d603c42611 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -136,6 +136,7 @@ struct global { int maxpollevents; /* max number of poll events at once */ int maxaccept; /* max number of consecutive accept() */ int options; /* various tuning options */ + int runqueue_depth;/* max number of tasks to run at once */ int recv_enough; /* how many input bytes at once are "enough" */ int bufsize; /* buffer size in bytes, defaults to BUFSIZE */ int maxrewrite; /* buffer max rewrite size in bytes, defaults to MAXREWRITE */ diff --git a/src/cfgparse.c b/src/cfgparse.c index 024502c4b8..023973f40e 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -788,6 +788,22 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm) goto out; global.mode |= MODE_QUIET; } + else if (!strcmp(args[0], "tune.runqueue-depth")) { + if (alertif_too_many_args(1, file, linenum, args, &err_code)) + goto out; + if (global.tune.runqueue_depth != 0) { + ha_alert("parsing [%s:%d] : '%s' already specified. Continuing.\n", file, linenum, args[0]); + err_code |= ERR_ALERT; + goto out; + } + if (*(args[1]) == 0) { + ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; + } + global.tune.runqueue_depth = atol(args[1]); + + } else if (!strcmp(args[0], "tune.maxpollevents")) { if (alertif_too_many_args(1, file, linenum, args, &err_code)) goto out; diff --git a/src/haproxy.c b/src/haproxy.c index 6fd2e83832..4e61e4056f 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1853,6 +1853,9 @@ static void init(int argc, char **argv) if (global.tune.maxpollevents <= 0) global.tune.maxpollevents = MAX_POLL_EVENTS; + if (global.tune.runqueue_depth <= 0) + global.tune.runqueue_depth = RUNQUEUE_DEPTH; + if (global.tune.recv_enough == 0) global.tune.recv_enough = MIN_RECV_AT_ONCE_ENOUGH; diff --git a/src/task.c b/src/task.c index 3032010ba0..3275188969 100644 --- a/src/task.c +++ b/src/task.c @@ -243,7 +243,7 @@ void process_runnable_tasks() tasks_run_queue_cur = tasks_run_queue; /* keep a copy for reporting */ nb_tasks_cur = nb_tasks; - max_processed = 200; + max_processed = global.tune.runqueue_depth; if (likely(global.nbthread > 1)) { HA_SPIN_LOCK(TASK_RQ_LOCK, &rq_lock); @@ -297,7 +297,7 @@ void process_runnable_tasks() * get too much in the task list, but put a bit more than * the max that will be run, to give a bit more fairness */ - while (max_processed + 20 > task_list_size[tid]) { + while (max_processed + (max_processed / 10) > task_list_size[tid]) { /* Note: this loop is one of the fastest code path in * the whole program. It should not be re-arranged * without a good reason. -- 2.47.3