use of zmq.Ctx in project jeromq by zeromq.
the class InprocLat method main.
public static void main(String[] argv) throws Exception {
if (argv.length != 2) {
printf("usage: inproc_lat <message-size> <roundtrip-count>\n");
return;
}
int messageSize = atoi(argv[0]);
int roundtripCount = atoi(argv[1]);
Ctx ctx = ZMQ.init(1);
if (ctx == null) {
printf("error in init:");
return;
}
SocketBase s = ZMQ.socket(ctx, ZMQ.ZMQ_REQ);
if (s == null) {
printf("error in socket: ");
return;
}
boolean rc = ZMQ.bind(s, "inproc://lat_test");
if (!rc) {
printf("error in bind: ");
return;
}
Thread localThread = new Thread(new Worker(ctx, roundtripCount));
localThread.start();
Msg smsg = ZMQ.msgInitWithSize(messageSize);
printf("message size: %d [B]\n", (int) messageSize);
printf("roundtrip count: %d\n", (int) roundtripCount);
long watch = ZMQ.startStopwatch();
for (int i = 0; i != roundtripCount; i++) {
int r = ZMQ.sendMsg(s, smsg, 0);
if (r < 0) {
printf("error in sendmsg: %s\n");
return;
}
Msg msg = ZMQ.recvMsg(s, 0);
if (msg == null) {
printf("error in recvmsg: %s\n");
return;
}
if (ZMQ.msgSize(msg) != messageSize) {
printf("message of incorrect size received\n");
return;
}
}
long elapsed = ZMQ.stopStopwatch(watch);
double latency = (double) elapsed / (roundtripCount * 2);
localThread.join();
printf("average latency: %.3f [us]\n", (double) latency);
ZMQ.close(s);
ZMQ.term(ctx);
}
Aggregations