SPARK-2197 Add some MBO stats logged every 5 minutes
This commit is contained in:
1 parent
c923be6ced
commit
71d2e01187
3 files changed
+64
-3
No files matched your search
@@ -34,4 +34,8 @@ message SoundNotifications {
|
||||
|
||||
message VolumeAtPrice{
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
|
||||
message MBOStats {
|
||||
optional bool enabled = 1 [default = true];
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
#include "MBOProcessor.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/ConcurrentPool.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/toggles.pb.h"
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include <tbb/concurrent_hash_map.h>
|
||||
|
||||
@@ -20,11 +24,50 @@ struct SecurityKeyHashCompare {
|
||||
}
|
||||
};
|
||||
|
||||
void print_pool_stats(const utils::ConcurrentPool<MBOSnapshot>& pool) {
|
||||
size_t count = 0;
|
||||
std::vector<int> bid_sz,ask_sz;
|
||||
pool.unsafe_iterate([&](const MBOSnapshot& s) {
|
||||
if (s.bids.size() > 0 || s.asks.size() > 0) {
|
||||
count++;
|
||||
bid_sz.push_back(s.bids.size());
|
||||
ask_sz.push_back(s.asks.size());
|
||||
}
|
||||
});
|
||||
|
||||
std::sort(bid_sz.begin(), bid_sz.end());
|
||||
std::sort(ask_sz.begin(), ask_sz.end());
|
||||
size_t bid_tot =0, ask_tot = 0;
|
||||
for(size_t i : bid_sz) { bid_tot += i; }
|
||||
for(size_t i : ask_sz) { ask_tot += i; }
|
||||
|
||||
std::stringstream bid_percentiles, ask_percentiles;
|
||||
for (double x : { 0.5, 0.75, 0.9, 0.95, 0.99 }) {
|
||||
size_t index = count * x;
|
||||
bid_percentiles << bid_sz[index] << " ";
|
||||
ask_percentiles << ask_sz[index] << " ";
|
||||
}
|
||||
bid_percentiles << bid_sz[count-1] << " ";
|
||||
ask_percentiles << ask_sz[count-1] << " ";
|
||||
LOG(md,Info,
|
||||
"MBO statistics: count: {} - %[50,75,90,95,99,100] bid: [{}] - ask: [{}]",
|
||||
count, bid_percentiles.str(), ask_percentiles.str());
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_hash_map<SecurityKey, MBOSnapshot*, SecurityKeyHashCompare> MapType;
|
||||
struct MBOProcessorImpl {
|
||||
utils::ConcurrentPool<MBOSnapshot> pool;
|
||||
MapType snapshots;
|
||||
MBOProcessorImpl() : pool(2048,512), snapshots() {}
|
||||
utils::DispatcherTimer timer;
|
||||
MBOProcessorImpl() :
|
||||
pool(2048,512),
|
||||
snapshots(),
|
||||
timer(utils::Dispatcher::background(), 600*1000, [&]() { print_pool_stats(pool); })
|
||||
{
|
||||
if (config::get<config::toggles::MBOStats>().enabled()) {
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
|
||||
@@ -10,11 +10,12 @@ template <class T>
|
||||
class ConcurrentPool {
|
||||
tbb::concurrent_vector<std::unique_ptr<T[]>> _all;
|
||||
tbb::concurrent_queue<T*> _free;
|
||||
size_t _initial_size;
|
||||
size_t _grow_size;
|
||||
std::atomic<size_t> _outstanding;
|
||||
size_t _outstanding;
|
||||
public:
|
||||
ConcurrentPool(size_t initial_size=256, size_t grow_size=32):
|
||||
_all(), _free(), _grow_size(grow_size), _outstanding(0) {
|
||||
_all(), _free(), _initial_size(initial_size), _grow_size(grow_size), _outstanding(0) {
|
||||
reserve(initial_size);
|
||||
}
|
||||
|
||||
@@ -34,6 +35,7 @@ class ConcurrentPool {
|
||||
|
||||
void reserve(size_t count) {
|
||||
std::unique_ptr<T[]> buffer {new T[count]};
|
||||
_outstanding += count;
|
||||
for (size_t x = 0; x < count; ++x) {
|
||||
T* temp = &buffer[x];
|
||||
release(&temp);
|
||||
@@ -50,6 +52,18 @@ class ConcurrentPool {
|
||||
}
|
||||
}
|
||||
|
||||
template <class CB>
|
||||
void unsafe_iterate(CB cb) const {
|
||||
for (auto iter = _all.begin(); iter != _all.end(); ++iter) {
|
||||
size_t size = (iter == _all.begin()) ? _initial_size : _grow_size;
|
||||
for (size_t x = 0; x < size; ++x) {
|
||||
const std::unique_ptr<T[]>& bucket = *iter;
|
||||
const T* start = bucket.get();
|
||||
cb(start[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}} //namespace
|
||||
Reference in new issue
Block a user