Changed default number of threads and added auto value.

Changed default number of threads to 1 instead of autoconfigured value and
added a new `auto` variable which enables autoconfiguration of thread count.

The number of threads used when autoconfiguratio fails was changed from 4 to 1.

The default value of using N threads where N is the number of CPU cores was
not optimal as the possibility of rescheduling was higher the more utility
threads there were. Due to this, N-1 is deemed to be the better autoconfigured
value for thread count.
This commit is contained in:
Markus Makela
2015-12-14 11:56:34 +02:00
parent 78b5777d6e
commit 8d969aadd1
5 changed files with 39 additions and 20 deletions

View File

@ -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;

View File

@ -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.