zeromq / php-zmq

ZeroMQ for PHP
http://pecl.php.net/zmq
Other
551 stars 119 forks source link

Fixes the slow joiner syndrome? #161

Closed daniel-adlantic closed 8 years ago

daniel-adlantic commented 9 years ago

Hello,

I've run into the slow joiner syndrome, and it gave me a headache as it's a pain to debug. Current solutions seem to be either adding overhead (an extra connection to do you're own handshake / state update) or the more simple sleep for a bit and hope it was long enough.

The first seems to be a little excessive since all I want to do is connect and send some data:

$ctx = new ZMQContext();
$socket = $ctx->getsocket(ZMQ::SOCKET_PUB); // Connecting to an XSUB proxy
$socket->connect("tcp://127.0.0.1:7000");
// The fix for this, but it isn't very comforting - is this enough, too little or too much?
usleep(1e3); // 1000 µs = 1 ms
$socket->send("zmq message");

Some ideas to fix this problem properly:

  1. Add a non async connect function. Difference being that it will return only after a connection has been established.
  2. Add a isConnected function - returns true if TCP handshakes have been finalized and false otherwise. I suppose this would be used to let people mimic option 1 with a while loop, which would run until it's either reached a timeout (max n iterations) or isConnected returns true.

It could also be that I'm missing something, so I'm open to other fixes.

mkoppanen commented 8 years ago

Maybe you could use another socket type, such as PUSH which will block?

mkoppanen commented 8 years ago

Other option is to use polling on the socket and see when it becomes writable. This should work for socket types like PUSH

mkoppanen commented 8 years ago

No feedback.

RPGillespie6 commented 7 years ago

This problem isn't unique to PHP... I'm running into the same problem with C++. This is a core issue with PUB/SUB, and even more difficult to work around with XPUB/XSUB