Rewrite of mercury for better performance.
This commit is contained in:
1 parent
3005dfdc0f
commit
fa2a2e2107
60 files changed
+971
-1255
No files matched your search
@@ -1,21 +1,22 @@
|
||||
#include "Benchmark.h"
|
||||
#include "lib/api/services/OrderService.server.pb.h"
|
||||
#include "lib/jetfix/jetfix.h"
|
||||
#include "lib/md/PriceSize.h"
|
||||
#include "lib/mercury/common/FatWrapper.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/Puid.h"
|
||||
#include "lib/utils/SpinLock.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/Uuid.h"
|
||||
#include "server/sparkd/cmds/CmdRegistry.h"
|
||||
#include "lib/jetfix/jetfix.h"
|
||||
#include "lib/mercury/broker/CoreEventBroker.h"
|
||||
#include "lib/mercury/mercury_utils/FatWrapper.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/md/PriceSize.h"
|
||||
#include "lib/os/os.h"
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/lockfree/queue.hpp>
|
||||
#include <boost/lockfree/spsc_queue.hpp>
|
||||
|
||||
#include <boost/lockfree/stack.hpp>
|
||||
#include <boost/pool/object_pool.hpp>
|
||||
#include <boost/pool/pool.hpp>
|
||||
@@ -157,7 +158,7 @@ BENCHMARK(copy_perf_trace);
|
||||
// static void serialize_order(benchmark::State &state) {
|
||||
// auto order_state =
|
||||
// utils::pb::from_string<api::orderman::OrderState>(order_state_str);
|
||||
// auto
|
||||
// auto
|
||||
// auto order_state_cpy = order_state;
|
||||
// for (auto _ : state) {
|
||||
// order_state_cpy = order_state;
|
||||
@@ -173,23 +174,23 @@ static void serialize_update(benchmark::State &state) {
|
||||
|
||||
std::string buffer;
|
||||
buffer.resize(update.ByteSize());
|
||||
|
||||
|
||||
bts_assert(update.SerializeToArray(&buffer[0], buffer.size()));
|
||||
for (auto _ : state) {
|
||||
update.SerializeWithCachedSizesToArray((unsigned char*) &buffer[0]);
|
||||
update.SerializeWithCachedSizesToArray((unsigned char *)&buffer[0]);
|
||||
}
|
||||
}
|
||||
BENCHMARK(serialize_update);
|
||||
|
||||
static void serialize_order(benchmark::State &state) {
|
||||
auto order_state =
|
||||
utils::pb::from_string<api::orderman::OrderState>(order_state_str);
|
||||
utils::pb::from_string<api::orderman::OrderState>(order_state_str);
|
||||
|
||||
std::string buffer;
|
||||
buffer.resize(order_state.ByteSize());
|
||||
bts_assert(order_state.SerializeToArray(&buffer[0], buffer.size()));
|
||||
for (auto _ : state) {
|
||||
order_state.SerializeWithCachedSizesToArray((unsigned char*) &buffer[0]);
|
||||
for (auto _ : state) {
|
||||
order_state.SerializeWithCachedSizesToArray((unsigned char *)&buffer[0]);
|
||||
}
|
||||
}
|
||||
BENCHMARK(serialize_order);
|
||||
@@ -417,42 +418,6 @@ int Benchmark::execute(std::vector<std::string> const &args) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct Notify {
|
||||
mercury::EventBrokerID id;
|
||||
mercury::SubID suid;
|
||||
mercury::StreamID sid;
|
||||
utils::FatWrapper<80> payload;
|
||||
};
|
||||
|
||||
static void queue_notification(benchmark::State &state) {
|
||||
std::array<utils::FatWrapper<128>, 1> queue;
|
||||
for (auto _ : state) {
|
||||
auto &n = queue[0].wrap_in_place<Notify>();
|
||||
n.id = mercury::EventBrokerID(1);
|
||||
n.suid = mercury::SubID(1);
|
||||
n.sid = mercury::StreamID(1);
|
||||
auto &a = n.payload.wrap_in_place<A>();
|
||||
a.x = 1;
|
||||
benchmark::DoNotOptimize(queue[0].empty());
|
||||
}
|
||||
}
|
||||
BENCHMARK(queue_notification);
|
||||
|
||||
static void queue_notification2(benchmark::State &state) {
|
||||
std::array<utils::FatWrapper<128>, 2> queue;
|
||||
auto &n = queue[0].wrap_in_place<Notify>();
|
||||
n.id = mercury::EventBrokerID(1);
|
||||
n.suid = mercury::SubID(1);
|
||||
n.sid = mercury::StreamID(1);
|
||||
auto &a = n.payload.wrap_in_place<A>();
|
||||
a.x = 1;
|
||||
for (auto _ : state) {
|
||||
queue[1] = queue[0];
|
||||
benchmark::DoNotOptimize(queue[1].empty());
|
||||
}
|
||||
}
|
||||
BENCHMARK(queue_notification2);
|
||||
|
||||
static void boost_lockless_queue(benchmark::State &state) {
|
||||
using FreeList = boost::lockfree::queue<void *>;
|
||||
FreeList queue(1000000);
|
||||
@@ -465,7 +430,7 @@ static void boost_lockless_queue(benchmark::State &state) {
|
||||
BENCHMARK(boost_lockless_queue);
|
||||
|
||||
static void tbb_concurrent_queue(benchmark::State &state) {
|
||||
|
||||
|
||||
using FreeList = tbb::concurrent_queue<void *>;
|
||||
FreeList queue;
|
||||
for (auto _ : state) {
|
||||
@@ -489,26 +454,16 @@ static void moody_camel_queue(benchmark::State &state) {
|
||||
|
||||
BENCHMARK(moody_camel_queue);
|
||||
|
||||
static void moody_camel_fat_push(benchmark::State &state) {
|
||||
using Msg = utils::FatWrapper<80>;
|
||||
using Q = moodycamel::ConcurrentQueue<Msg>;
|
||||
Q queue;
|
||||
|
||||
Msg fw;
|
||||
auto &n = fw.wrap_in_place<Notify>();
|
||||
n.id = mercury::EventBrokerID(1);
|
||||
n.suid = mercury::SubID(1);
|
||||
n.sid = mercury::StreamID(1);
|
||||
auto &a = n.payload.wrap_in_place<A>();
|
||||
a.x = 1;
|
||||
static void boost_spsc(benchmark::State &state) {
|
||||
boost::lockfree::spsc_queue<int> q(10000);
|
||||
|
||||
int i = 0;
|
||||
for (auto _ : state) {
|
||||
queue.enqueue(fw);
|
||||
Msg fw2;
|
||||
benchmark::DoNotOptimize(queue.try_dequeue(fw2));
|
||||
q.push(++i);
|
||||
benchmark::DoNotOptimize(q.pop(i));
|
||||
}
|
||||
}
|
||||
BENCHMARK(moody_camel_fat_push);
|
||||
BENCHMARK(boost_spsc);
|
||||
|
||||
static void boost_lockless_stack(benchmark::State &state) {
|
||||
using FreeList = boost::lockfree::stack<void *>;
|
||||
@@ -521,7 +476,7 @@ static void boost_lockless_stack(benchmark::State &state) {
|
||||
}
|
||||
BENCHMARK(boost_lockless_stack);
|
||||
|
||||
using Msg = utils::FatWrapper<80>;
|
||||
using Msg = mercury::FatWrapper<80>;
|
||||
struct PPQueue {
|
||||
std::atomic_flag _mutex = ATOMIC_FLAG_INIT;
|
||||
std::vector<Msg *> v;
|
||||
@@ -546,130 +501,6 @@ struct PPQueue {
|
||||
}
|
||||
};
|
||||
|
||||
static void moody_camel_slim_push(benchmark::State &state) {
|
||||
using Q = moodycamel::ConcurrentQueue<Msg *>;
|
||||
Q queue;
|
||||
PPQueue store;
|
||||
store.v.reserve(10);
|
||||
|
||||
Msg fw;
|
||||
auto &n = fw.wrap_in_place<Notify>();
|
||||
n.id = mercury::EventBrokerID(1);
|
||||
n.suid = mercury::SubID(1);
|
||||
n.sid = mercury::StreamID(1);
|
||||
auto &a = n.payload.wrap_in_place<A>();
|
||||
a.x = 1;
|
||||
|
||||
store.push(&fw);
|
||||
|
||||
for (auto _ : state) {
|
||||
Msg *fw_ptr = nullptr;
|
||||
store.pop(&fw_ptr);
|
||||
auto &n = fw_ptr->wrap_in_place<Notify>();
|
||||
n.id = mercury::EventBrokerID(1);
|
||||
n.suid = mercury::SubID(1);
|
||||
n.sid = mercury::StreamID(1);
|
||||
auto &a = n.payload.wrap_in_place<A>();
|
||||
a.x = 1;
|
||||
queue.enqueue(fw_ptr);
|
||||
queue.try_dequeue(fw_ptr);
|
||||
store.push(fw_ptr);
|
||||
benchmark::DoNotOptimize(fw_ptr);
|
||||
}
|
||||
}
|
||||
BENCHMARK(moody_camel_slim_push);
|
||||
|
||||
using EventBrokerID = uint32_t;
|
||||
using StreamID = uint32_t;
|
||||
using SubID = uint32_t;
|
||||
using TopicPtr = std::shared_ptr<int>;
|
||||
using IEventBrokerPtr = TopicPtr;
|
||||
using TopicFilter = std::function<void()>;
|
||||
using InternalEventHandler = TopicFilter;
|
||||
using InternalSubID = uint32_t;
|
||||
|
||||
struct NeighbourAddition {
|
||||
NeighbourAddition() : ptr() {}
|
||||
IEventBrokerPtr ptr;
|
||||
};
|
||||
struct NeighbourRemoval {
|
||||
NeighbourRemoval() : id() {}
|
||||
EventBrokerID id;
|
||||
};
|
||||
|
||||
struct Advertisement {
|
||||
Advertisement() : id(), sid(), topic() {}
|
||||
EventBrokerID id;
|
||||
StreamID sid;
|
||||
TopicPtr topic;
|
||||
};
|
||||
|
||||
struct Unadvertisement {
|
||||
Unadvertisement() : id(), sid() {}
|
||||
EventBrokerID id;
|
||||
StreamID sid;
|
||||
};
|
||||
|
||||
struct Subscription {
|
||||
Subscription() : id(), suid(), sid() {}
|
||||
EventBrokerID id;
|
||||
SubID suid;
|
||||
StreamID sid;
|
||||
};
|
||||
|
||||
struct Unsubscription {
|
||||
Unsubscription() : id(), suid(), sid() {}
|
||||
EventBrokerID id;
|
||||
SubID suid;
|
||||
StreamID sid;
|
||||
};
|
||||
|
||||
struct InternalSubscription {
|
||||
InternalSubscription() : suid(), filter(), handler() {}
|
||||
InternalSubID suid;
|
||||
TopicFilter filter;
|
||||
InternalEventHandler handler;
|
||||
};
|
||||
|
||||
struct InternalUnsubscription {
|
||||
InternalUnsubscription() : suid() {}
|
||||
InternalSubID suid;
|
||||
};
|
||||
|
||||
template <class T> static void lambda_alloc_copy(benchmark::State &state) {
|
||||
utils::FatWrapper<128> fw;
|
||||
using Action = std::function<int()>;
|
||||
|
||||
T t;
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(
|
||||
fw.wrap_in_place<Action>([]() { return sizeof(T); }));
|
||||
}
|
||||
}
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, NeighbourAddition);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, NeighbourRemoval);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, Advertisement);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, Unadvertisement);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, Subscription);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, Unsubscription);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, InternalSubscription);
|
||||
BENCHMARK_TEMPLATE(lambda_alloc_copy, InternalUnsubscription);
|
||||
|
||||
template <class T> static void simple_alloc_copy(benchmark::State &state) {
|
||||
utils::FatWrapper<128> fw;
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(fw.wrap_in_place<T>());
|
||||
}
|
||||
}
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, NeighbourAddition);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, NeighbourRemoval);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, Advertisement);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, Unadvertisement);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, Subscription);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, Unsubscription);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, InternalSubscription);
|
||||
BENCHMARK_TEMPLATE(simple_alloc_copy, InternalUnsubscription);
|
||||
|
||||
static void get_thread_id(benchmark::State &state) {
|
||||
for (auto _ : state) {
|
||||
auto tid = std::this_thread::get_id();
|
||||
|
||||
Reference in new issue
Block a user