OnixS C++ ICE Binary Order Entry Handler 1.2.3
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 43 of file TCPStandardBenchmark.cpp.

44{
45 // `--help` to show options.
46 const AppConfiguration<
53 > cfg{"TCPStandardBenchmark", argc, argv};
54
55 int result = 0;
56 try
57 {
58 const auto numberOfMessages = cfg.numberOfMessages();
59 const auto warmupInterval = cfg.warmupInterval();
60 const auto intervalBetweenSending = (std::max)(cfg.intervalBetweenSending(), warmupInterval);
61 const auto storageType = cfg.storage();
62
63 ThisThread::affinity(cfg.mainThreadCpu());
65
66 auto settings = fillSettings(cfg);
67 const auto emulator = createEmulator(settings, cfg);
68
69 // Request Binary Order Gateway credentials from Binary Utility Service Gateway.
70 const auto bgwCredentials = receiveBgwCredentials(settings, cfg.host(), cfg.port());
71
72 settings
73 .receiveSpinningTimeout(1000 * 1000)
74 .useSpinLock(true)
75 .logBeforeSending(false)
76 .threadingModel(ThreadingModel::External);
77
78 printBenchmarkSettings(std::clog, numberOfMessages, intervalBetweenSending, warmupInterval, storageType);
79
80 const auto guard = setPriorityAndPolicy();
81
82 TcpStandardStack stack;
83
84 ReactorBenchmarkListener listener{numberOfMessages};
85 listener.measureOverhead();
86
87 try
88 {
89 const auto bgwSession = makeUnique<BgwSession>(stack, settings, &listener, cfg.storage());
90
91 const auto connected = bgwSession->connectAsync(bgwCredentials);
92
93 while(!connected.is_ready())
94 stack.dispatchEvents();
95
96 if(connected.has_exception())
97 connected.get();
98
99 auto order = Helper::createOrder(cfg.traderId());
100
101 std::clog << "\nWarm-up phase to make first calls faster..." << std::endl;
102
104 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
105
106 if(listener.receivedAllMessages())
107 {
108 std::clog << "\nMeasurement phase..." << std::endl;
109
111 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
112 }
113
114 const auto disconnected = bgwSession->disconnectAsync();
115
116 while(!disconnected.is_ready())
117 stack.dispatchEvents();
118
119 if(disconnected.has_exception())
120 disconnected.get();
121 }
122 catch(const std::exception& ex)
123 {
124 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
125 result = 1;
126 }
127
128 while(!stack.isQuiescent())
129 stack.dispatchEvents();
130
131 if(listener.receivedAllMessages())
132 {
133 if(listener.packetGroupingDetected())
134 std::clog << "Attention: packet grouping detected! Increase the interval between sending!" << std::endl;
135
136 BenchmarkData::reportResults("Latency", listener.sendMarks(), listener.receiveMarks(), numberOfMessages, listener.overhead());
137 }
138 }
139 catch (const std::exception& ex)
140 {
141 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
142 result = 1;
143 }
144
145 return result;
146}
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:159
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
Definition Listener.h:265
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
std::unique_ptr< T > makeUnique(Args &&...args)
Definition Tools.h:30
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