Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this JeroMQ (ZeroMQ port) benchmark so slow?

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?

like image 564
Dan Avatar asked Oct 27 '12 17:10

Dan


People also ask

Is Zeromq fast?

It's fast enough to be the fabric for clustered products. Its asynchronous I/O model gives you scalable multicore applications, built as asynchronous message-processing tasks. It has a score of language APIs and runs on most operating systems.

What is a Zeromq context?

A ØMQ context is thread safe and may be shared among as many application threads as necessary, without any additional locking required on the part of the caller. Individual ØMQ sockets are not thread safe except in the case where full memory barriers are issued when migrating a socket from one thread to another.


2 Answers

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.

like image 170
Pieter Hintjens Avatar answered Oct 04 '22 08:10

Pieter Hintjens


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.

like image 26
Min Yu Avatar answered Oct 04 '22 09:10

Min Yu