OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
TCPStandardBenchmark.cpp File Reference

Go to the source code of this file.

Functions

int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 42 of file TCPStandardBenchmark.cpp.

43{
44 // `--help` to show options.
45 const AppConfiguration<
52 > cfg{"TCPStandardBenchmark", argc, argv};
53
54 int result = 0;
55 try
56 {
57 const auto numberOfMessages = cfg.numberOfMessages();
58 const auto warmupInterval = cfg.warmupInterval();
59 const auto intervalBetweenSending = (std::max)(cfg.intervalBetweenSending(), warmupInterval);
60 const auto storageType = cfg.storage();
61
62 ThisThread::affinity(cfg.mainThreadCpu());
64
65 auto settings = fillSettings(cfg);
66 const auto emulator = createEmulator(settings, cfg);
67
68 // Request Binary Order Gateway credentials from Binary Utility Service Gateway.
69 const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
70
71 settings
72 .receiveSpinningTimeout(1000 * 1000)
73 .useSpinLock(true)
74 .logBeforeSending(false)
75 .threadingModel(ThreadingModel::External);
76
77 printBenchmarkSettings(std::clog, numberOfMessages, intervalBetweenSending, warmupInterval, storageType);
78
79 const auto guard = setPriorityAndPolicy();
80
81 TcpStandardStack stack;
82
83 ReactorBenchmarkListener listener{numberOfMessages};
84 listener.measureOverhead();
85
86 try
87 {
88 const auto bgwSession = std::make_unique<BgwSession>(stack, settings, &listener, cfg.storage());
89
90 const auto connected = bgwSession->connectAsync(bgwCredentials);
91
92 while(!connected.is_ready())
93 stack.dispatchEvents();
94
95 if(connected.has_exception())
96 connected.get();
97
98 auto order = Helper::createOrder(cfg.traderId());
99
100 std::clog << "\nWarm-up phase to make first calls faster..." << std::endl;
101
103 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
104
105 if(listener.receivedAllMessages())
106 {
107 std::clog << "\nMeasurement phase..." << std::endl;
108
110 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
111 }
112
113 const auto disconnected = bgwSession->disconnectAsync();
114
115 while(!disconnected.is_ready())
116 stack.dispatchEvents();
117
118 if(disconnected.has_exception())
119 disconnected.get();
120 }
121 catch(const std::exception& ex)
122 {
123 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
124 result = 1;
125 }
126
127 while(!stack.isQuiescent())
128 stack.dispatchEvents();
129
130 if(listener.receivedAllMessages())
131 {
132 if(listener.packetGroupingDetected())
133 std::clog << "Attention: packet grouping detected! Increase the interval between sending!" << std::endl;
134
135 BenchmarkData::reportResults("Latency", listener.sendMarks(), listener.receiveMarks(), numberOfMessages, listener.overhead());
136 }
137 }
138 catch (const std::exception& ex)
139 {
140 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
141 result = 1;
142 }
143
144 return result;
145}
const BenchmarkData::SendMarks * sendMarks() const noexcept
const BenchmarkData::ReceiveMarks * receiveMarks() const noexcept
const BenchmarkData::Overhead & overhead() const noexcept
bool packetGroupingDetected() const noexcept
A high-level wrapper over the TCP standard stack.
ONIXS_ICEBOE_FORCEINLINE void dispatchEvents() override
Processes events on a stack and performs the necessary handling.
ONIXS_ICEBOE_FORCEINLINE bool isQuiescent() const override
static void affinity(const CpuIndexes &cpuIndexes)
Sets the processor affinity mask for the current thread. The thread is rescheduled after this call.
bool receivedAllMessages() const noexcept
void collectSessionTimeMarks(Stack &stack, Session &session, MessageHolder< NewOrderRequest > &order, size_t numberOfMessages, size_t sendPeriod, size_t warmupPeriod)
static MessageHolder< NewOrderRequest > createOrder(const std::string &traderId)
Definition Helpers.h:104
std::shared_ptr< void > setPriorityAndPolicy(Session *session=nullptr)
Definition Helpers.h:150
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
Definition Emulator.h:157
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
Definition Listener.h:264
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
Definition Settings.h:32
void printBenchmarkSettings(std::ostream &o, size_t numberOfMessages, size_t intervalBetweenSending, size_t warmupInterval, SessionStorageType::Enum storageType)
Definition Helpers.h:182
static void reportResults(const std::string &name, const SendMarks *sendMarksArray, const ReceiveMarks *receiveMarksArray, std::size_t count, const Overhead &overhead)
@ External
Session events are handled by rolling an event loop in a user thread.
static void manageSignals() noexcept
Definition Signal.h:46