Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jzmq poller performance #74

Closed
youest opened this issue Sep 16, 2011 · 2 comments
Closed

jzmq poller performance #74

youest opened this issue Sep 16, 2011 · 2 comments

Comments

@youest
Copy link

youest commented Sep 16, 2011

Hi,
I wrote this test case to check the performance:

package alfred.mdp;

import org.junit.Test;
import org.zeromq.ZMQ;

import java.util.UUID;

import static org.junit.Assert.assertTrue;

/**
 */
public class ZeroMQPerformanceTest {

    private static final int N_MESSAGES = 100000;
    private static final String ADDR = "inproc://reqrep";
    private static final int POLLER_TIMEOUT = 250;

    @Test
    public void performanceTestWithPoller() {
        ZMQ.Context context = ZMQ.context(1);

        ZMQ.Socket in = context.socket(ZMQ.XREQ);
        in.bind(ADDR);

        ZMQ.Socket out = context.socket(ZMQ.XREP);
        out.connect(ADDR);

        ZMQ.Poller poller = context.poller();
        poller.register(out, ZMQ.Poller.POLLIN);
        poller.register(in, ZMQ.Poller.POLLIN);

        for (int i = 0; i < N_MESSAGES; i++) {
            byte[] req = UUID.randomUUID().toString().getBytes();
            assertTrue(in.send(req, 0));
        }

        for (int i = 0; i < N_MESSAGES; i++) {
            if (poller.poll(POLLER_TIMEOUT) > 0 && poller.pollin(0)) {
                out.recv(0);//id
                byte[] reqTmp = out.recv(0);
            }
        }
        long start = System.currentTimeMillis();
        for (int i = 0; i < N_MESSAGES; i++) {
            byte[] req = UUID.randomUUID().toString().getBytes();
            assertTrue(in.send(req, 0));
        }
        System.out.println("performanceTestWithPoller send:" + (System.currentTimeMillis() - start));
        start = System.currentTimeMillis();
        for (int i = 0; i < N_MESSAGES; i++) {
            if (poller.poll(POLLER_TIMEOUT) > 0 && poller.pollin(0)) {
                out.recv(0);//id
                byte[] reqTmp = out.recv(0);
            }
        }
        System.out.println("performanceTestWithPoller receive:" + (System.currentTimeMillis() - start));
    }

    @Test
    public void performanceTest() {
        ZMQ.Context context = ZMQ.context(1);

        ZMQ.Socket in = context.socket(ZMQ.XREQ);
        in.bind(ADDR);

        ZMQ.Socket out = context.socket(ZMQ.XREP);
        out.connect(ADDR);

        for (int i = 0; i < N_MESSAGES; i++) {
            byte[] req = UUID.randomUUID().toString().getBytes();
            assertTrue(in.send(req, 0));
        }

        for (int i = 0; i < N_MESSAGES; i++) {
            out.recv(0);//id
            byte[] reqTmp = out.recv(0);
        }
        long start = System.currentTimeMillis();
        for (int i = 0; i < N_MESSAGES; i++) {
            byte[] req = UUID.randomUUID().toString().getBytes();
            assertTrue(in.send(req, 0));
        }
        System.out.println("performanceTest send:" + (System.currentTimeMillis() - start));
        start = System.currentTimeMillis();
        for (int i = 0; i < N_MESSAGES; i++) {
            out.recv(0);//id
            byte[] reqTmp = out.recv(0);
        }
        System.out.println("performanceTest receive:" + (System.currentTimeMillis() - start));
    }
}

my results are:
performanceTestWithPoller send:787
performanceTestWithPoller receive:1338
performanceTest send:784
performanceTest receive:78

so why are there these differences on receive elapsed time?
is possible it's twenty times slower?

thanks in adv. for help.

Giuseppe

@gonzus
Copy link
Contributor

gonzus commented Sep 16, 2011

This seems to have no specific relation with jzmq, other than the language used to implement your tests. I would advise to post your question on the 0MQ mailing list.

@youest
Copy link
Author

youest commented Sep 16, 2011

Ok thanks ;)

@youest youest closed this as completed Sep 16, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants