Question

I would like to use this library I found, it's a pure java port (not a wrapper) of zeromq. I am trying to test it and while it claims some good numbers, the test I am performing is giving rather poor results and it's even performed locally (client and serve on the same machine). I'm sure it's something I am doing wrong. It takes approx. 5 seconds to execute this 10.000 messages loop.

All I did is take the Hello world example and removed pause and sysouts. Here is the code:

The Server:

package guide;

import org.jeromq.ZMQ;

public class hwserver{
    public static void main(String[] args) throws Exception{

        //  Prepare our context and socket
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket socket = context.socket(ZMQ.REP);

        System.out.println("Binding hello world server");
        socket.bind ("tcp://*:5555");        

        while (true) {                  
            byte[] reply = socket.recv(0);
            String requestString = "Hello" ;
            byte[] request = requestString.getBytes();              
            socket.send(request, 0);            
        }              
    }
}

The Client:

package guide;

import org.jeromq.ZMQ;

public class hwclient{
    public static void main(String[] args){
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket socket = context.socket(ZMQ.REQ);
        socket.connect ("tcp://localhost:5555");

        System.out.println("Connecting to hello world server");

        long start = System.currentTimeMillis();
        for(int request_nbr = 0; request_nbr != 10_000; request_nbr++) {
            String requestString = "Hello" ;
            byte[] request = requestString.getBytes();           
            socket.send(request, 0);
            byte[] reply = socket.recv(0);           
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
        socket.close();
        context.term();
    }
}

Is is possible to fix this code and get some decent numbers?

Was it helpful?

Solution

You're doing round-trip request-reply, and this will be just as slow using the C++ libzmq. You will only get fast performance on JeroQM, ZeroMQ, or any I/O when you do streaming.

Round-tripping is slow due to how I/O and TCP work. On libzmq we can do about 20K messages/second using round-tripping, and 8M/sec using streaming. Streaming has additional optimizations like batching which you can't do with round-trip request-reply.

For a throughput performance test, send 10M messages from node 1 to node 2, then send back a single ACK when you get them. Time that on ZeroMQ and on JeroMQ, you should see around 3x difference in speed.

OTHER TIPS

Please refer the throughput test between synchronous round-trip and asynchronous round-trip at

https://github.com/zeromq/jeromq/blob/master/src/test/java/guide/tripping.java

The asynchronous was x40 faster than the synchronous round-trip.

If you want to benchmark the full speed of jeromq, please run perf.LocalThr and perf.RemoteThr on your environment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top