"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).
}
// destroying the thread pool
- if (MultiThreadingMgr::instance().getMode()) {
- MultiThreadingMgr::instance().getPktThreadPool().reset();
- }
+ MultiThreadingMgr::instance().apply(false, 0);
return (true);
}
// 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;
"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).
}
// destroying the thread pool
- if (MultiThreadingMgr::instance().getMode()) {
- MultiThreadingMgr::instance().getPktThreadPool().reset();
- }
+ MultiThreadingMgr::instance().apply(false, 0);
return (true);
}
// 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;
#include <config.h>
-#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/multi_threading_utils.h>
#include <exceptions/exceptions.h>
#include <util/multi_threading_mgr.h>
}
}
-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
#include <boost/noncopyable.hpp>
-#include <stdint.h>
-
namespace isc {
namespace dhcp {
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
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
/// @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.