From dc7bf4a767a6aec72a664e99677f0075ab89ac2c Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Jun 15 2020 15:01:02 +0000 Subject: Issue 51072 - Set the default minimum worker threads Description: Testing has shown that using current number of CPU cores to set the thread number gives the best performance, but when there are expensive operations total throughput drops. We still need a minimum number of workers threads to handle a wide range of operations. We decided for now that the minimum should be 16 workers. relates: https://pagure.io/389-ds-base/issue/51072 Reviewed by: tbordaz & firstyear (Thanks!!) Define MAX and MIN threads, and improve logging --- diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c index fbf90d9..d540d84 100644 --- a/ldap/servers/slapd/libglobs.c +++ b/ldap/servers/slapd/libglobs.c @@ -5905,11 +5905,6 @@ config_get_threadnumber(void) retVal = util_get_hardware_threads(); } - /* We *still* can't detect hardware threads. Okay, return 30 :( */ - if (retVal <= 0) { - retVal = 30; - } - return retVal; } diff --git a/ldap/servers/slapd/util.c b/ldap/servers/slapd/util.c index fc67d70..fda4fdf 100644 --- a/ldap/servers/slapd/util.c +++ b/ldap/servers/slapd/util.c @@ -26,6 +26,7 @@ #include "snmp_collator.h" #include #include +#include #define UTIL_ESCAPE_NONE 0 #define UTIL_ESCAPE_HEX 1 @@ -40,6 +41,9 @@ #define FILTER_BUF 128 /* initial buffer size for attr value */ #define BUF_INCR 16 /* the amount to increase the FILTER_BUF once it fills up */ +#define MIN_THREADS 16 +#define MAX_THREADS 512 + /* slapi-private contains the pal. */ #include @@ -1487,26 +1491,39 @@ util_is_cachesize_sane(slapi_pal_meminfo *mi, uint64_t *cachesize) long util_get_hardware_threads(void) { + long threads = MIN_THREADS; #ifdef LINUX long hw_threads = sysconf(_SC_NPROCESSORS_ONLN); - long threads = 0; - slapi_log_err(SLAPI_LOG_TRACE, "util_get_hardware_threads", "Detected %lu hardware threads\n", threads); - if (hw_threads == 0) { - /* Error! */ - threads = -1; - } else if (hw_threads < 512) { - threads = hw_threads; - } else { - /* Cap at 512 for now ... */ - threads = 512; + + slapi_log_err(SLAPI_LOG_TRACE, "util_get_hardware_threads", + "Detected %ld hardware threads\n", hw_threads); + + if (hw_threads == -1) { + /* sysconf failed, use MIN_THREADS */ + slapi_log_err(SLAPI_LOG_ERR, "util_get_hardware_threads", + "Failed to get hardware threads. Error (%d) %s\n", + errno, slapd_system_strerror(errno)); + } else if (hw_threads == 0) { + /* sysconf failed to find any processors, use MIN_THREADS */ + slapi_log_err(SLAPI_LOG_ERR, "util_get_hardware_threads", + "Cannot detect any hardware threads.\n"); + } else if (hw_threads > MIN_THREADS) { + if (hw_threads < MAX_THREADS) { + threads = hw_threads; + } else { + /* Cap at 512 for now ... */ + threads = MAX_THREADS; + } } - slapi_log_err(SLAPI_LOG_INFO, "util_get_hardware_threads", "Automatically configuring %lu threads\n", threads); + + slapi_log_err(SLAPI_LOG_INFO, "util_get_hardware_threads", "Automatically configuring %ld threads\n", threads); return threads; #else - slapi_log_err(SLAPI_LOG_ERR, "util_get_hardware_threads", "ERROR: Cannot detect hardware threads on this platform. This is probably a bug!\n"); - /* Can't detect threads on this platform! */ - return -1; + slapi_log_err(SLAPI_LOG_ERR, "util_get_hardware_threads", + "ERROR: Cannot detect hardware threads on this platform. This is probably a bug!\n"); + /* Can't detect threads on this platform! Return the default thread number */ + return threads; #endif }