44{
45
54 > cfg{"TCPDirectBenchmark", argc, argv};
55
56 int result = 0;
57 try
58 {
59 const auto numberOfMessages = cfg.numberOfMessages();
60 const auto warmupInterval = cfg.warmupInterval();
61 const auto intervalBetweenSending = (std::max)(cfg.intervalBetweenSending(), warmupInterval);
62 const auto storageType = cfg.storage();
63
66
69
70
72
73 settings
74 .receiveSpinningTimeout(1000 * 1000)
75 .useSpinLock(true)
76 .logBeforeSending(false)
78
80
82
84
85
86
87 attr.
set(
"interface", cfg.nif());
88
90
93
94 try
95 {
96 const auto bgwSession = std::make_unique<BgwSession>(stack, settings, &listener, cfg.storage());
97
98 const auto connected = bgwSession->connectAsync(bgwCredentials);
99
100 while(!connected.is_ready())
102
103 if(connected.has_exception())
104 connected.get();
105
107
108 std::clog << "\nWarm-up phase to make first calls faster..." << std::endl;
109
111 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
112
114 {
115 std::clog << "\nMeasurement phase..." << std::endl;
116
118 stack, *bgwSession, order, numberOfMessages, intervalBetweenSending, warmupInterval);
119 }
120
121 const auto disconnected = bgwSession->disconnectAsync();
122
123 while(!disconnected.is_ready())
125
126 if(disconnected.has_exception())
127 disconnected.get();
128 }
129 catch(const std::exception& ex)
130 {
131 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
132 result = 1;
133 }
134
137
139 {
141 std::clog << "Attention: packet grouping detected! Increase the interval between sending!" << std::endl;
142
144 }
145 }
146 catch (const std::exception& ex)
147 {
148 std::cerr << "\nEXCEPTION: " << ex.what() << std::endl;
149 result = 1;
150 }
151
152 return result;
153}
const BenchmarkData::SendMarks * sendMarks() const noexcept
const BenchmarkData::ReceiveMarks * receiveMarks() const noexcept
const BenchmarkData::Overhead & overhead() const noexcept
bool packetGroupingDetected() const noexcept
TCPDirect Attributes to pass configuration details (a wrapper around the zf_attr struct).
void set(const std::string &name, const std::string &value)
Sets the attribute to the given value.
A high-level wrapper over the TCPDirect network stack.
bool isQuiescent() const noexcept override
void dispatchEvents() noexcept override
This function processes events on a stack and performs the necessary handling.
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)
std::shared_ptr< void > setPriorityAndPolicy(Session *session=nullptr)
std::pair< std::unique_ptr< GatewayEmulatorThread< BusSessionGatewayListener > >, std::unique_ptr< GatewayEmulatorThread< GatewayListener > > > createEmulator(const SessionSettings &settings, const ConnectivityConfiguration &cfg, bool tcpDirect=false)
BgwCredentials receiveBgwCredentials(SessionSettings settings, std::string host, Port port)
SessionSettings fillSettings(const LogonConfiguration &logonCfg, const ConnectivityConfiguration &connCfg, const SettingsConfiguration &settingsCfg)
void printBenchmarkSettings(std::ostream &o, size_t numberOfMessages, size_t intervalBetweenSending, size_t warmupInterval, SessionStorageType::Enum storageType)
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