mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +00:00
[#892] refactored
This commit is contained in:
parent
7d300cabc8
commit
16dfb865b1
@ -169,16 +169,9 @@ ControlledDhcpv4Srv::loadConfigFile(const std::string& file_name) {
|
||||
"processCommand(\"config-set\", json)");
|
||||
}
|
||||
|
||||
if (MultiThreadingUtil::threadCount()) {
|
||||
auto& thread_pool = MultiThreadingMgr::instance().getPktThreadPool();
|
||||
if (thread_pool.size()) {
|
||||
thread_pool.stop();
|
||||
}
|
||||
MultiThreadingMgr::instance().setMode(true);
|
||||
thread_pool.start(MultiThreadingUtil::threadCount());
|
||||
} else {
|
||||
MultiThreadingMgr::instance().setMode(false);
|
||||
}
|
||||
// @todo enable multi-threading - disabled for now
|
||||
MultiThreadingMgr::instance().apply(false,
|
||||
CfgMgr::instance().getCurrentCfg()->getServerThreadCount());
|
||||
|
||||
// Now check is the returned result is successful (rcode=0) or not
|
||||
// (see @ref isc::config::parseAnswer).
|
||||
|
@ -803,9 +803,7 @@ Dhcpv4Srv::run() {
|
||||
}
|
||||
|
||||
// destroying the thread pool
|
||||
if (MultiThreadingMgr::instance().getMode()) {
|
||||
MultiThreadingMgr::instance().getPktThreadPool().reset();
|
||||
}
|
||||
MultiThreadingMgr::instance().apply(false, 0);
|
||||
|
||||
return (true);
|
||||
}
|
||||
@ -821,8 +819,8 @@ Dhcpv4Srv::run_one() {
|
||||
|
||||
// Do not read more packets from socket if there are enough
|
||||
// packets to be processed in the packet thread pool queue
|
||||
const int max_queue_size = MultiThreadingUtil::maxThreadQueueSize();
|
||||
const int thread_count = MultiThreadingUtil::threadCount();
|
||||
const int max_queue_size = CfgMgr::instance().getCurrentCfg()->getServerMaxThreadQueueSize();
|
||||
const int thread_count = MultiThreadingMgr::instance().getPktThreadPoolSize();
|
||||
size_t pkt_queue_size = MultiThreadingMgr::instance().getPktThreadPool().count();
|
||||
if (thread_count && (pkt_queue_size >= thread_count * max_queue_size)) {
|
||||
read_pkt = false;
|
||||
|
@ -141,16 +141,9 @@ ControlledDhcpv6Srv::loadConfigFile(const std::string& file_name) {
|
||||
"processCommand(\"config-set\", json)");
|
||||
}
|
||||
|
||||
if (MultiThreadingUtil::threadCount()) {
|
||||
auto& thread_pool = MultiThreadingMgr::instance().getPktThreadPool();
|
||||
if (thread_pool.size()) {
|
||||
thread_pool.stop();
|
||||
}
|
||||
MultiThreadingMgr::instance().setMode(true);
|
||||
thread_pool.start(MultiThreadingUtil::threadCount());
|
||||
} else {
|
||||
MultiThreadingMgr::instance().setMode(false);
|
||||
}
|
||||
// @todo enable multi-threading - disabled for now
|
||||
MultiThreadingMgr::instance().apply(false,
|
||||
CfgMgr::instance().getCurrentCfg()->getServerThreadCount());
|
||||
|
||||
// Now check is the returned result is successful (rcode=0) or not
|
||||
// (see @ref isc::config::parseAnswer).
|
||||
|
@ -473,9 +473,7 @@ bool Dhcpv6Srv::run() {
|
||||
}
|
||||
|
||||
// destroying the thread pool
|
||||
if (MultiThreadingMgr::instance().getMode()) {
|
||||
MultiThreadingMgr::instance().getPktThreadPool().reset();
|
||||
}
|
||||
MultiThreadingMgr::instance().apply(false, 0);
|
||||
|
||||
return (true);
|
||||
}
|
||||
@ -490,8 +488,8 @@ void Dhcpv6Srv::run_one() {
|
||||
|
||||
// Do not read more packets from socket if there are enough
|
||||
// packets to be processed in the packet thread pool queue
|
||||
const int max_queue_size = MultiThreadingUtil::maxThreadQueueSize();
|
||||
const int thread_count = MultiThreadingUtil::threadCount();
|
||||
const int max_queue_size = CfgMgr::instance().getCurrentCfg()->getServerMaxThreadQueueSize();
|
||||
const int thread_count = MultiThreadingMgr::instance().getPktThreadPoolSize();
|
||||
size_t pkt_queue_size = MultiThreadingMgr::instance().getPktThreadPool().count();
|
||||
if (thread_count && (pkt_queue_size >= thread_count * max_queue_size)) {
|
||||
read_pkt = false;
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <dhcpsrv/cfgmgr.h>
|
||||
#include <dhcpsrv/multi_threading_utils.h>
|
||||
#include <exceptions/exceptions.h>
|
||||
#include <util/multi_threading_mgr.h>
|
||||
@ -43,24 +42,5 @@ MultiThreadingCriticalSection::~MultiThreadingCriticalSection() {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t
|
||||
MultiThreadingUtil::threadCount() {
|
||||
uint32_t sys_threads = CfgMgr::instance().getCurrentCfg()->getServerThreadCount();
|
||||
if (sys_threads) {
|
||||
return sys_threads;
|
||||
}
|
||||
sys_threads = std::thread::hardware_concurrency();
|
||||
return sys_threads * 0;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
MultiThreadingUtil::maxThreadQueueSize() {
|
||||
uint32_t max_thread_queue_size = CfgMgr::instance().getCurrentCfg()->getServerMaxThreadQueueSize();
|
||||
if (max_thread_queue_size) {
|
||||
return max_thread_queue_size;
|
||||
}
|
||||
return 4;
|
||||
}
|
||||
|
||||
} // namespace dhcp
|
||||
} // namespace isc
|
||||
|
@ -9,8 +9,6 @@
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace isc {
|
||||
namespace dhcp {
|
||||
|
||||
@ -48,16 +46,7 @@ public:
|
||||
static void startPktProcessing();
|
||||
};
|
||||
|
||||
class MultiThreadingUtil {
|
||||
public:
|
||||
|
||||
/// @brief returns Kea DHCPv4 server thread count.
|
||||
static uint32_t threadCount();
|
||||
|
||||
/// @brief returns Kea DHCPv4 server max thread queue size.
|
||||
static uint32_t maxThreadQueueSize();
|
||||
};
|
||||
|
||||
} // namespace dhcp
|
||||
} // namespace isc
|
||||
|
||||
#endif // MULTI_THREADING_UTIL_H
|
||||
|
@ -46,5 +46,37 @@ MultiThreadingMgr::setPktThreadPoolSize(uint32_t size) {
|
||||
pkt_thread_pool_size_ = size;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
MultiThreadingMgr::supportedThreadCount(uint32_t thread_count) {
|
||||
return (std::thread::hardware_concurrency());
|
||||
}
|
||||
|
||||
void
|
||||
MultiThreadingMgr::apply(bool enabled, uint32_t thread_count) {
|
||||
// check the enabled flag
|
||||
if (enabled) {
|
||||
// check for auto scaling (enabled flag true but thread_count 0)
|
||||
if (!thread_count) {
|
||||
// might also return 0
|
||||
thread_count = MultiThreadingMgr::supportedThreadCount();
|
||||
}
|
||||
} else {
|
||||
thread_count = 0;
|
||||
}
|
||||
// check enabled flag and explicit number of threads or system supports
|
||||
// hardware concurrency
|
||||
if (thread_count) {
|
||||
if (pkt_thread_pool_.size()) {
|
||||
pkt_thread_pool_.stop();
|
||||
}
|
||||
setPktThreadPoolSize(thread_count);
|
||||
setMode(true);
|
||||
pkt_thread_pool_.start(thread_count);
|
||||
} else {
|
||||
pkt_thread_pool_.reset();
|
||||
setMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace isc
|
||||
|
@ -81,6 +81,21 @@ public:
|
||||
/// @param size The packet thread pool size of this binary instance.
|
||||
void setPktThreadPoolSize(uint32_t size);
|
||||
|
||||
/// @brief The system current supported hardware concurrency thread count.
|
||||
///
|
||||
/// This function will return 0 if the value can not be determined.
|
||||
///
|
||||
/// @return The thread count.
|
||||
static uint32_t supportedThreadCount();
|
||||
|
||||
/// @brief Apply the multi-threading related settings
|
||||
///
|
||||
/// @param enabled The enabled flag: true if multi-threading is enabled,
|
||||
/// false otherwise.
|
||||
/// @param thread_count The number of desired threads: non 0 if explicitly
|
||||
/// configured, 0 if auto scaling is desired
|
||||
void apply(bool enabled, uint32_t thread_count);
|
||||
|
||||
protected:
|
||||
|
||||
/// @brief Constructor.
|
||||
|
Loading…
x
Reference in New Issue
Block a user