Added central control of threading.
This commit is contained in:
1 parent
ef3b39361a
commit
2769de6f7e
25 files changed
+259
-110
No files matched your search
@@ -18,6 +18,7 @@
|
||||
#include "lib/orderman/actors/order_manager/OrderManager.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "lib/utils/type_name.h"
|
||||
#include "lib/utils/thread_manager.h"
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
@@ -25,7 +26,7 @@ namespace bts {
|
||||
namespace orderman {
|
||||
|
||||
struct ActorThread {
|
||||
ActorThread(const config::OrdermanCfg::OrdermanThread &cfg,metrics::MetricsContainer &stats)
|
||||
ActorThread(const config::OrdermanCfg::Executor &cfg,metrics::MetricsContainer &stats)
|
||||
: cfg(cfg), thread(), executor(), loop_metric(), done(false) {
|
||||
std::array<double, 30> buckets;
|
||||
auto i = 0;
|
||||
@@ -33,14 +34,12 @@ struct ActorThread {
|
||||
b = (i += 1000);
|
||||
|
||||
loop_metric = std::make_shared<metrics::HistogramMetric<30>>(
|
||||
fmt::format("spark_metrics_{}_thread_loop_ns", cfg.name()), buckets);
|
||||
fmt::format("spark_metrics_{}_thread_loop_ns", cfg.thread_name()), buckets);
|
||||
stats.publish(loop_metric);
|
||||
}
|
||||
|
||||
void start() {
|
||||
thread = std::thread([this]() {
|
||||
os::set_thread_name(cfg.name());
|
||||
|
||||
thread = threading::make_thread(cfg.thread_name(),[this]() {
|
||||
const auto inner_iter = 1000;
|
||||
while (!done) {
|
||||
auto start = Timer::now();
|
||||
@@ -48,25 +47,10 @@ struct ActorThread {
|
||||
executor.do_work();
|
||||
auto stop = Timer::now();
|
||||
loop_metric->observe(ns_diff(stop, start) / inner_iter);
|
||||
if (!cfg.busy_poll())
|
||||
if (!cfg.poll())
|
||||
std::this_thread::sleep_for(10ms);
|
||||
}
|
||||
});
|
||||
|
||||
if (cfg.core_affinity() >= 0) {
|
||||
LOG(OrderMan, Info, "Setting {} core affinity to {}", cfg.name(),
|
||||
cfg.core_affinity());
|
||||
cpu_set_t cpuset;
|
||||
CPU_ZERO(&cpuset);
|
||||
CPU_SET(cfg.core_affinity(), &cpuset);
|
||||
int rc = pthread_setaffinity_np(thread.native_handle(),
|
||||
sizeof(cpu_set_t), &cpuset);
|
||||
if (rc != 0)
|
||||
LOG(OrderMan, Error,
|
||||
"Could not set core affinity to {} for {}. Error "
|
||||
"code={}",
|
||||
cfg.core_affinity(), cfg.name(), rc);
|
||||
}
|
||||
}
|
||||
|
||||
~ActorThread() {
|
||||
@@ -74,7 +58,7 @@ struct ActorThread {
|
||||
thread.join();
|
||||
}
|
||||
|
||||
config::OrdermanCfg::OrdermanThread cfg;
|
||||
config::OrdermanCfg::Executor cfg;
|
||||
std::thread thread;
|
||||
mercury::Executor executor;
|
||||
std::shared_ptr<metrics::HistogramMetric<30>> loop_metric;
|
||||
@@ -83,12 +67,12 @@ struct ActorThread {
|
||||
|
||||
ActorThread *find_thread_for_actor(
|
||||
std::string const &actor_name,
|
||||
std::vector<std::unique_ptr<ActorThread>> const &all_threads) {
|
||||
for (auto const &at : all_threads)
|
||||
for (auto const &hosted : at->cfg.hosted_actor())
|
||||
std::vector<std::unique_ptr<ActorThread>> const &all_executors) {
|
||||
for (auto const &ex : all_executors)
|
||||
for (auto const &hosted : ex->cfg.hosted_actor())
|
||||
if (hosted == "*" || boost::algorithm::to_lower_copy(hosted) ==
|
||||
boost::algorithm::to_lower_copy(actor_name))
|
||||
return at.get();
|
||||
boost::algorithm::to_lower_copy(actor_name))
|
||||
return ex.get();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -126,8 +110,8 @@ OrderServiceServer::OrderServiceServer(
|
||||
me->publish_fills = make_fills_publisher();
|
||||
|
||||
std::vector<mercury::Executor*> all_executors;
|
||||
for (auto const &thread_cfg : config::get<config::OrdermanCfg>().thread()) {
|
||||
auto at = std::make_unique<ActorThread>(thread_cfg,stats);
|
||||
for (auto const &ex_cfg : config::get<config::OrdermanCfg>().executor()) {
|
||||
auto at = std::make_unique<ActorThread>(ex_cfg,stats);
|
||||
all_executors.push_back(&at->executor);
|
||||
me->actor_threads.push_back(std::move(at));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user