[nanomsg] Trying to implement "directory" pattern

  • From: Paul Colomiets <paul@xxxxxxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Fri, 22 Feb 2013 00:53:13 +0200

Hi,

I'm trying to implement the following message pattern, I call it
"directory" (have a better name?).

Directory pattern has two socket types: ASK and ANSWER. They are mostly
analogous to REQ and REP types respectively. The difference is that ANSWER
socket can choose what requests it serves. This works by setting SUBSCRIBE
option on the socket, which sends the subscription to ASK socket, similarly
to how it's done for PUB/SUB sockets in crossroads IO (with subscription
forwarding). ASK socket keeps a trie of prefixes and for each node of the
trie a list of pipes (ANSWER endpoints) is kept to load-balance between
them. So each message matches against trie to find a subset of pipes that
can be used to serve a request.

Illustration attached. At the picture there is a single node A which serves
requests for "cars" and two nodes (B and C) which serve requests for
"computers"

This way we get a request-reply pattern with stateful routing, while
keeping important properties of other patterns (scalability, uniformity and
interjection)

In the future it's intended to use same infrastructure that will be
implemented for PUB/SUB subscriptions (i.e. plugins for subscription
matching)

I currently have the following questions:

1. Does AF_SP_RAW intended for asynchronous socket handling, similarly to
how X* sockets worked in zeromq? It matters because xask and xanswer going
to operate on subscriptions with messages, and asynchronous sockets should
subscribe by socket option. However, non-raw answer socket can only process
one request at a time, which is unviable for asynchronous applications.

2. When pipe is added to answer socket, all subscriptions should be resent.
Is there a way to put all the subscriptions into a pipe without any limits?
Otherwise, I need either build a complex state machine to track which
subscriptions are already resent, or bundle all subscriptions to a single
message (inventing some ad-hoc message format). BTW, similar problem with
just adding a subscription, when some output pipes are full. What
crossroads does in this case?

3. I'm going to use NN_RESEND_IVL and NN_SUBSCRIBE options, but they have
same integer value. So I either need to reinvent names, or we need to set
unique numbers for built-in socket options. I think the latter is
preferable, as it also less error prone (can't setsockopt(NN_RESEND_IVL)
for SUB socket)

4. Martin, could you describe a bit, how chunks work? I need to mark
messages for being either subscriptions or request/reply, as well as keep a
chain of routing data like for req-rep. Any suggestions?

5. The POLLOUT will always be signaled. It's useless to check if at least
one pipe is not full, as the subset of pipes can be used for each message.
The end to end resending mechanism will be used to fix the problem. Is the
tradeoff ok?

Of course, overall comments on pattern design are appreciated.

-- 
Paul

Attachment: directory_pattern.png
Description: PNG image

Other related posts: