]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#893] parse multi-threading config and apply
authorRazvan Becheriu <razvan@isc.org>
Thu, 9 Apr 2020 12:30:37 +0000 (15:30 +0300)
committerRazvan Becheriu <razvan@isc.org>
Tue, 14 Apr 2020 19:28:19 +0000 (22:28 +0300)
src/bin/dhcp4/ctrl_dhcp4_srv.cc
src/bin/dhcp6/ctrl_dhcp6_srv.cc
src/lib/dhcpsrv/Makefile.am
src/lib/dhcpsrv/cfg_multi_threading.cc [new file with mode: 0644]
src/lib/dhcpsrv/cfg_multi_threading.h [new file with mode: 0644]

index 055ed5024c016cf3bd9ea1fed63d6dd12fc229f2..6ddd9a2873136866fe8001ea91dca57a1b9a2ff6 100644 (file)
@@ -17,6 +17,7 @@
 #include <dhcp4/json_config_parser.h>
 #include <dhcp4/parser_context.h>
 #include <dhcpsrv/cfg_db_access.h>
+#include <dhcpsrv/cfg_multi_threading.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/db_type.h>
 #include <hooks/hooks.h>
@@ -878,24 +879,11 @@ ControlledDhcpv4Srv::processConfig(isc::data::ConstElementPtr config) {
 
     // Configure multi threading
     try {
-        data::ConstElementPtr mt;
-        // command line parameters overwrite file and database configuration
-        bool enabled = false;
-        uint32_t thread_pool_size = 0;
-        uint32_t thread_queue_size = 0;
-        if (Dhcpv4Srv::srv_thread_count_ >= 0) {
-            enabled = true;
-        }
-        if (enabled) {
-            thread_pool_size = Dhcpv4Srv::srv_thread_count_;
+        CfgMultiThreading::apply(Dhcpv4Srv::srv_thread_count_,
+            CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
+        if (MultiThreadingMgr::instance().getMode()) {
             LOG_FATAL(dhcp4_logger, DHCP4_MULTI_THREADING_WARNING);
-        } else {
-            enabled = false; // todo parse
-            thread_pool_size = 0; // todo parse
-            thread_queue_size = 0; // todo parse
         }
-        MultiThreadingMgr::instance().apply(enabled, thread_pool_size,
-                                            thread_queue_size);
     } catch (const std::exception& ex) {
         err << "Error applying multi threading settings: "
             << ex.what();
index 3cbbf85cee9559b78ea0390b17cc24845fac3178..1d875b60c6ad9965c58e0144eb351b4f964b9cd3 100644 (file)
@@ -17,6 +17,7 @@
 #include <dhcp6/json_config_parser.h>
 #include <dhcp6/parser_context.h>
 #include <dhcpsrv/cfg_db_access.h>
+#include <dhcpsrv/cfg_multi_threading.h>
 #include <dhcpsrv/cfgmgr.h>
 #include <dhcpsrv/db_type.h>
 #include <hooks/hooks.h>
@@ -900,24 +901,11 @@ ControlledDhcpv6Srv::processConfig(isc::data::ConstElementPtr config) {
 
     // Configure multi threading
     try {
-        data::ConstElementPtr mt;
-        // command line parameters overwrite file and database configuration
-        bool enabled = false;
-        uint32_t thread_pool_size = 0;
-        uint32_t thread_queue_size = 0;
-        if (Dhcpv6Srv::srv_thread_count_ >= 0) {
-            enabled = true;
-        }
-        if (enabled) {
-            thread_pool_size = Dhcpv6Srv::srv_thread_count_;
+        CfgMultiThreading::apply(Dhcpv6Srv::srv_thread_count_,
+            CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading());
+        if (MultiThreadingMgr::instance().getMode()) {
             LOG_FATAL(dhcp6_logger, DHCP6_MULTI_THREADING_WARNING);
-        } else {
-            enabled = false; // todo parse
-            thread_pool_size = 0; // todo parse
-            thread_queue_size = 0; // todo parse
         }
-        MultiThreadingMgr::instance().apply(enabled, thread_pool_size,
-                                            thread_queue_size);
     } catch (const std::exception& ex) {
         err << "Error applying multi threading settings: "
             << ex.what();
index 4792ad55f435b509888b68af187e948dd3f2d052..ad56594716577aa001038adf69427c37cbfd9203 100644 (file)
@@ -88,6 +88,7 @@ libkea_dhcpsrv_la_SOURCES += cfg_shared_networks.cc cfg_shared_networks.h
 libkea_dhcpsrv_la_SOURCES += cfg_subnets4.cc cfg_subnets4.h
 libkea_dhcpsrv_la_SOURCES += cfg_subnets6.cc cfg_subnets6.h
 libkea_dhcpsrv_la_SOURCES += cfg_mac_source.cc cfg_mac_source.h
+libkea_dhcpsrv_la_SOURCES += cfg_multi_threading.cc cfg_multi_threading.h
 libkea_dhcpsrv_la_SOURCES += cfgmgr.cc cfgmgr.h
 libkea_dhcpsrv_la_SOURCES += client_class_def.cc client_class_def.h
 libkea_dhcpsrv_la_SOURCES += config_backend_dhcp4.h
@@ -314,6 +315,7 @@ libkea_dhcpsrv_include_HEADERS = \
        cfg_hosts_util.h \
        cfg_iface.h \
        cfg_mac_source.h \
+       cfg_multi_threading.h \
        cfg_option.h \
        cfg_option_def.h \
        cfg_rsoo.h \
diff --git a/src/lib/dhcpsrv/cfg_multi_threading.cc b/src/lib/dhcpsrv/cfg_multi_threading.cc
new file mode 100644 (file)
index 0000000..9a13c61
--- /dev/null
@@ -0,0 +1,47 @@
+// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#include <config.h>
+
+#include <cc/data.h>
+#include <cc/simple_parser.h>
+#include <cfg_multi_threading.h>
+#include <util/multi_threading_mgr.h>
+
+using namespace isc::data;
+using namespace isc::util;
+
+namespace isc {
+namespace dhcp {
+
+void
+CfgMultiThreading::apply(int32_t overwrite, ConstElementPtr value) {
+        // command line parameters overwrite file and database configuration
+        bool enabled = false;
+        uint32_t thread_pool_size = 0;
+        uint32_t thread_queue_size = 0;
+        if (overwrite >= 0) {
+            enabled = true;
+        }
+        if (enabled) {
+            thread_pool_size = overwrite;
+        } else {
+            if (value->get("enable-multi-threading")) {
+                enabled = SimpleParser::getBoolean(value, "enable-multi-threading");
+            }
+            if (value->get("thread-pool-size")) {
+                thread_pool_size = SimpleParser::getInteger(value, "thread-pool-size");
+            }
+            if (value->get("packet-queue-size")) {
+                thread_queue_size = SimpleParser::getInteger(value, "packet-queue-size");
+            }
+        }
+        MultiThreadingMgr::instance().apply(enabled, thread_pool_size,
+                                            thread_queue_size);
+    }
+
+}  // namespace dhcp
+}  // namespace isc
diff --git a/src/lib/dhcpsrv/cfg_multi_threading.h b/src/lib/dhcpsrv/cfg_multi_threading.h
new file mode 100644 (file)
index 0000000..dfae901
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (C) 2020 Internet Systems Consortium, Inc. ("ISC")
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#ifndef CFG_MULTI_THREADING_H
+#define CFG_MULTI_THREADING_H
+
+#include <cc/data.h>
+
+namespace isc {
+namespace dhcp {
+
+/// @brief Utility class to apply multi threading configurations
+class CfgMultiThreading {
+public:
+
+    /// @brief apply multi threading configuration
+    ///
+    /// @param overwrite The value used to overwrite configuration
+    /// @param value The multi-threading configuration
+    static void apply(int32_t overwrite, data::ConstElementPtr value);
+};
+
+}  // namespace dhcp
+}  // namespace isc
+
+#endif // CFG_MULTI_THREADING_H