Skip to content

Commit

Permalink
Configure the default scheduler with a maximum number of threads equa…
Browse files Browse the repository at this point in the history
…l to the number of cores on the machine
  • Loading branch information
mattrm456 committed Sep 5, 2024
1 parent a35689e commit 3ae66ef
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
2 changes: 1 addition & 1 deletion groups/ntc/ntcf/ntcf_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void createDefaultInterface(bsl::shared_ptr<ntci::Interface>* result,
ntca::InterfaceConfig interfaceConfig;
interfaceConfig.setThreadName("default");
interfaceConfig.setMinThreads(1);
interfaceConfig.setMaxThreads(64);
interfaceConfig.setMaxThreads(ntscfg::Platform::numCores());

bsl::shared_ptr<ntci::Interface> interface =
ntcf::System::createInterface(interfaceConfig, allocator);
Expand Down
2 changes: 1 addition & 1 deletion groups/ntc/ntci/ntci_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,7 @@ bsl::size_t LogUtil::formatContext(char* destination,
if (!empty) {
os << ' ';
}
os << "transport '" << logContext.d_owner << "'";
os << "scheduler '" << logContext.d_owner << "'";
empty = false;
}

Expand Down
12 changes: 6 additions & 6 deletions groups/ntc/ntcp/ntcp_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,31 @@ BSLS_IDENT_RCSID(ntcp_interface_cpp, "$Id$ $CSID$")

#define NTCP_INTERFACE_LOG_STARTING(config, numThreads) \
NTCI_LOG_DEBUG( \
"Interface '%s' is starting %d/%d thread(s) " \
"Scheduler '%s' is starting %d/%d thread(s) " \
"with %s load balancing", \
config.metricName().c_str(), \
(int)(numThreads), \
(int)(config.maxThreads()), \
(config.dynamicLoadBalancing().value() ? "dynamic" : "static"))

#define NTCP_INTERFACE_LOG_STARTED(config) \
NTCI_LOG_DEBUG("Interface '%s' has started", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' has started", config.metricName().c_str())

#define NTCP_INTERFACE_LOG_STOPPING(config) \
NTCI_LOG_DEBUG("Interface '%s' is stopping", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' is stopping", config.metricName().c_str())

#define NTCP_INTERFACE_LOG_STOPPED(config) \
NTCI_LOG_DEBUG("Interface '%s' has stopped", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' has stopped", config.metricName().c_str())

#define NTCP_INTERFACE_LOG_LOAD_FACTOR_EXCEEDED(config, load) \
NTCI_LOG_DEBUG("Interface '%s' least used thread has a load of %d, " \
NTCI_LOG_DEBUG("Scheduler '%s' least used thread has a load of %d, " \
"greater than the maximum desired load of %d", \
config.metricName().c_str(), \
(int)(load), \
(int)(config.threadLoadFactor()))

#define NTCP_INTERFACE_LOG_EXPANDING(config, numThreads) \
NTCI_LOG_DEBUG("Interface '%s' is expanding to %d/%d threads", \
NTCI_LOG_DEBUG("Scheduler '%s' is expanding to %d/%d threads", \
config.metricName().c_str(), \
(int)(numThreads), \
(int)(config.maxThreads()))
Expand Down
12 changes: 6 additions & 6 deletions groups/ntc/ntcr/ntcr_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ BSLS_IDENT_RCSID(ntcr_interface_cpp, "$Id$ $CSID$")

#define NTCR_INTERFACE_LOG_STARTING(config, numThreads) \
NTCI_LOG_DEBUG( \
"Interface '%s' is starting %d/%d thread(s) " \
"Scheduler '%s' is starting %d/%d thread(s) " \
"with %s load balancing", \
config.metricName().c_str(), \
(int)(numThreads), \
(int)(config.maxThreads()), \
(config.dynamicLoadBalancing().value() ? "dynamic" : "static"))

#define NTCR_INTERFACE_LOG_STARTED(config) \
NTCI_LOG_DEBUG("Interface '%s' has started", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' has started", config.metricName().c_str())

#define NTCR_INTERFACE_LOG_STOPPING(config) \
NTCI_LOG_DEBUG("Interface '%s' is stopping", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' is stopping", config.metricName().c_str())

#define NTCR_INTERFACE_LOG_STOPPED(config) \
NTCI_LOG_DEBUG("Interface '%s' has stopped", config.metricName().c_str())
NTCI_LOG_DEBUG("Scheduler '%s' has stopped", config.metricName().c_str())

#define NTCR_INTERFACE_LOG_LOAD_FACTOR_EXCEEDED(config, load) \
NTCI_LOG_DEBUG("Interface '%s' least used thread has a load of %d, " \
NTCI_LOG_DEBUG("Scheduler '%s' least used thread has a load of %d, " \
"greater than the maximum desired load of %d", \
config.metricName().c_str(), \
(int)(load), \
(int)(config.threadLoadFactor()))

#define NTCR_INTERFACE_LOG_EXPANDING(config, numThreads) \
NTCI_LOG_DEBUG("Interface '%s' is expanding to %d/%d threads", \
NTCI_LOG_DEBUG("Scheduler '%s' is expanding to %d/%d threads", \
config.metricName().c_str(), \
(int)(numThreads), \
(int)(config.maxThreads()))
Expand Down
27 changes: 27 additions & 0 deletions groups/nts/ntscfg/ntscfg_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ BSLS_IDENT_RCSID(ntscfg_platform_cpp, "$Id$ $CSID$")
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <limits.h>

#if defined(BSLS_PLATFORM_OS_LINUX)
#include <linux/version.h>
Expand All @@ -40,6 +41,7 @@ BSLS_IDENT_RCSID(ntscfg_platform_cpp, "$Id$ $CSID$")
#if defined(BSLS_PLATFORM_OS_WINDOWS)
#include <windows.h>
#include <winsock2.h>
#include <sysinfoapi.h>
#pragma comment(lib, "ws2_32.lib")
#endif

Expand Down Expand Up @@ -163,6 +165,31 @@ int Platform::exit()
#endif
}


bsl::size_t Platform::numCores()
{
#if defined(BSLS_PLATFORM_OS_UNIX)

errno = 0;
const int cpuCount = sysconf(_SC_NPROCESSORS_ONLN);
if (cpuCount < 0) {
return 1;
}

return static_cast<bsl::size_t>(cpuCount);

#elif defined(BSLS_PLATFORM_OS_WINDOWS)

SYSTEM_INFO systemInfo;
GetSystemInfo(&systemInfo);

return static_cast<bsl::size_t>(systemInfo.dwNumberOfProcessors);

#else
#error Not implemented
#endif
}

bool Platform::supportsNotifications()
{
#if defined(BSLS_PLATFORM_OS_LINUX)
Expand Down
3 changes: 3 additions & 0 deletions groups/nts/ntscfg/ntscfg_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,9 @@ struct Platform {
/// error otherwise.
static int exit();

/// Return the number of CPU cores on the current machine.
static bsl::size_t numCores();

/// Return true if the version of the operating system running the current
/// process supports asynchronous socket notifications via some mechanism
/// such as the Linux error queue.
Expand Down

0 comments on commit 3ae66ef

Please sign in to comment.