Added some performance metrics to server.

This commit is contained in:
Pedro Pinto committed 2018-08-29 15:48:28 +00:00
1 parent 6a6e1b1139
commit 353a33a391
4 files changed
+51 -18

No files matched your search

+29 -14
View File
@@ -3,10 +3,11 @@
#include "lib/api/services/AdminService.client.pb.h"
#include "lib/config/config.h"
#include "lib/config/protos/jetfix.pb.h"
#include "lib/utils/bts_chrono.h"
#include "lib/md/MDConsumer.h"
#include "lib/mercury/actors/Timer.h"
#include "lib/mercury/broker/AsyncEventBroker.h"
#include "lib/mercury/mercury_utils/Executor.h"
#include "lib/metrics/metrics.h"
#include "lib/orderman/actors/AsyncFactory.h"
#include "lib/orderman/actors/ExecutionGateway.h"
#include "lib/orderman/actors/FillStore.h"
@@ -15,20 +16,22 @@
#include "lib/orderman/actors/SecuritySrc.h"
#include "lib/orderman/actors/ServiceBridge.h"
#include "lib/orderman/actors/order_manager/OrderManager.h"
#include "lib/md/MDConsumer.h"
#include "lib/utils/bts_chrono.h"
namespace bts {
namespace orderman {
struct OrderServiceServer::PImpl {
PImpl(bts::api::ServiceContext &ctx, std::shared_ptr<api::ISyntheticSecurityService>& ss)
PImpl(bts::api::ServiceContext &ctx,
std::shared_ptr<api::ISyntheticSecurityService> &ss,
metrics::MetricsContainer &stats)
: fast_broker(std::make_shared<mercury::AsyncEventBroker>()),
slow_broker(std::make_shared<mercury::AsyncEventBroker>()),
service_bridge(), fast_exe(*fast_broker), slow_exe(*slow_broker),
fast_thread(), slow_thread(), service_ready(false), known_orders(),
known_fills(), publish_orders(), publish_fills(),
admin_service(ctx.locate<api::admin::AdminService>()),
md_consumer(ss) {}
admin_service(ctx.locate<api::admin::AdminService>()), md_consumer(ss),
stats(stats) {}
std::shared_ptr<mercury::AsyncEventBroker> fast_broker;
std::shared_ptr<mercury::AsyncEventBroker> slow_broker;
@@ -45,12 +48,14 @@ struct OrderServiceServer::PImpl {
OrderServiceServer::FillsPublisher publish_fills;
api::admin::AdminService admin_service;
bts::md::MDConsumer md_consumer;
metrics::MetricsContainer &stats;
};
OrderServiceServer::OrderServiceServer(
bts::api::ServiceContext &ctx,
std::shared_ptr<api::ISyntheticSecurityService> &ss)
: api::orderman::OrderServiceBase(ctx), me(new PImpl(ctx, ss)) {
std::shared_ptr<api::ISyntheticSecurityService> &ss,
metrics::MetricsContainer &stats)
: api::orderman::OrderServiceBase(ctx), me(new PImpl(ctx, ss, stats)) {
me->publish_orders = make_orders_publisher();
me->publish_fills = make_fills_publisher();
@@ -70,7 +75,7 @@ OrderServiceServer::OrderServiceServer(
me->slow_broker->init_neighbours({me->fast_broker});
// fast actors
me->fast_exe.spawn<MDSource>(me->md_consumer);
me->fast_exe.spawn<MDSource>(me->md_consumer,me->stats);
me->fast_exe.spawn<OrderManager>();
auto &all_connections = config::get<config::JetFIX>().connection();
@@ -79,8 +84,18 @@ OrderServiceServer::OrderServiceServer(
me->fast_thread = std::thread([this]() {
os::set_thread_name("fast_exe");
for (;;)
auto loop_timer =
std::make_shared < metrics::HistogramMetric<16>>(
"spark_metrics_fast_thread_loop",
std::array<double, 16>({2, 4, 8, 16, 32, 64,
128, 256, 512, 1024,2048,4096,8192,16384}));
me->stats.publish(loop_timer);
for (;;) {
auto start = Timer::now();
me->fast_exe.do_work();
auto stop = Timer::now();
loop_timer->observe(us_diff(stop,start));
}
});
// slow actors
@@ -99,13 +114,13 @@ OrderServiceServer::OrderServiceServer(
// wait for the service bridge to be ready
me->service_bridge->block_until_ready();
// subscribe to admin model updates and forward them to the service bridge
me->admin_service.subscribe_admin_data() |
rxcpp::operators::subscribe<api::admin::Admin_dataUpdate>(
[this](auto const &update) {
bts_assert(update.all().size() == 1);
me->service_bridge->update_admin_data(update.all()[0]);
bts_assert(update.all().size() == 1);
me->service_bridge->update_admin_data(update.all()[0]);
});
}
@@ -206,5 +221,5 @@ void OrderServiceServer::crack_order(
response = me->service_bridge->crack_order(crack);
r(response);
}
}
}
} // namespace orderman
} // namespace bts