On Fri, Mar 1, 2013 at 9:10 AM, Ken Giusti <[email protected]> wrote:

> Thanks, I think you've clarified my understanding of the intended behavior
> of N in messenger::recv(N) - it places a limit to the number of messages
> the application can pn_messenger_get() for that invokation of recv(N).  If
> N==-1, then the number is unspecified.
>
> My understanding is that this API is not making any explicit guarantees
> about what is happening at the wire level - for example, it's possible that
> more messages may in fact arrive via the network - is that correct?
>
> I can buy that.
>

It's certainly not making explicit guarantees about what happens on the
wire, but it's not good in general for the implementation to ever prefetch
more than it needs to. As I mentioned in my reply to Alan on this subject
prefetching too much can have very negative consequences if you're trying
to load balance messages across multiple consumers, and prefetching in
general introduces additional risk/exposure. If a client app asks for 10
messages, processes them, and then exits, and we optimistically prefetch
1024, we've just caused 1014 messages to be abandoned. Even if they were
sent pre-settled it's still not great, it could mean additional load on the
senders since they need to requeue those messages, and some queue
implementations would hold those messages for an extended period before
allowing them to be requeued.

That said, I don't think we urgently need to solve the pathological case
where you have thousands of incoming links and the app is asking for one
message at a time, but that is actually quite straightforward if we
properly implement and use the "available" field in the protocol, and I
actually think it enables some fairly powerful use cases.

Bingo!  That's _exactly_ my problem: the current impl tries to make a
> mapping from the recv(N) argument into the proper distribution of link
> credit. And it does so badly in the multi-link case (w/o the ability to
> really drain, as you point out).  Using N makes it hard to optimize credit
> allocation for any scenario that involves more than one underlying link
> (probably the case for scenario(1) and some cases of scenario(3)).  Good
> optimization for multi-link is complicated because N is unconstrained
> between calls to recv(N) - very hard to do something predictive and fair in
> this case.
>
> However, establishing bounds not based on recv(N) - as you point out -
> would go a long way to making a very nice multi-link credit distribution
> impl.
>
> From a documentation point of view - yes, certainly, a description of
> recv(N) shouldn't involve describing credit at all.
>

Given that we have recv(), I don't think anyone actually needs to use
recv(N) unless they actually really mean I want N messages and no more
(right now), so I don't think we need to worry about recv(N) being fast for
the case where there are lots of underlying links. I think you would use it
if, e.g., you want to write a script that pops exactly N messages off of a
queue, in which case you really don't want any prefetch.

--Rafael

Reply via email to