jeromq
jeromq copied to clipboard
HWM not reliable
hwm don't seems to be reliable on open socket.
I tried the following code:
import java.util.Date;
import java.util.function.Consumer;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;
public class TestOne {
static public void main(final String[] args) throws InterruptedException {
Context context = ZMQ.context(1);
Socket spull = context.socket(ZMQ.PULL);
spull.setRcvHWM(1);
spull.bind("ipc://one");
Socket spush = context.socket(ZMQ.PUSH);
spush.setSndHWM(5);
spush.setSendTimeOut(100);
spush.connect("ipc://one");
long timestart = (new Date()).getTime();
Consumer<Object> delta= (i) -> { System.out.println("" + Long.toString((new Date()).getTime() - timestart) + ": " + i.toString());};
for(int i = 1; i < 20; i++) {
delta.accept("" + i+ " " + spush.send("" + i) + " " + spush.base().errno());
Thread.sleep(1);
}
delta.accept("" + new String(spull.recv()));
}
}
I'm not getting reliable results.
It should hang after 5 ou 6 events or failed. But spush.send("" + i) always succeed. And errno is not always consistent. Some time this code output:
55: 1 true 0
57: 2 true 0
58: 3 true 0
60: 4 true 0
61: 5 true 0
63: 6 true 35
64: 7 true 35
66: 8 true 35
67: 9 true 35
68: 10 true 35
70: 11 true 35
71: 12 true 35
73: 13 true 35
74: 14 true 35
75: 15 true 35
77: 16 true 35
78: 17 true 35
79: 18 true 35
81: 19 true 35
82: 1
How can I get a true (send succeed) but still get a 35 errno ? But I can also get:
55: 1 true 0
58: 2 true 0
60: 3 true 0
61: 4 true 0
63: 5 true 0
64: 6 true 0
65: 7 true 0
67: 8 true 0
68: 9 true 0
69: 10 true 0
71: 11 true 0
72: 12 true 0
74: 13 true 0
75: 14 true 0
76: 15 true 0
78: 16 true 0
79: 17 true 0
81: 18 true 0
82: 19 true 0
84: 1
I tried it with a git clone of the day.
If there is no pull socket open, I get the expected results:
60: 1 true 0
62: 2 true 0
63: 3 true 0
65: 4 true 0
66: 5 true 0
172: 6 false 35
278: 7 false 35
384: 8 false 35
486: 9 false 35
592: 10 false 35
696: 11 false 35
802: 12 false 35
904: 13 false 35
1009: 14 false 35
1114: 15 false 35
1220: 16 false 35
1325: 17 false 35
1428: 18 false 35
1533: 19 false 35
Recently found that this issue still exists. Neither HWM or buffer size seems to work correctly.
It is only for inproc transport that the number of messages able to be sent without hanging is equal to send HWM + receive HWM. As it is ipc transport, the mechanism is very different.
I invite you to read https://github.com/zeromq/pyzmq/issues/96, comments are especially insightful.
Regarding errno, value should be considered only in case of error, as it is not automatically reset between calls.