[zeromq-dev] zmq cpp performance compared to the latency reported by `qperf`

Doron Somech somdoron at gmail.com
Sun Dec 2 13:42:04 CET 2018

This is known, when you do request-response measure, because of zeromq
internal thread signaling. Actually on high load you will get better
results. ZeroMQ excel at high number of messages and asynchronous
communication pattern.

In case of request-response between client and server you will still enjoy
the benefits on the server side if you use a router and answer requests
asynchronously. However, if you do pure request-response, zeromq add some

On Nov 28, 2018 02:53, "Ernest Zed" <kreuzerkrieg at gmail.com> wrote:

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);

while (true) {
    zmq::message_t request;

    //  Wait for next request from client

    //  Send reply back to client
    zmq::message_t reply(5);
    memcpy(reply.data(), "World", 5);

The ZMQ client

zmq::context_t context;
zmq::socket_t socket(context, ZMQ_REQ);

std::cout << "Connecting to hello world server…" << std::endl;
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();
    //  Get the reply.
    socket.recv(&reply);}auto end =
std::chrono::high_resolution_clock::now();auto us =
std::chrono::duration_cast<std::chrono::microseconds>(end -
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


zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20181202/ccd4cdd3/attachment.htm>

More information about the zeromq-dev mailing list