From 529e697eafc8e48a4550beac024352d2c3120880 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Mon, 2 Nov 2015 10:29:47 +0200 Subject: [PATCH] Updated code based on review of ac308dcb2c34e081f9814ad40c0961a217c86fc4 Removed unnecessary spinlock and added more checks. --- .../Getting-Started/Configuration-Guide.md | 4 +--- server/core/config.c | 21 +++++++++---------- server/core/gw_utils.c | 10 +++++++-- server/include/maxconfig.h | 1 - 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Documentation/Getting-Started/Configuration-Guide.md b/Documentation/Getting-Started/Configuration-Guide.md index 4eaf175e6..a4af5529c 100644 --- a/Documentation/Getting-Started/Configuration-Guide.md +++ b/Documentation/Getting-Started/Configuration-Guide.md @@ -54,9 +54,7 @@ The global settings, in a section named `[MaxScale]`, allow various parameters t #### `threads` -This parameter controls the number of threads that poll for network traffic. MaxScale will autodetect 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 autodetected value, you can manually configure it. - -If you want to fine-tune the number of threads, start with a single thread and add more as you find the performance is not satisfactory. MaxScale is implemented to be very thread efficient, so a small number of threads is usually adequate to support reasonably heavy workloads. Adding more threads may not improve performance and can consume resources needlessly. Increasing the amount of worker threads beyond the number of processor cores is not recommended. +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 performance and can consume resources needlessly. ``` # Valid options are: diff --git a/server/core/config.c b/server/core/config.c index b1c713a6b..ae7181a41 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -1495,15 +1495,6 @@ CONFIG_PARAMETER *p1, *p2; int config_threadcount() { - spinlock_acquire(&gateway.lock); - if(gateway.n_threads <= 0) - { - int nthr = get_processor_count(); - skygw_log_write(LE, "Warning: Invalid value for 'threads': %d. Using default " - "number of %d threads.", gateway.n_threads, nthr); - gateway.n_threads = nthr; - } - spinlock_release(&gateway.lock); return gateway.n_threads; } @@ -1564,7 +1555,16 @@ handle_global_item(const char *name, const char *value) int i; if (strcmp(name, "threads") == 0) { - gateway.n_threads = atoi(value); + int thrcount = atoi(value); + if (thrcount > 0) + { + gateway.n_threads = thrcount; + } + else + { + skygw_log_write(LE, "Warning: Invalid value for 'threads': %d. Using default " + "number of %d threads.", thrcount, gateway.n_threads); + } } else if (strcmp(name, "non_blocking_polls") == 0) { @@ -1667,7 +1667,6 @@ global_defaults() { uint8_t mac_addr[6]=""; struct utsname uname_data; - spinlock_init(&gateway.lock); gateway.n_threads = get_processor_count(); gateway.n_nbpoll = DEFAULT_NBPOLLS; gateway.pollsleep = DEFAULT_POLLSLEEP; diff --git a/server/core/gw_utils.c b/server/core/gw_utils.c index 593cb447f..043a4d645 100644 --- a/server/core/gw_utils.c +++ b/server/core/gw_utils.c @@ -235,8 +235,14 @@ struct hostent *hp; long get_processor_count() { long processors = 1; -#ifdef _SC_NPROCESSORS_CONF - processors = sysconf(_SC_NPROCESSORS_CONF); +#ifdef _SC_NPROCESSORS_ONLN + if ((processors = sysconf(_SC_NPROCESSORS_ONLN)) <= 0) + { + skygw_log_write(LE, "Unable to establish the number of available cores. Defaulting to 4."); + processors = 4; + } +#else +#error _SC_NPROCESSORS_ONLN not available. #endif return processors; } \ No newline at end of file diff --git a/server/include/maxconfig.h b/server/include/maxconfig.h index e5ae5989a..f6fb52596 100644 --- a/server/include/maxconfig.h +++ b/server/include/maxconfig.h @@ -97,7 +97,6 @@ typedef struct config_context { * The gateway global configuration data */ typedef struct { - SPINLOCK lock; /*< Lock used when accessing the global configuration */ int n_threads; /**< Number of polling threads */ char *version_string; /**< The version string of embedded database library */ char release_string[_SYSNAME_STR_LENGTH]; /**< The release name string of the system */