[zeromq-dev] zmq cpp performance compared to the latency reported by `qperf`
Ernest Zed
kreuzerkrieg at gmail.com
Wed Nov 28 01:50:05 CET 2018
I'm trying to figure out why the qperf reports latency (one way) x and
REQ/REP (roundtrip) reports something like 4x. Any particular socket
tweaking I have to do? Because if I just open socket, set TCP_NODELAY
(which set in ZMQ by default) I get latency very close (for 1k buffers) to
the number reported by qperf. However the ZMQ is lagging behind these
numbers about 4-5 times
The ZMQ server
zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
while (true) {
zmq::message_t request;
// Wait for next request from client
socket.recv(&request);
// Send reply back to client
zmq::message_t reply(5);
memcpy(reply.data(), "World", 5);
socket.send(reply);}
The ZMQ client
zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REQ);
std::cout << "Connecting to hello world server…" << std::endl;
socket.connect("tcp://my.host:5555");
const size_t cycles = 100'000;double throughput = 0;
zmq::message_t reply;
auto start = std::chrono::high_resolution_clock::now();vector<uint8_t>
buff(MessageSize, 0);for (auto i = 0ul; i < cycles; ++i) {
zmq::message_t request(MessageSize);
memcpy(request.data(), buff.data(), MessageSize);
throughput += request.size();
socket.send(request);
// Get the reply.
socket.recv(&reply);}auto end =
std::chrono::high_resolution_clock::now();auto us =
std::chrono::duration_cast<std::chrono::microseconds>(end -
start).count();
std::cout << "Latency: " << us / cycles << "us." << std::endl;
std::cout << "Througput: " << std::fixed << throughput / us *
1'000'000 / 1024 / 1024 << "MiB/s." << std::endl;
Both are essentially ZMQ examples provided here
http://zguide.zeromq.org/cpp:hwclient Some background, Linux, Ubuntu 18.04,
GCC 7.3, static library provided by vcpkg, built locally, looks like they
pull the master from GitHub.
Original question on stack overflow
https://stackoverflow.com/questions/53506353/zmq-cpp-performance-compared-to-the-latency-reported-by-qperf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20181128/d4a2e467/attachment.htm>
More information about the zeromq-dev
mailing list