From 8cfca8e40ef011bbf1708c470ed29fc029f2d2b3 Mon Sep 17 00:00:00 2001 From: Pedro Pinto Date: Wed, 5 Dec 2018 23:31:26 +0000 Subject: [PATCH] Corrected channel in correlation id. --- src/lib/jetfix/connection/AsyncReader.cpp | 10 ++++- src/lib/orderman/actors/MDSource.h | 41 ++++++++++++++----- .../actors/order_manager/OrderServices.h | 31 +++++++++++--- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/lib/jetfix/connection/AsyncReader.cpp b/src/lib/jetfix/connection/AsyncReader.cpp index 93129e2d0..1b564bb3c 100644 --- a/src/lib/jetfix/connection/AsyncReader.cpp +++ b/src/lib/jetfix/connection/AsyncReader.cpp @@ -84,7 +84,8 @@ struct AsyncReader::PImpl sink (sink), perf_log(l), high_water_mark (high_water_mark), - connection_name(connection_name) + connection_name(connection_name), + channel(new std::string(connection_name)) {} // abstraction for source of raw bytes @@ -106,6 +107,11 @@ struct AsyncReader::PImpl // need to increase the buffer size uint32_t high_water_mark; const std::string connection_name; + + // we leak this because we do not have a good way to pass a pointer + // to the perf_log object and guarantee that pointer is valid by + // the time the string is written to disk + const std::string *channel; }; AsyncReader::AsyncReader (IConnection &connection, @@ -144,7 +150,7 @@ void AsyncReader::dispatch () auto read_count = me->connection.read (cursor (),free_bytes ()); auto read_time = utils::TimeStamp::now(); trace::CorID trace; - trace.channel = "fix"; + trace.channel = me->channel->c_str(); // signal a disconnect if the connection broke if (read_count <= 0) { diff --git a/src/lib/orderman/actors/MDSource.h b/src/lib/orderman/actors/MDSource.h index 83f58a387..03a527495 100644 --- a/src/lib/orderman/actors/MDSource.h +++ b/src/lib/orderman/actors/MDSource.h @@ -3,14 +3,15 @@ #include "lib/logging/logging.h" #include "lib/md/MDConsumer.h" #include "lib/md/MDConsumerHandle.h" +#include "lib/md/cme/MDP3Utils.h" #include "lib/mercury/actors/Actor.h" #include "lib/mercury/actors/IPollableActor.h" #include "lib/mercury/events/TimerEvent.h" #include "lib/orderman/events/BookUpdateEvent.h" #include "lib/orderman/events/MDRequestEvent.h" +#include "lib/tracing/PerfLog.h" #include "lib/tracing/bts_trace.h" #include "lib/utils/TimeStamp.h" -#include "lib/tracing/PerfLog.h" namespace bts { namespace orderman { @@ -22,11 +23,23 @@ namespace orderman { class MDSource : public mercury::Actor, public mercury::IPollableActor { public: - MDSource(md::MDConsumer &consumer, metrics::MetricsContainer &stats, trace::PerfLog &log) - : _handles(), _md_consumer(consumer), _book_update(), _perf_log(log),_stats(stats), _loop_timer() {} + MDSource(md::MDConsumer &consumer, metrics::MetricsContainer &stats, + trace::PerfLog &log) + : _handles(), _md_consumer(consumer), _book_update(), _perf_log(log), + _stats(stats), _loop_timer() { + + auto cme_channels = md::get_configured_cme_channels(); + for (auto const &c : cme_channels) + for (auto const &s : c.symbols) + _symbol_to_channel[s] = c.id; + } + void init() override { LOG(OrderMan, Warn, "Starting MDSource actor"); - bts_assert_msg(_md_consumer.all_heartbeats_ok(), "Marketdata heartbeats are bad. MDConsumer will not recover from this condition. Please run 'sparkd md cleanup' and restart sparkd"); + bts_assert_msg( + _md_consumer.all_heartbeats_ok(), + "Marketdata heartbeats are bad. MDConsumer will not recover from " + "this condition. Please run 'sparkd md cleanup' and restart sparkd"); std::array buckets; auto i = 1; @@ -64,7 +77,13 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor { LOG(OrderMan, Warn, "Starting to publish book updates for security key: {}", k); auto handle = _md_consumer.get_handle(k); - _handles.push_back({utils::TimeStamp(), handle}); + + auto &channel = _symbol_to_channel[handle.get_usersymbol()]; + if (channel.empty()) + channel = "sim"; + + _handles.push_back( + {utils::TimeStamp(), handle, channel.c_str()}); if (handle.is_synthetic()) { synthetic_count_metric->increment(); } @@ -82,21 +101,22 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor { for (auto &h : _handles) { auto &handle = h.handle; if (handle.get_book(h.last, std::tuple_size(), - &book.bid()[0], &book.ask()[0]) == - md::HandleReadResult::SUCCESS) { + &book.bid()[0], + &book.ask()[0]) == md::HandleReadResult::SUCCESS) { book._security_key = SecurityKey(handle.key()); - trace::CorID trace {"md",handle.sequence()}; - _perf_log.log(trace,h.last,"md",handle.key()); + trace::CorID trace{h.channel, handle.sequence()}; + _perf_log.log(trace, h.last, "md", handle.key()); publish(_book_update, book, trace); } } auto stop = utils::TimeStamp::now(); - _loop_timer->observe((start-stop).nanoseconds()); + _loop_timer->observe((start - stop).nanoseconds()); } struct HandleRecord { utils::TimeStamp last; md::MDConsumerHandle handle; + const char *channel; }; std::vector _handles; @@ -105,6 +125,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor { trace::PerfLog &_perf_log; metrics::MetricsContainer &_stats; std::shared_ptr> _loop_timer; + std::map _symbol_to_channel; }; } // namespace orderman } // namespace bts diff --git a/src/lib/orderman/actors/order_manager/OrderServices.h b/src/lib/orderman/actors/order_manager/OrderServices.h index d80f5c274..74c098a36 100644 --- a/src/lib/orderman/actors/order_manager/OrderServices.h +++ b/src/lib/orderman/actors/order_manager/OrderServices.h @@ -134,7 +134,7 @@ class OrderServices { void log(trace::CorID cid, const char *entry_kind, uint32_t uint32_1 = 0, uint32_t uint32_2 = 0, const char *txt_1 = "", uint64_t uint64_1 = 0) { - _data->log.log(cid,entry_kind,uint32_1,uint32_2,txt_1,uint64_1); + _data->log.log(cid, entry_kind, uint32_1, uint32_2, txt_1, uint64_1); } void report_state(const api::orderman::OrderState &state, @@ -154,9 +154,9 @@ class OrderServices { self._book_updates.unsub_all(); self._settlement_updates.unsub_all(); self._time_change.unsub_all(); - self._create_order_reply.unsub_all(); + self._create_order_reply.unsub_all(); } - if (self._parent) + if (self._parent) self._parent->_child_update_cb(ev); }); } @@ -173,21 +173,28 @@ class OrderServices { // Subscriptions ------------------------------ using BookSubID = EventStream::SubID; template BookSubID subscribe_to_book(SecurityKey k, CB &&cb) { - return _book_updates.sub(k, std::forward(cb)); + return _book_updates.sub(k, [this,cb] (auto const &ev) { + this->on_external_event(ev,cb); + }); } + void unsubscribe_from_book(BookSubID sid) { _book_updates.unsub(sid); } using SettlementSubID = EventStream::SubID; template SettlementSubID subscribe_to_settlements(SecurityKey k, CB &&cb) { - return _settlement_updates.sub(k, std::forward(cb)); + return _settlement_updates.sub(k, [this,cb] (auto const&ev) { + this->on_external_event(ev,cb); + }); } void unsubscribe_from_settlements(SettlementSubID sid) { _settlement_updates.unsub(sid); } template void subscribe_to_time(CB &&cb) { - _time_change_sub = _time_change.sub(std::forward(cb)); + _time_change_sub = _time_change.sub([this,cb] (auto const&ev) { + this->on_external_event(ev,cb); + }); } void unsubscribe_from_time() { _time_change.unsub(_time_change_sub); } @@ -202,6 +209,18 @@ class OrderServices { private: friend class OrderBuilder; + template void on_external_event(EV const &ev, C const &c) { + bts_assert(!_busy); + _busy = true; + c(ev); + for (size_t i = 0; i < _pending_calls.size(); i++) { + auto c = _pending_calls[i]; + c(*this); + } + _pending_calls.clear(); + _busy = false; + } + template void on_inter_order_call(C const &c) { if (_busy) _pending_calls.emplace_back(c);