From ae3e721f623764ebc38ef8bed198f2d0f5288900 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Wed, 3 Oct 2018 15:45:29 +0000 Subject: [PATCH] Changed MDP3 producer to honor new thread configuration. --- src/lib/config/defaults/orderman_cfg.conf | 18 +++++++ src/lib/config/defaults/threads.conf | 5 +- src/lib/config/protos/MarketData.proto | 2 +- src/lib/utils/thread_manager.cpp | 54 ++++++++++++------- src/lib/utils/thread_manager.h | 2 + .../md/platforms/mdp3_onixs/MDP3Main.cpp | 6 ++- 6 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/lib/config/defaults/orderman_cfg.conf b/src/lib/config/defaults/orderman_cfg.conf index 30e9e515b..38dcf1639 100644 --- a/src/lib/config/defaults/orderman_cfg.conf +++ b/src/lib/config/defaults/orderman_cfg.conf @@ -1,3 +1,21 @@ +OrdermanCfg { + rule: "DeploymentType.type == 'dev'" + value { + executor { + thread_name: "oman_orders" + poll: false + hosted_actor: "MDSource" + hosted_actor: "OrderManager" + hosted_actor: "ExecutionGateway" + } + executor { + thread_name: "oman_slow" + poll: false + hosted_actor: "*" + } + } +} + OrdermanCfg { value { executor { diff --git a/src/lib/config/defaults/threads.conf b/src/lib/config/defaults/threads.conf index 2106c010b..02c0d6f44 100644 --- a/src/lib/config/defaults/threads.conf +++ b/src/lib/config/defaults/threads.conf @@ -1,6 +1,7 @@ Threads { value { - thread_group {name_rx: "oman_orders" core: 0} - thread_group {name_rx: ".*" exclude:true core:0} + thread_group {name_rx: "mdp3feed" core: 0} + thread_group {name_rx: "oman_orders" core: 1} + thread_group {name_rx: ".*" exclude:true core:0 core:1} } } \ No newline at end of file diff --git a/src/lib/config/protos/MarketData.proto b/src/lib/config/protos/MarketData.proto index eaf069a98..df6c5f924 100755 --- a/src/lib/config/protos/MarketData.proto +++ b/src/lib/config/protos/MarketData.proto @@ -75,7 +75,7 @@ message CMEOptions // Defines amount of time Feed Engine keeps cycling before going to sleep when no useful activity can be done optional uint32 spin_time = 4 [default = 1]; optional uint32 channels_per_thread = 5 [default = 3]; - repeated uint32 affinity = 10; + optional string thread_group = 10 [default=""]; // if present this will be used to retrieve affinity settings from Threads config key optional uint32 udp_socket_buffer_size = 11 [default = 33554432]; //32mb } enum BookType { diff --git a/src/lib/utils/thread_manager.cpp b/src/lib/utils/thread_manager.cpp index 81649db15..4120ac231 100644 --- a/src/lib/utils/thread_manager.cpp +++ b/src/lib/utils/thread_manager.cpp @@ -24,6 +24,23 @@ config::ThreadGroupCfg get_thread_cfg(std::string const &name) { fmt::format("No configuration found for thread {}", name)); } +std::vector get_affinity(std::string const &name) { + std::vector result; +#ifndef WIN32 + auto cfg = get_thread_cfg(name); + if (cfg.exclude()) { + auto total_cpus = sysconf(_SC_NPROCESSORS_ONLN); + for (int i = 0; i < total_cpus; i++) + if (std::find(cfg.core().begin(), cfg.core().end(), i) == cfg.core().end()) + result.push_back(i); + } else { + for (auto const &core : cfg.core()) + result.push_back(core); + } +#endif + return result; +} + #ifndef WIN32 void configure_thread(std::string const &name, config::ThreadGroupCfg const &cfg, pthread_t t) { @@ -54,46 +71,43 @@ void configure_thread(std::string const &name, #endif void configure_current_thread(std::string const &name) { - #ifndef WIN32 +#ifndef WIN32 configure_thread(name, get_thread_cfg(name), pthread_self()); - #endif +#endif os::set_thread_name(name); - } void configure_current_thread(std::string const &name, config::ThreadGroupCfg const &cfg) { - #ifndef WIN32 +#ifndef WIN32 configure_thread(name, cfg, pthread_self()); - #endif +#endif os::set_thread_name(name); } std::thread make_thread_from_function(std::string const &name, std::function const &c) { - auto result = std::thread( - [c,name] () { - os::set_thread_name(name); - c(); - }); - - #ifndef WIN32 + auto result = std::thread([c, name]() { + os::set_thread_name(name); + c(); + }); + +#ifndef WIN32 configure_thread(name, get_thread_cfg(name), result.native_handle()); - #endif +#endif return result; } std::thread make_thread_from_function(std::string const &name, std::function const &c, config::ThreadGroupCfg const &cfg) { - auto result = std::thread( - [c,name] () { - os::set_thread_name(name); - c(); - }); - #ifndef WIN32 + auto result = std::thread([c, name]() { + os::set_thread_name(name); + c(); + }); +#ifndef WIN32 configure_thread(name, cfg, result.native_handle()); - #endif +#endif return result; } diff --git a/src/lib/utils/thread_manager.h b/src/lib/utils/thread_manager.h index 622af742e..6c5ce4556 100644 --- a/src/lib/utils/thread_manager.h +++ b/src/lib/utils/thread_manager.h @@ -27,4 +27,6 @@ void configure_current_thread(std::string const&name, config::ThreadGroupCfg con config::ThreadGroupCfg get_thread_cfg(std::string const &); +std::vector get_affinity(std::string const&name); + }} diff --git a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp index 98e31a9c3..115a23e64 100644 --- a/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp +++ b/src/server/sparkd/md/platforms/mdp3_onixs/MDP3Main.cpp @@ -11,6 +11,8 @@ #include "lib/config/protos/MarketData.pb.h" #include "lib/config/protos/system.pb.h" +#include "lib/utils/thread_manager.h" + #include #include @@ -62,8 +64,8 @@ const onixs::FeedEngineSettings feed_engine_settings_from_config(const CMEOption result.socketBufferSize(settings.udp_socket_buffer_size()); - - for (auto& core : settings.affinity()) { + auto affinity = threading::get_affinity("mdp3feed"); + for (auto& core : affinity) { result.threadAffinity().cpus().insert(core); }