-
Notifications
You must be signed in to change notification settings - Fork 485
Home
miniway edited this page Oct 7, 2012
·
20 revisions
Welcome to the jeromq wiki!
Please read the bible first.
JeroMQ ported guide examples. I just changed the namespace from org.zeromq to org.jeromq, removed '\u0000' terminated string and 0MQ 2.x specific code.
- Context.term() must be called before interrupting a thread by Thread.interrupt. Otherwise internal pipe which is used to signal ZMQ commands will be shutdown unexpectedly.
- When you use the org.jeromq.ZMQ.Poller, it opens a Selector by using (java.nio.channels.Selector.open) right before poll then close the selector by default. You should disable it by setAutoClose(false) and poll many times on a existing poller when you want to increase performance. Also don't forget to call close.
/* bad */
while(true) {
ZMQ.Poller items = ctx.getContext().poller();
items.register(socket, ZMQ.Poller.POLLIN);
items.poll(timeout);
// blabla
}
/* good */
ZMQ.Poller items = ctx.getContext().poller();
items.setAutoClose(false);
items.register(socket, ZMQ.Poller.POLLIN);
while(true) {
items.poll(timeout);
// blabla
}
items.close();
Common mistakes (Already mentioned at the zguide )
- Close all the sockets property otherwise Context.term() will wait forever
- Set a proper linger by using Socket.setLinger(millis) when you want to wait before socket termination. Otherwise some last messages could not be delivered.
- Set a propert HWM (High Water Mark). At 0MQ 3.x, you should set Socket.setSndHWM and setRcvHWM separately. The default value is 1000 each. -1 is unlimited but it could blow your memory.
- At PUB/SUB, PUB will drop messages silently when a connected sending pipe has more messages than HWM. Other available SUBs will can receive the messages.
- At PUSH/PULL, PUSH will block sending messages when there's no available PULL. Otherwise one of available PULL can receive the messages.
- If you're interested in LWM (Low Water Mark) also please refer compute_lwm at Pipe.java
- -server -XX:+UseConcMarkSweepGC
- -XX:+TieredCompilation (if you're using the latest JVM)
- At java7, tiered compilation is now the default mode for the server VM
- -XX:+AggressiveOpts
- -XX:+UseCompressedOops might increase performance a little bit or not at 64bit OS
- enabled by default in Java SE 6u23 and later. In Java SE 7, use of compressed oops is the default for 64-bit JVM processes when -Xmx isn't specified and for values of -Xmx less than 32 gigabytes.
- -XX:+UseBiasedLocking might increase performance a little bit or not