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

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