-
Notifications
You must be signed in to change notification settings - Fork 635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPC queue delay #1009
Comments
I have switched to a PULL/PUSH pair rather than PUB/SUB, without seeing any improvements. I think it would be also important to note that the message size varies between 200 and 300 bytes, being received over an UDP socket. Switching to the multiptocessing Pipe, the performances have increased, the latency is way lower, but I don't understand what's the difference. In particular, what's the difference between zmq IPC and multiprocessing Pipe? Could a maintainer please bring some light here and/or point me to the right docs? Thanks, |
Due to poor zmq IPC performances: zeromq/pyzmq#1009 Can be revisited when the issue is clarified.
@minrk does this sound familiar to you at all? Or I am doing something really dumb there that borked the performances? Thanks, |
I'm not sure what could precisely be the cause of a six second, but there may be a failure in libzmq to correctly wake the sub socket when the pub connects to it. Do you mainly see a delay for the first message after a socket connects, or continuous slow performance? Do you see a significant change if you switch to tcp on 127.0.0.1? With a simple PUSH/PULL throughput test, I get a bit under one million 200B msgs/sec on ipc (macOS, libzmq 4.2.1, zmq 16.0.2). |
Hi @minrk - much appreciated your answer. Yes, I would have expected the same: to have a very high number of PPS. Just a quick question: do you think the size of the messages might affect the performances at all? Just a reminder (and trying to clarify and bring more background, without polluting this with unnecessary info): There are two child processes (started with multiprocessing, from a different parent process):
Do you see any potential culprit? Thanks, |
When I've seen weird issues with ipc, it's sometimes been because two processes accidentally 'bind' to the same ipc interface, which doesn't work but won't raise errors. I have also seen issues with unusual bind/connect relationships such as SUB sockets binding. One thing to check is switching transport (try tcp, etc.) and see if things change. |
I did that, but I didn't see any improvement.
it's very likely to be that. Unfortunately, I can't find a good doc to explain the proper bind/connect: http://learning-0mq-with-pyzmq.readthedocs.io/en/latest/pyzmq/patterns/pubsub.html says that the PUB executes the bind, while the SUB executes the connect. Looking at someone else's question (https://stackoverflow.com/questions/5060508/cant-get-zeromq-python-bindings-to-receive-messages-over-ipc), it looks like they did the opposite: PUB does the connect and the SUB does the bind. This is also the pattern you used in your example from #710 (comment) -- which, apparently, doesn't seem to actually work.
@minrk Could you please share the implementation you used for the benchmark above? It would help me too if you could point me to the right documentation; looking at the reference I linked above Thank you! |
Because of zmq's abstractions, every connection order and direction is valid. So it shouldn't be an issue for SUB to bind and PUB to connect. However, I have seen some issues mainly because this scenario is uncommon, and thus bugs are less likely to be found/prioritized. That said, it is rare that I would recommend using PUB-SUB if the receiver is the socket that binds. Some tips about which socket should connect and which should bind:
Some tips for when to choose PUB-SUB:
If the following conditions are met, PUB-SUB is probably not right for you:
Often when I see PUB connecting and SUB binding, what makes more sense is the sink pattern, the bottom half of ventillator-sink in the Guide. That is, many PUSH sockets connecting to one PULL socket. A PUSH-PULL sink has these differences from using PUB-SUB in the same arrangement:
Here's a gist that does a simple push/pull test. On my current machine (macOS 10.12.5, 4GHz Core i7, libzmq 4.1.6, pyzmq master, Python 3.5), I get ~1.3 million msgs/sec over tcp and ~1.6 million msgs/sec over ipc. |
Many thanks @minrk for the detailed answer, much appreciated your time! I am going to close this, it is purely a design fault on my side, that I need to identify. I think your pointers already gave me enough input to know where to start looking from. When I will identify the culprit I will update this in case anyone else will need it later. Thanks once again! |
Hello,
I am designing a new app which makes use of multiprocessing. From multiple sources I heard that zmq IPC may be faster than Python's Pipe (is that correct?).
Inside the program, there are two queues using zmq IPC whose logic is pretty simple: read -> process -> queue. If you would need more background on this, please let me know, I would be happy to expand.
What I have noticed is that even with a relatively low pace (100 messages per second) going through both queues, it takes about 14 seconds. The complete debug log is below:
Very interesting that when there are 10k it takes 19 seconds, vs 14 when there are 100.
Looking straight at the first queue:
this is when the message is received and queued (code)
this is when it's read from the queue (code)
Which introduces a considerable delay of about 6 seconds.
Please note that the SUB and the PUB are running in separate sub-processes started by the same parent. The app is using multiprocessing.
Is there anything I am doing wrong?
My versions:
Thank you,
-Mircea
The text was updated successfully, but these errors were encountered: