6

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?

Evgeniy Berezovsky
  • 18,571
  • 13
  • 82
  • 156
Dan
  • 11,077
  • 20
  • 84
  • 119
  • Other have answered how to get faster numbers - by doing something else. I just want to point out that your numbers, in absolute terms, are not necessarily bad: On average 0.5 ms per round-tripped message. And as part of the roundtrip, the message is being parsed into a highlevel language, and a processed version of it sent back. Compare that to the figures you get doing a simple ICMP ping, and you get a feeling for the overhead of TCP, JeroMQ and your code. – Evgeniy Berezovsky Apr 18 '14 at 02:50

2 Answers2

15

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.

Pieter Hintjens
  • 6,599
  • 1
  • 24
  • 29
4

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.

Min Yu
  • 194
  • 1
  • 5