0

ZeroMQ with czmq is displaying some worrying performance. Timed results differ by a factor of almost 20. Specifically, in the following example, test times range from about 7ms up to 150ms!?

Based on the provided czmq "grassland" [1] test examples, I'm sending a string like abcdefghijklmnopqrstuvwxyz 1000x to the consumer.

Anyone know why this might be?

Minimal, complete, and verifiable example

Based on the grasslands example. Producer and consumer broken into separate files/processes.

Subject

#include <czmq.h>
#include <sys/time.h>
#include <string>
#include <iostream>

int main (void)
{
    struct timeval start, end;

    //  Create and bind server socket
    zsock_t *server = zsock_new (ZMQ_PUSH);
    zsock_set_linger(server, 10000);
    zsock_bind (server, "tcp://*:9000");
    // Set the string to send
    const std::string s = "abcdefghijklmnopqrstuvwxyz";

    // Timestamp start, send 1000x, timetamp end.
    gettimeofday(&start, NULL);
    for (int i=0; i<1000; ++i) {
        zstr_send (server, s.c_str());
    }
    gettimeofday(&end, NULL);

    printf("%06ld\n", (long) start.tv_usec);
    printf("%06ld\n", (long) end.tv_usec);

    zsock_destroy (&server);
    return 0;
}

Observer

#include <czmq.h>
#include <stdio.h>

int main (void)
{
    zsock_t *client = zsock_new (ZMQ_PULL);
    zsock_connect (client, "tcp://127.0.0.1:9000");

    while(1) {
        char *message = zstr_recv (client);
        printf("%s\n", message);
        free (message);
    }

    zsock_destroy (&client);
    return 0;
}

Five Runs

$ pub
745709
868642

$ pub
487869
643882

$ pub
564730
572683

$ pub
865532
873030

$ pub
356007
500260

References

  1. https://github.com/zeromq/czmq/tree/master/examples/security
kmiklas
  • 13,085
  • 22
  • 67
  • 103
  • regarding: `const std::string s = "abcdefghijklmnopqrstuvwxyz";` this is C++, not C. Please remove the `c` tag from your question – user3629249 Jun 12 '20 at 16:32
  • @user3629249 C still applies, as both the test and MQ libraries are in C. I compiled the test as C++ to leverage the ``std:string`` class. – kmiklas Jun 12 '20 at 16:41
  • It does not matter what language the libraries are written in. (so long as the associated header files have the appropriate check for `cplusplus`. – user3629249 Jun 12 '20 at 16:48

0 Answers0