pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.17k stars 163 forks source link

Sync sub/pub inconsistent and often fails using go-zmq4 vs C #109

Closed hamid-elaosta closed 7 years ago

hamid-elaosta commented 7 years ago

Running the following example from the guide; "Node Coordination" http://zguide.zeromq.org/page:all#Node-Coordination

but using the modified examples from this repository; https://github.com/pebbe/zmq4/blob/master/examples/syncpub.go and https://github.com/pebbe/zmq4/blob/master/examples/syncsub.go

fail almost every time. Running the original guide examples in C succeed every time with the same conditions.

I am using TCP, client and server are on the same machine, compiling against go1.8.3 linux/amd64. Using libzmq5 (4.1.4-7 amd64) on Ubuntu 16.04 amd64 and kernel 4.8.0-58.

Playing around with timings changes the behaviour but is not acceptable for a usable system.

pebbe commented 7 years ago

I had problems getting this to work. Messages were never received. I fixed this by introducing delays.

But it seems that in the mean time the C example has changed. It now uses a high water mark. I introduced this into the example, added an explicit termination of the context, and dropped all the delays. Now it works fine on my machine. Tested also in zmq2 and zmq3.

Can you please test the updated version?

hamid-elaosta commented 7 years ago

Will do, I had already tested the HWM but it made no difference, I'll try the context termination and let you know.

hamid-elaosta commented 7 years ago

@pebbe I can confirm that adding the context termination as well as the HWM does indeed solve the issue with my setup. I removed all delays and all messages are received consistently now.

Removing either of the HWM config or the deferred Term of the context breaks it again.

Without HWM of 1.1M & with deferred context term:

1000000 updates sent
Received 387675 updates
Received 374175 updates
Received 408175 updates
Received 368675 updates
Received 423675 updates
Received 411175 updates
Received 400675 updates
Received 416675 updates
Received 420175 updates
Received 394675 updates

with HWM of 1.1M & deferred context term:

1000000 updates sent
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates
Received 1000000 updates