ZeroMQ with czmq showing wild swings in performance tests

126 views Asked by At

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
0

There are 0 answers