Blame SOURCES/0021-Issue-49256-log-warning-when-thread-number-is-very-d.patch

d69b2b
From 2be9d1b4332d3b9b55a2d285e9610813100e235f Mon Sep 17 00:00:00 2001
d69b2b
From: Mark Reynolds <mreynolds@redhat.com>
d69b2b
Date: Mon, 22 Jun 2020 17:49:10 -0400
d69b2b
Subject: [PATCH] Issue 49256 - log warning when thread number is very
d69b2b
 different from autotuned value
d69b2b
d69b2b
Description:  To help prevent customers from setting incorrect values for
d69b2b
              the thread number it would be useful to warn them that the
d69b2b
              configured value is either way too low or way too high.
d69b2b
d69b2b
relates: https://pagure.io/389-ds-base/issue/49256
d69b2b
d69b2b
Reviewed by: firstyear(Thanks!)
d69b2b
---
d69b2b
 .../tests/suites/config/autotuning_test.py    | 28 +++++++++++++++
d69b2b
 ldap/servers/slapd/libglobs.c                 | 34 ++++++++++++++++++-
d69b2b
 ldap/servers/slapd/slap.h                     |  3 ++
d69b2b
 3 files changed, 64 insertions(+), 1 deletion(-)
d69b2b
d69b2b
diff --git a/dirsrvtests/tests/suites/config/autotuning_test.py b/dirsrvtests/tests/suites/config/autotuning_test.py
d69b2b
index d1c751444..540761250 100644
d69b2b
--- a/dirsrvtests/tests/suites/config/autotuning_test.py
d69b2b
+++ b/dirsrvtests/tests/suites/config/autotuning_test.py
d69b2b
@@ -43,6 +43,34 @@ def test_threads_basic(topo):
d69b2b
     assert topo.standalone.config.get_attr_val_int("nsslapd-threadnumber") > 0
d69b2b
 
d69b2b
 
d69b2b
+def test_threads_warning(topo):
d69b2b
+    """Check that we log a warning if the thread number is too high or low
d69b2b
+
d69b2b
+    :id: db92412b-2812-49de-84b0-00f452cd254f
d69b2b
+    :setup: Standalone Instance
d69b2b
+    :steps:
d69b2b
+        1. Get autotuned thread number
d69b2b
+        2. Set threads way higher than hw threads, and find a warning in the log
d69b2b
+        3. Set threads way lower than hw threads, and find a warning in the log
d69b2b
+    :expectedresults:
d69b2b
+        1. Success
d69b2b
+        2. Success
d69b2b
+        3. Success
d69b2b
+    """
d69b2b
+    topo.standalone.config.set("nsslapd-threadnumber", "-1")
d69b2b
+    autotuned_value = topo.standalone.config.get_attr_val_utf8("nsslapd-threadnumber")
d69b2b
+
d69b2b
+    topo.standalone.config.set("nsslapd-threadnumber", str(int(autotuned_value) * 4))
d69b2b
+    time.sleep(.5)
d69b2b
+    assert topo.standalone.ds_error_log.match('.*higher.*hurt server performance.*')
d69b2b
+
d69b2b
+    if int(autotuned_value) > 1:
d69b2b
+        # If autotuned is 1, there isn't anything to test here
d69b2b
+        topo.standalone.config.set("nsslapd-threadnumber", "1")
d69b2b
+        time.sleep(.5)
d69b2b
+        assert topo.standalone.ds_error_log.match('.*lower.*hurt server performance.*')
d69b2b
+
d69b2b
+
d69b2b
 @pytest.mark.parametrize("invalid_value", ('-2', '0', 'invalid'))
d69b2b
 def test_threads_invalid_value(topo, invalid_value):
d69b2b
     """Check nsslapd-threadnumber for an invalid values
d69b2b
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
d69b2b
index fbf90d92d..88676a303 100644
d69b2b
--- a/ldap/servers/slapd/libglobs.c
d69b2b
+++ b/ldap/servers/slapd/libglobs.c
d69b2b
@@ -4374,6 +4374,7 @@ config_set_threadnumber(const char *attrname, char *value, char *errorbuf, int a
d69b2b
 {
d69b2b
     int retVal = LDAP_SUCCESS;
d69b2b
     int32_t threadnum = 0;
d69b2b
+    int32_t hw_threadnum = 0;
d69b2b
     char *endp = NULL;
d69b2b
 
d69b2b
     slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
d69b2b
@@ -4386,8 +4387,39 @@ config_set_threadnumber(const char *attrname, char *value, char *errorbuf, int a
d69b2b
     threadnum = strtol(value, &endp, 10);
d69b2b
 
d69b2b
     /* Means we want to re-run the hardware detection. */
d69b2b
+    hw_threadnum = util_get_hardware_threads();
d69b2b
     if (threadnum == -1) {
d69b2b
-        threadnum = util_get_hardware_threads();
d69b2b
+        threadnum = hw_threadnum;
d69b2b
+    } else {
d69b2b
+        /*
d69b2b
+         * Log a message if the user defined thread number is very different
d69b2b
+         * from the hardware threads as this is probably not the optimal
d69b2b
+         * value.
d69b2b
+         */
d69b2b
+        if (threadnum >= hw_threadnum) {
d69b2b
+            if (threadnum > MIN_THREADS && threadnum / hw_threadnum >= 4) {
d69b2b
+                /* We're over the default minimum and way higher than the hw
d69b2b
+                 * threads. */
d69b2b
+                slapi_log_err(SLAPI_LOG_NOTICE, "config_set_threadnumber",
d69b2b
+                        "The configured thread number (%d) is significantly "
d69b2b
+                        "higher than the number of hardware threads (%d).  "
d69b2b
+                        "This can potentially hurt server performance.  If "
d69b2b
+                        "you are unsure how to tune \"nsslapd-threadnumber\" "
d69b2b
+                        "then set it to \"-1\" and the server will tune it "
d69b2b
+                        "according to the system hardware\n",
d69b2b
+                        threadnum, hw_threadnum);
d69b2b
+            }
d69b2b
+        } else if (threadnum < MIN_THREADS) {
d69b2b
+            /* The thread number should never be less than the minimum and
d69b2b
+             * hardware threads. */
d69b2b
+            slapi_log_err(SLAPI_LOG_WARNING, "config_set_threadnumber",
d69b2b
+                    "The configured thread number (%d) is lower than the number "
d69b2b
+                    "of hardware threads (%d).  This will hurt server performance.  "
d69b2b
+                    "If you are unsure how to tune \"nsslapd-threadnumber\" then "
d69b2b
+                    "set it to \"-1\" and the server will tune it according to the "
d69b2b
+                    "system hardware\n",
d69b2b
+                    threadnum, hw_threadnum);
d69b2b
+            }
d69b2b
     }
d69b2b
 
d69b2b
     if (*endp != '\0' || errno == ERANGE || threadnum < 1 || threadnum > 65535) {
d69b2b
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
d69b2b
index 8e76393c3..894efd29c 100644
d69b2b
--- a/ldap/servers/slapd/slap.h
d69b2b
+++ b/ldap/servers/slapd/slap.h
d69b2b
@@ -403,6 +403,9 @@ typedef void (*VFPV)(); /* takes undefined arguments */
d69b2b
 #define SLAPD_DEFAULT_PW_MAX_CLASS_CHARS_ATTRIBUTE 0
d69b2b
 #define SLAPD_DEFAULT_PW_MAX_CLASS_CHARS_ATTRIBUTE_STR "0"
d69b2b
 
d69b2b
+#define MIN_THREADS 16
d69b2b
+#define MAX_THREADS 512
d69b2b
+
d69b2b
 
d69b2b
 /* Default password values. */
d69b2b
 
d69b2b
-- 
d69b2b
2.26.2
d69b2b