Fix to MXS-436: https://mariadb.atlassian.net/browse/MXS-436
Added autodetection of processor cores and used it as the default if an invalid value is used for threads.
This commit is contained in:
@ -50,11 +50,13 @@ Please see the section about [Protocol Modules](#protocol-modules) for more deta
|
||||
|
||||
### Global Settings
|
||||
|
||||
The global settings, in a section named `[MaxScale]`, allow various parameters that affect MaxScale as a whole to be tuned. Currently the only setting that is supported is the number of threads to use to handle the network traffic. MaxScale will also accept the section name of `[gateway]` for global settings. This is for backward compatibility with versions prior to the naming of MaxScale.
|
||||
The global settings, in a section named `[MaxScale]`, allow various parameters that affect MaxScale as a whole to be tuned.
|
||||
|
||||
#### `threads`
|
||||
|
||||
To control the number of threads that poll for network traffic set the parameter threads to a number. It is recommended that you 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.
|
||||
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.
|
||||
|
||||
```
|
||||
# Valid options are:
|
||||
|
||||
@ -75,6 +75,7 @@
|
||||
#include <sys/utsname.h>
|
||||
#include <pcre.h>
|
||||
#include <dbusers.h>
|
||||
#include <gw.h>
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#include <pcre2.h>
|
||||
|
||||
@ -1494,6 +1495,15 @@ 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;
|
||||
}
|
||||
|
||||
@ -1657,7 +1667,8 @@ global_defaults()
|
||||
{
|
||||
uint8_t mac_addr[6]="";
|
||||
struct utsname uname_data;
|
||||
gateway.n_threads = 1;
|
||||
spinlock_init(&gateway.lock);
|
||||
gateway.n_threads = get_processor_count();
|
||||
gateway.n_nbpoll = DEFAULT_NBPOLLS;
|
||||
gateway.pollsleep = DEFAULT_POLLSLEEP;
|
||||
gateway.auth_conn_timeout = DEFAULT_AUTH_CONNECT_TIMEOUT;
|
||||
|
||||
@ -226,3 +226,17 @@ struct hostent *hp;
|
||||
addr->sin_port = htons(pnum);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of processors available.
|
||||
* @return Number of processors or 1 if the required definition of _SC_NPROCESSORS_CONF
|
||||
* is not found
|
||||
*/
|
||||
long get_processor_count()
|
||||
{
|
||||
long processors = 1;
|
||||
#ifdef _SC_NPROCESSORS_CONF
|
||||
processors = sysconf(_SC_NPROCESSORS_CONF);
|
||||
#endif
|
||||
return processors;
|
||||
}
|
||||
@ -88,4 +88,5 @@ int gw_getsockerrno(int fd);
|
||||
int parse_bindconfig(char *, unsigned short, struct sockaddr_in *);
|
||||
int setipaddress(struct in_addr *, char *);
|
||||
char* get_libdir();
|
||||
long get_processor_count();
|
||||
#endif
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include <skygw_utils.h>
|
||||
#include <stdint.h>
|
||||
#include <openssl/sha.h>
|
||||
#include <spinlock.h>
|
||||
/**
|
||||
* @file config.h The configuration handling elements
|
||||
*
|
||||
@ -96,6 +97,7 @@ 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 */
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
|
||||
# Global parameters
|
||||
#
|
||||
# Set the number of threads to a value equal to the number of CPU cores.
|
||||
# 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=4
|
||||
#threads=8
|
||||
|
||||
# Server definitions
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user