codypiersall / pynng

Python bindings for Nanomsg Next Generation.
https://pynng.readthedocs.io
MIT License
260 stars 58 forks source link

AddressInUse error when using multiple Pull0 receivers #82

Closed rossrochford closed 3 years ago

rossrochford commented 3 years ago

Hello,

My understanding from the documentation is that Pull0, Push0 support multiple senders and receivers with load-balancing. I'm able to get multiple senders working but I get an AddressInUse error when multiple Pull0 sockets attempt to listen on the same address. Am I misunderstanding something or is this excepted behavior?

Here is an example script: https://gist.github.com/rossrochford/efc426bc053b9b9a1c85b94fd0dca2f3

You test multiple senders and receivers by passing arguments like:

python pynng_pull0.py receiver1 receiver2 sender1

codypiersall commented 3 years ago

Hello, and thanks for opening an issue!

You are correct that Push/Pull works in a load-balancing way. However, Sockets cannot listen on the same address.

What you can do is have each Pull0 socket at a unique address, where each Pull0 only binds a single address, and have each of the Push0 sockets dial all the receiver addresses. Then you will see the load balancing you expect.

rossrochford commented 3 years ago

Hi, thanks for your response.

Do you mean that a Push0 socket can dial multiple Pull0 sockets and the Push0 socket object will load-balance internally? Or should clients maintain a pool of multiple Push0 sockets?

rossrochford commented 3 years ago

Ok, I tried that and it's working. I guess I can just implement a little address-discovery on top of this for clients.

Thanks again!

codypiersall commented 3 years ago

Glad you got it figured out!