Updated code based on review of ac308dcb2c34e081f9814ad40c0961a217c86fc4
Removed unnecessary spinlock and added more checks.
This commit is contained in:
@ -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:
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -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 */
|
||||
|
Reference in New Issue
Block a user