Corrected channel in correlation id.

This commit is contained in:
Pedro Pinto committed 2018-12-05 23:31:26 +00:00
1 parent 9cb619d374
commit 8cfca8e40e
3 files changed
+64 -18

No files matched your search

+8 -2
View File
@@ -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) {
+31 -10
View File
@@ -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<double, 30> 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<BookSide>(),
&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<HandleRecord> _handles;
@@ -105,6 +125,7 @@ class MDSource : public mercury::Actor, public mercury::IPollableActor {
trace::PerfLog &_perf_log;
metrics::MetricsContainer &_stats;
std::shared_ptr<metrics::HistogramMetric<30>> _loop_timer;
std::map<md::UserSymbol, std::string> _symbol_to_channel;
};
} // namespace orderman
} // namespace bts
@@ -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<BookUpdateEvent>::SubID;
template <class CB> BookSubID subscribe_to_book(SecurityKey k, CB &&cb) {
return _book_updates.sub(k, std::forward<CB>(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<SettlementUpdateEvent>::SubID;
template <class CB>
SettlementSubID subscribe_to_settlements(SecurityKey k, CB &&cb) {
return _settlement_updates.sub(k, std::forward<CB>(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 <class CB> void subscribe_to_time(CB &&cb) {
_time_change_sub = _time_change.sub(std::forward<CB>(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 <class EV, class C> 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 <class C> void on_inter_order_call(C const &c) {
if (_busy)
_pending_calls.emplace_back(c);