Skip to content
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

How to use AF_SO_RAW / AF_SP_RAW to create Zeromq ROUTER / DEALER equivalent? #143

Closed
yoshuawuyts opened this issue Jan 9, 2016 · 5 comments
Labels

Comments

@yoshuawuyts
Copy link

I'm trying to create the following network setup:

 ┌──────────┐   ┌──────────┐   ┌──────────┐
 │  Client  │   │  Client  │   │  Client  │
 ├──────────┤   ├──────────┤   ├──────────┤
 │   REQ    │   │   REQ    │   │   REQ    │
 └──────────┘   └──────────┘   └──────────┘
       │              │              │
       └──────────────┼──────────────┘
                ┌─────▼────┐
                │  ROUTER  │
                ├──────────┤
                │  Broker  │
                ├──────────┤
                │  DEALER  │
                └──────────┘
                      │
       ┌──────────────┼──────────────┐
       │              │              │
 ┌─────▼────┐   ┌─────▼────┐   ┌─────▼────┐
 │   REP    │   │   REP    │   │   REP    │
 ├──────────┤   ├──────────┤   ├──────────┤
 │Service A │   │Service B │   │Service C │
 └──────────┘   └──────────┘   └──────────┘

I was looking how to create zeromq's ROUTER / DEALER in nanomsg and stumbled upon a mailinglist answer on how to achieve this.

Nanomsg's creator gave the following response:

Just use REQs, REPs and a device in the middle. When creating sockets
for the device, use AF_SP_RAW family (AF_SP_RAW+REQ is what's called
DEALER in ZeroMQ parlance, and AF_SO_RAW+REP corresponds to ROUTER).

This was slightly confusing to me, as I'm not very familiar with the _RAW variants in nanomsg. So my question is: how can I create a ROUTER / DEALER setup in node-nanomsg? Thanks!

@yoshuawuyts
Copy link
Author

Ah, so it appears load balancing is built into REQ and PUSH sockets, which clarifies the idea behind it a little; we no longer have to think about how to round robin (or in this case, have a multi-tier round robin) to balance the load. All that I'm curious about now is how to wire up the sockets so they're actually connected (which is a lot more trivial).

@reqshark
Copy link
Collaborator

reqshark commented Jan 9, 2016

hey that's a good link, i'm also a fan of: http://250bpm.wdfiles.com/local--files/publications/ietf.pdf

Ah, so it appears load balancing is built into REQ and PUSH sockets

that's right, REQ/REP was designed around the need to distribute precise load balancing tasks among stateless workers. There's also PUSH/PULL, discussed some in #118.

@yoshuawuyts, i think RAW sockets usually need sudo permissions like the low ports, but I'm not 100% if that's the case on every operating system and for every AF_SP_RAW combo

@reqshark
Copy link
Collaborator

reqshark commented Jan 9, 2016

OK I think we only use RAW sockets at the local proxy endpoint, Martin says it's intended for nn_device() which is basically zmq_proxy() or xpub/xsub, etc. from zeromq

here's the better answer: http://www.freelists.org/post/nanomsg/AF-SP-RAW-vs-AF-SP,1

@yoshuawuyts
Copy link
Author

Ah right, so nano.device / nano.createDevice is exposed but not mentioned in the documentation. Mentioning stuff like nano.term() might be good to have in there.

It appears there's some tests around device and raw: true:

raw: true sockets should work with transports other than inproc too right?

edit: I would assume so. From the page you linked:

Use standard sockets if you are going to use the socket yourself. Use RAW sockets to be passed to nn_device().

I think this is pretty clear now; perhaps adding an example for this in /examples might be useful. Thanks!

@reqshark
Copy link
Collaborator

yes it would definitely be useful, @yoshuawuyts would you be up for a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants