From: Razvan Becheriu Date: Thu, 9 Apr 2020 12:30:37 +0000 (+0300) Subject: [#893] parse multi-threading config and apply X-Git-Tag: Kea-1.7.7~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bbdc09943b1b29ebc4976b84f12b7749547baef;p=thirdparty%2Fkea.git [#893] parse multi-threading config and apply --- diff --git a/src/bin/dhcp4/ctrl_dhcp4_srv.cc b/src/bin/dhcp4/ctrl_dhcp4_srv.cc index 055ed5024c..6ddd9a2873 100644 --- a/src/bin/dhcp4/ctrl_dhcp4_srv.cc +++ b/src/bin/dhcp4/ctrl_dhcp4_srv.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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(); diff --git a/src/bin/dhcp6/ctrl_dhcp6_srv.cc b/src/bin/dhcp6/ctrl_dhcp6_srv.cc index 3cbbf85cee..1d875b60c6 100644 --- a/src/bin/dhcp6/ctrl_dhcp6_srv.cc +++ b/src/bin/dhcp6/ctrl_dhcp6_srv.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -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(); diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am index 4792ad55f4..ad56594716 100644 --- a/src/lib/dhcpsrv/Makefile.am +++ b/src/lib/dhcpsrv/Makefile.am @@ -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 index 0000000000..9a13c61885 --- /dev/null +++ b/src/lib/dhcpsrv/cfg_multi_threading.cc @@ -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 + +#include +#include +#include +#include + +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 index 0000000000..dfae9013da --- /dev/null +++ b/src/lib/dhcpsrv/cfg_multi_threading.h @@ -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 + +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