diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index d08c5aaaa..fbecf2252 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -69,19 +69,20 @@ The global settings, in a section named `[MaxScale]`, allow various parameters t #### `threads` This parameter controls the number of worker threads that are handling the -events coming from the kernel. MaxScale will auto-detect the number of -processors of the system unless number of threads is manually configured. -It is recommended that you let MaxScale detect how many cores the system -has and leave this parameter undefined. The number of used cores will be -logged into the message logs and if you are not satisfied with the -auto-detected value, you can manually configure it. Increasing the amount -of worker threads beyond the number of processor cores does not improve -the performance, rather is likely to degrade it, and can consume resources -needlessly. +events coming from the kernel. The default is 1 thread. It is recommended that +you start with one thread and increase the number if you require greater +performance. Increasing the amount of worker threads beyond the number of +processor cores does not improve the performance, rather is likely to degrade +it, and can consume resources needlessly. + +You can enable automatic configuration of this value by setting the value to +`auto`. This way MaxScale will detect the number of available processors and +set the amount of threads to be equal to that number. This should only be used +for systems dedicated for running MaxScale. ``` # Valid options are: -# threads= +# threads=[ | auto ] [MaxScale] threads=1 diff --git a/server/core/config.c b/server/core/config.c index 75c65007c..703ebf972 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1578,15 +1578,33 @@ handle_global_item(const char *name, const char *value) int i; if (strcmp(name, "threads") == 0) { - int thrcount = atoi(value); - if (thrcount > 0) + if (strcmp(name, "auto") == 0) { - gateway.n_threads = thrcount; + if ((gateway.n_threads = get_processor_count()) > 1) + { + gateway.n_threads--; + } } else { - MXS_WARNING("Invalid value for 'threads': %s.", value); - return 0; + int thrcount = atoi(value); + if (thrcount > 0) + { + gateway.n_threads = thrcount; + + int processor_count = get_processor_count(); + if (thrcount > processor_count) + { + MXS_WARNING("Number of threads set to %d which is greater than" + " the number of processors available: %d", + thrcount, processor_count); + } + } + else + { + MXS_WARNING("Invalid value for 'threads': %s.", value); + return 0; + } } } else if (strcmp(name, "non_blocking_polls") == 0) @@ -1706,7 +1724,7 @@ global_defaults() { uint8_t mac_addr[6]=""; struct utsname uname_data; - gateway.n_threads = get_processor_count(); + gateway.n_threads = DEFAULT_NTHREADS; gateway.n_nbpoll = DEFAULT_NBPOLLS; gateway.pollsleep = DEFAULT_POLLSLEEP; gateway.auth_conn_timeout = DEFAULT_AUTH_CONNECT_TIMEOUT; diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c index 175586f57..57c562b9b 100644 --- a/server/core/gw_utils.c +++ b/server/core/gw_utils.c @@ -237,8 +237,8 @@ long get_processor_count() #ifdef _SC_NPROCESSORS_ONLN if ((processors = sysconf(_SC_NPROCESSORS_ONLN)) <= 0) { - MXS_WARNING("Unable to establish the number of available cores. Defaulting to 4."); - processors = 4; + MXS_WARNING("Unable to establish the number of available cores. Defaulting to 1."); + processors = 1; } #else #error _SC_NPROCESSORS_ONLN not available. diff --git a/server/include/maxconfig.h b/server/include/maxconfig.h index 89ee2abeb..439157dba 100644 --- a/server/include/maxconfig.h +++ b/server/include/maxconfig.h @@ -41,6 +41,7 @@ #define DEFAULT_POLLSLEEP 1000 /**< Default poll wait time (milliseconds) */ #define _SYSNAME_STR_LENGTH 256 /**< sysname len */ #define _RELEASE_STR_LENGTH 256 /**< release len */ +#define DEFAULT_NTHREADS 1 /**< Default number of polling threads */ /** * Maximum length for configuration parameter value. */ diff --git a/server/maxscale_template.cnf b/server/maxscale_template.cnf index 26e35d8a4..e9b5f94aa 100644 --- a/server/maxscale_template.cnf +++ b/server/maxscale_template.cnf @@ -3,12 +3,11 @@ # Global parameters # -# Number of threads is autodetected, uncomment for manual configuration # Complete list of configuration options: # https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Getting-Started/Configuration-Guide.md [maxscale] -#threads=8 +threads=1 # Server definitions #