You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Kai Hudalla <so...@gmail.com> on 2017/03/01 14:31:19 UTC

[proton-j] handling of link-credit

Hi,

we are working on the Eclipse Hono project where we use vertx-proton and
(implicitly) proton-j under the hood for exchanging large amounts of messages
using AMQP 1.0.

During our tests I stumbled across the way that proton-j seems to handle link-
credit being exchanged via FLOWs.
My understanding is the following:

Assuming that we have a link established between a Receiver (r) and a Sender (s)
with a current link-credit of 4 and a delivery count of 20 on both sides.

When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
current credit resulting in r.getCredit() returning 10.

When the FLOW is then flushed to the sender, the sender seems to _add_ the link-
credit from the FLOW to its already existing credit. Analogously, this results in
s.getCredit() now returning 10.

With this approach, it doesn't seem to be possible to stop the sender from
sending messages. The only thing a receiver can do is to wait until the sender
has used up all its credit (which may be a lot given that with the current
approach the sender's credit can pile up substantially).

Or am I mistaken?

Also, I cannot find the code where the link credit is actually updated from a
FLOW received from a Receiver. Can you point me to the right class?

Regards,
Kai

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 6 March 2017 at 12:23, Robbie Gemmell <ro...@gmail.com> wrote:

> On 3 March 2017 at 19:31, Alan Conway <ac...@redhat.com> wrote:
> > On Wed, 2017-03-01 at 15:45 +0000, Robbie Gemmell wrote:
> >> > That is a correct understanding of the AMQP 1.0 spec (section 2.6.7
> >> > specifically deals with this case of credit being revoked: "If the
> >> > link-credit is less than or equal to zero, i.e., the delivery-count
> >> > is the
> >> > same as or greater than the delivery-limit, a sender MUST NOT send
> >> > more
> >> > messages. If the link-credit is reduced by the receiver when
> >> > transfers are
> >> > in-flight, the receiver MAY either handle the excess messages
> >> > normally or
> >> > detach the link with a transfer-limit-exceeded error code.")
> >> >
> >> > As Gordon suggested separately, the logical thing to do through the
> >> > Proton
> >> > API would be to try to flow negative credits...
> >
> > I would *strongly* suggest that if  you want to stop a sender with too
> > much credit you should close the link. The inconvenience of re-
> > establishing the link will be nothing to the hell you will enter if you
> > try to implement negative credit. It is theoretically possible and
> > allowed by the spec, but the chances that any application you are
> > connected to will implement it properly are slim to none.
> >
>
> This mail weirdly turned up a days late :)
>

Indeed, I'd assumed it had got stuck in moderation and you'd pushed it
through... obviously not :-)


>
> > The concept of credit is clear and simple when you see it as a promise
> > between sender and receiver that must not be broken *in either
> > direction*. Revoking credit is breaking half the promise. The more
> > elaborate AMQP view of "credit" where it can be negative (debit?) is
> > mathematically sound but pragmatically a bad idea.
> >
> >> > however I'm not sure that
> >> > Proton-J is going to handle this correctly,
> >
> > See? See? I am fairly certain that almost nobody will handle this
> > correctly. Proton-C provides the tools, but you have to get the book-
> > keeping right, and have faith that every application you connect to
> > will as well. That is a bad bet.
> >
>
> I'm still not particularly confident that proton-c can handle this
> fully either. From some testing Rob did, proton-j definitely doesnt
> and as I suspected can do bad things like wrapping credit values and
> end up sending massive uint values thinking they are negative (you
> cant actually represent negative credit on the wire since its
> unsigned).
>


So there are, I think two distinct things here:

1) Proton[-J] should absolutely be able to handle the peer it is
communicating with following the AMQP spec and reducing credit.  Proton[-j]
should also handle the case where the amount of link credit granted on a
link is greater than the largest values able to be stored in a signed int.
Currently in Proton-J it looks to me like
  a) Receivers do absolutely no checking to see if the sender is sending
beyond the amount of credit the receiver has allocated, and that any such
checking is left to the application layer.  Is this a deliberate API choice
  b) Very large credit values granted to senders will actually be
interpreted as negative values and the sender will not send.  This is
clearly a bug.

2) Proton[-J] has no API that explicitly allows the reducing of granted
credit.  The documentation for (Proton-J) Receiver.flow() talks about
"adding credit", and does not explicitly rule out the idea that the number
to add may be negative... but it doesn't state it as a valid use case
either.

For point 2) there are essentially two API choices - either explicitly
allowing -ve adds (and pushing the responsibility to the application layer
to ensure that credit is granted retrospectively for messages sent after
reduction has been initiation, but before processing at the sender); or we
add a "stop()" method to the receiver.  In the case of the latter the
notion of "adding" credit is hard to define until the sender and receiver
have a common view of the shared credit state.  (Unless we take the view
that stop() is simply an alias for flow(- current outstanding credit), and
that, again, the application needs to take responsibility for
retrospectively flowing credit for messages that were sent between the
receiver reducing credit and the sender processing this change of credit
state.

-- Rob


> That said, while in many cases it will behave no differently than a
> drain, I do think we should implement support for this eventually,
> thats why I raised the JIRA. Peers that dont handle it are one thing,
> proton not being able to do it to begin with is another.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 3 March 2017 at 19:31, Alan Conway <ac...@redhat.com> wrote:
> On Wed, 2017-03-01 at 15:45 +0000, Robbie Gemmell wrote:
>> > That is a correct understanding of the AMQP 1.0 spec (section 2.6.7
>> > specifically deals with this case of credit being revoked: "If the
>> > link-credit is less than or equal to zero, i.e., the delivery-count
>> > is the
>> > same as or greater than the delivery-limit, a sender MUST NOT send
>> > more
>> > messages. If the link-credit is reduced by the receiver when
>> > transfers are
>> > in-flight, the receiver MAY either handle the excess messages
>> > normally or
>> > detach the link with a transfer-limit-exceeded error code.")
>> >
>> > As Gordon suggested separately, the logical thing to do through the
>> > Proton
>> > API would be to try to flow negative credits...
>
> I would *strongly* suggest that if  you want to stop a sender with too
> much credit you should close the link. The inconvenience of re-
> establishing the link will be nothing to the hell you will enter if you
> try to implement negative credit. It is theoretically possible and
> allowed by the spec, but the chances that any application you are
> connected to will implement it properly are slim to none.
>

This mail weirdly turned up a days late :)

> The concept of credit is clear and simple when you see it as a promise
> between sender and receiver that must not be broken *in either
> direction*. Revoking credit is breaking half the promise. The more
> elaborate AMQP view of "credit" where it can be negative (debit?) is
> mathematically sound but pragmatically a bad idea.
>
>> > however I'm not sure that
>> > Proton-J is going to handle this correctly,
>
> See? See? I am fairly certain that almost nobody will handle this
> correctly. Proton-C provides the tools, but you have to get the book-
> keeping right, and have faith that every application you connect to
> will as well. That is a bad bet.
>

I'm still not particularly confident that proton-c can handle this
fully either. From some testing Rob did, proton-j definitely doesnt
and as I suspected can do bad things like wrapping credit values and
end up sending massive uint values thinking they are negative (you
cant actually represent negative credit on the wire since its
unsigned).

That said, while in many cases it will behave no differently than a
drain, I do think we should implement support for this eventually,
thats why I raised the JIRA. Peers that dont handle it are one thing,
proton not being able to do it to begin with is another.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Alan Conway <ac...@redhat.com>.
On Wed, 2017-03-01 at 15:45 +0000, Robbie Gemmell wrote:
> > That is a correct understanding of the AMQP 1.0 spec (section 2.6.7
> > specifically deals with this case of credit being revoked: "If the
> > link-credit is less than or equal to zero, i.e., the delivery-count 
> > is the
> > same as or greater than the delivery-limit, a sender MUST NOT send
> > more
> > messages. If the link-credit is reduced by the receiver when
> > transfers are
> > in-flight, the receiver MAY either handle the excess messages
> > normally or
> > detach the link with a transfer-limit-exceeded error code.")
> > 
> > As Gordon suggested separately, the logical thing to do through the
> > Proton
> > API would be to try to flow negative credits... 

I would *strongly* suggest that if  you want to stop a sender with too
much credit you should close the link. The inconvenience of re-
establishing the link will be nothing to the hell you will enter if you
try to implement negative credit. It is theoretically possible and
allowed by the spec, but the chances that any application you are
connected to will implement it properly are slim to none.

The concept of credit is clear and simple when you see it as a promise
between sender and receiver that must not be broken *in either
direction*. Revoking credit is breaking half the promise. The more
elaborate AMQP view of "credit" where it can be negative (debit?) is
mathematically sound but pragmatically a bad idea.

> > however I'm not sure that
> > Proton-J is going to handle this correctly, 

See? See? I am fairly certain that almost nobody will handle this
correctly. Proton-C provides the tools, but you have to get the book-
keeping right, and have faith that every application you connect to
will as well. That is a bad bet.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 15:43, Rob Godfrey <ro...@gmail.com> wrote:
> On 1 March 2017 at 16:29, Kai Hudalla <so...@gmail.com> wrote:
>
>> On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
>> > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
>> > > Hi,
>> > >
>> > > we are working on the Eclipse Hono project where we use vertx-proton
>> and
>> > > (implicitly) proton-j under the hood for exchanging large amounts of
>> messages
>> > > using AMQP 1.0.
>> > >
>> > > During our tests I stumbled across the way that proton-j seems to
>> handle
>> > > link-
>> > > credit being exchanged via FLOWs.
>> > > My understanding is the following:
>> > >
>> > > Assuming that we have a link established between a Receiver (r) and a
>> Sender
>> > > (s)
>> > > with a current link-credit of 4 and a delivery count of 20 on both
>> sides.
>> > >
>> > > When invoking r.flow(6), the given credit (6) is _added_ to the
>> receiver's
>> > > current credit resulting in r.getCredit() returning 10.
>> > >
>> > > When the FLOW is then flushed to the sender, the sender seems to _add_
>> the
>> > > link-
>> > > credit from the FLOW to its already existing credit. Analogously, this
>> > > results in
>> > > s.getCredit() now returning 10.
>> >
>> > Correct. In proton the flow(credits) method grants additional credits.
>> >
>> > >
>> > > With this approach, it doesn't seem to be possible to stop the sender
>> from
>> > > sending messages. The only thing a receiver can do is to wait until the
>> > > sender
>> > > has used up all its credit (which may be a lot given that with the
>> current
>> > > approach the sender's credit can pile up substantially).
>> > >
>> > > Or am I mistaken?
>> >
>> > Granting credits is essentially giving the sender ability to send that
>> > many messages. If you are controlling credit, any 'pile up' of credit
>> > at the sender is one that you create yourself - if you dont want the
>> > sender to be able to send more than a certain number of messages at a
>> > given time, dont allow more than that number of credits to be
>> > outstanding at the time.
>>
>> So, still, there is no way to stop a sender from sending once it has
>> credit and
>> wants to send messages, right? My understanding of the AMQP 1.0 spec is
>> that it
>> should be possible to do so by flowing a link-credit of 0 to the sender.
>>
>
>
> That is a correct understanding of the AMQP 1.0 spec (section 2.6.7
> specifically deals with this case of credit being revoked: "If the
> link-credit is less than or equal to zero, i.e., the delivery-count is the
> same as or greater than the delivery-limit, a sender MUST NOT send more
> messages. If the link-credit is reduced by the receiver when transfers are
> in-flight, the receiver MAY either handle the excess messages normally or
> detach the link with a transfer-limit-exceeded error code.")
>
> As Gordon suggested separately, the logical thing to do through the Proton
> API would be to try to flow negative credits... however I'm not sure that
> Proton-J is going to handle this correctly, in particular in the case where
> you try to reduce the credit below the amount of credit that has already
> been used with messages in flight.
>
> -- Rob
>

I was about to reply to Gordons mail to say the same thing. As per my
other mail, proton doesn't really support reducing credit like that.

>
>>
>> >
>> > One thing you may not be aware of is you can drain the link of
>> > existing credit, which essentially asks the sender to send what they
>> > can (something they typically will have already done if they have
>> > credit and anything to send) then spontaneously advance the delivery
>> > count to the extent needed to use up all outstanding credit.
>> >
>>
>> I am aware of this but it also doesn't help with stopping a sender that is
>> already sending, does it?
>>
>> My understanding of all of this is that a Receiver should not grant much
>> credit
>> to a Sender (because it cannot stop the sender once it has started
>> sending).
>> Then, when a message is coming in, the receiver should check whether there
>> is
>> credit left for the sender (using Receiver.getCredit() ?) and if not it
>> should
>> grant some more credit using Receiver.flow(small number) again.
>>
>> Does that make sense?
>>
>>
>> > > Also, I cannot find the code where the link credit is actually updated
>> from a
>> > > FLOW received from a Receiver. Can you point me to the right class?
>> > >
>> >
>> > TransportSender is probably what you want.
>> >
>> > > Regards,
>> > > Kai
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> > > For additional commands, e-mail: users-help@qpid.apache.org
>> > >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> > For additional commands, e-mail: users-help@qpid.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 16:29, Kai Hudalla <so...@gmail.com> wrote:

> On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
> > > Hi,
> > >
> > > we are working on the Eclipse Hono project where we use vertx-proton
> and
> > > (implicitly) proton-j under the hood for exchanging large amounts of
> messages
> > > using AMQP 1.0.
> > >
> > > During our tests I stumbled across the way that proton-j seems to
> handle
> > > link-
> > > credit being exchanged via FLOWs.
> > > My understanding is the following:
> > >
> > > Assuming that we have a link established between a Receiver (r) and a
> Sender
> > > (s)
> > > with a current link-credit of 4 and a delivery count of 20 on both
> sides.
> > >
> > > When invoking r.flow(6), the given credit (6) is _added_ to the
> receiver's
> > > current credit resulting in r.getCredit() returning 10.
> > >
> > > When the FLOW is then flushed to the sender, the sender seems to _add_
> the
> > > link-
> > > credit from the FLOW to its already existing credit. Analogously, this
> > > results in
> > > s.getCredit() now returning 10.
> >
> > Correct. In proton the flow(credits) method grants additional credits.
> >
> > >
> > > With this approach, it doesn't seem to be possible to stop the sender
> from
> > > sending messages. The only thing a receiver can do is to wait until the
> > > sender
> > > has used up all its credit (which may be a lot given that with the
> current
> > > approach the sender's credit can pile up substantially).
> > >
> > > Or am I mistaken?
> >
> > Granting credits is essentially giving the sender ability to send that
> > many messages. If you are controlling credit, any 'pile up' of credit
> > at the sender is one that you create yourself - if you dont want the
> > sender to be able to send more than a certain number of messages at a
> > given time, dont allow more than that number of credits to be
> > outstanding at the time.
>
> So, still, there is no way to stop a sender from sending once it has
> credit and
> wants to send messages, right? My understanding of the AMQP 1.0 spec is
> that it
> should be possible to do so by flowing a link-credit of 0 to the sender.
>


That is a correct understanding of the AMQP 1.0 spec (section 2.6.7
specifically deals with this case of credit being revoked: "If the
link-credit is less than or equal to zero, i.e., the delivery-count is the
same as or greater than the delivery-limit, a sender MUST NOT send more
messages. If the link-credit is reduced by the receiver when transfers are
in-flight, the receiver MAY either handle the excess messages normally or
detach the link with a transfer-limit-exceeded error code.")

As Gordon suggested separately, the logical thing to do through the Proton
API would be to try to flow negative credits... however I'm not sure that
Proton-J is going to handle this correctly, in particular in the case where
you try to reduce the credit below the amount of credit that has already
been used with messages in flight.

-- Rob


>
> >
> > One thing you may not be aware of is you can drain the link of
> > existing credit, which essentially asks the sender to send what they
> > can (something they typically will have already done if they have
> > credit and anything to send) then spontaneously advance the delivery
> > count to the extent needed to use up all outstanding credit.
> >
>
> I am aware of this but it also doesn't help with stopping a sender that is
> already sending, does it?
>
> My understanding of all of this is that a Receiver should not grant much
> credit
> to a Sender (because it cannot stop the sender once it has started
> sending).
> Then, when a message is coming in, the receiver should check whether there
> is
> credit left for the sender (using Receiver.getCredit() ?) and if not it
> should
> grant some more credit using Receiver.flow(small number) again.
>
> Does that make sense?
>
>
> > > Also, I cannot find the code where the link credit is actually updated
> from a
> > > FLOW received from a Receiver. Can you point me to the right class?
> > >
> >
> > TransportSender is probably what you want.
> >
> > > Regards,
> > > Kai
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Paolo Patierno <pp...@live.com>.
I had the same question for Robbie few months ago ... and of course he replied me in the same way [😊]


Sending flow(0) as AMQP 1.0 allows is not provided by proton-j

Neither reducing credits with a negative value

Finally the only way could be using drain or just granting 1 credit at time ... but of course with poor performance !


Paolo Patierno
Senior Software Engineer (IoT) @ Red Hat
Microsoft MVP on Windows Embedded & IoT
Microsoft Azure Advisor

Twitter : @ppatierno<http://twitter.com/ppatierno>
Linkedin : paolopatierno<http://it.linkedin.com/in/paolopatierno>
Blog : DevExperience<http://paolopatierno.wordpress.com/>


________________________________
From: Robbie Gemmell <ro...@gmail.com>
Sent: Wednesday, March 01, 2017 3:49 PM
To: users@qpid.apache.org
Subject: Re: [proton-j] handling of link-credit

On 1 March 2017 at 15:44, Robbie Gemmell <ro...@gmail.com> wrote:
> On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
>> On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
>>> On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
>>> > Hi,
>>> >
>>> > we are working on the Eclipse Hono project where we use vertx-proton and
>>> > (implicitly) proton-j under the hood for exchanging large amounts of messages
>>> > using AMQP 1.0.
>>> >
>>> > During our tests I stumbled across the way that proton-j seems to handle
>>> > link-
>>> > credit being exchanged via FLOWs.
>>> > My understanding is the following:
>>> >
>>> > Assuming that we have a link established between a Receiver (r) and a Sender
>>> > (s)
>>> > with a current link-credit of 4 and a delivery count of 20 on both sides.
>>> >
>>> > When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
>>> > current credit resulting in r.getCredit() returning 10.
>>> >
>>> > When the FLOW is then flushed to the sender, the sender seems to _add_ the
>>> > link-
>>> > credit from the FLOW to its already existing credit. Analogously, this
>>> > results in
>>> > s.getCredit() now returning 10.
>>>
>>> Correct. In proton the flow(credits) method grants additional credits.
>>>
>>> >
>>> > With this approach, it doesn't seem to be possible to stop the sender from
>>> > sending messages. The only thing a receiver can do is to wait until the
>>> > sender
>>> > has used up all its credit (which may be a lot given that with the current
>>> > approach the sender's credit can pile up substantially).
>>> >
>>> > Or am I mistaken?
>>>
>>> Granting credits is essentially giving the sender ability to send that
>>> many messages. If you are controlling credit, any 'pile up' of credit
>>> at the sender is one that you create yourself - if you dont want the
>>> sender to be able to send more than a certain number of messages at a
>>> given time, dont allow more than that number of credits to be
>>> outstanding at the time.
>>
>> So, still, there is no way to stop a sender from sending once it has credit and
>> wants to send messages, right? My understanding of the AMQP 1.0 spec is that it
>> should be possible to do so by flowing a link-credit of 0 to the sender.
>>
>
> Correct, it does. Proton doesnt really support reducing credit.
>
> https://issues.apache.org/jira/browse/PROTON-796
>
>>>
>>> One thing you may not be aware of is you can drain the link of
>>> existing credit, which essentially asks the sender to send what they
>>> can (something they typically will have already done if they have
>>> credit and anything to send) then spontaneously advance the delivery
>>> count to the extent needed to use up all outstanding credit.
>>>
>>
>> I am aware of this but it also doesn't help with stopping a sender that is
>> already sending, does it?
>>
>
> To a large extent its little different than setting credit to 0; if a
> sender already has credit and content to send you then they can
> already send it, and are likely to do so before receiving a flow frame
> setting credit back to 0.
>
>> My understanding of all of this is that a Receiver should not grant much credit
>> to a Sender (because it cannot stop the sender once it has started sending).
>> Then, when a message is coming in, the receiver should check whether there is
>> credit left for the sender (using Receiver.getCredit() ?) and if not it should
>> grant some more credit using Receiver.flow(small number) again.
>>
>> Does that make sense?
>>
>
> As above, you should grant only as much outstanding credit as you are
> actually willing for a sender to use at a given time. The above would
> be one way to do it. You can also look at getRemoteCredit, which takes
> locally-queued deliveries into account as well.
>

Or, if I took the full context into account, I would instead have
said: also look at getQueued() to consider locally queued deliveries.

>>
>>> > Also, I cannot find the code where the link credit is actually updated from a
>>> > FLOW received from a Receiver. Can you point me to the right class?
>>> >
>>>
>>> TransportSender is probably what you want.
>>>
>>> > Regards,
>>> > Kai
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>>> > For additional commands, e-mail: users-help@qpid.apache.org
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 15:44, Robbie Gemmell <ro...@gmail.com> wrote:
> On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
>> On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
>>> On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
>>> > Hi,
>>> >
>>> > we are working on the Eclipse Hono project where we use vertx-proton and
>>> > (implicitly) proton-j under the hood for exchanging large amounts of messages
>>> > using AMQP 1.0.
>>> >
>>> > During our tests I stumbled across the way that proton-j seems to handle
>>> > link-
>>> > credit being exchanged via FLOWs.
>>> > My understanding is the following:
>>> >
>>> > Assuming that we have a link established between a Receiver (r) and a Sender
>>> > (s)
>>> > with a current link-credit of 4 and a delivery count of 20 on both sides.
>>> >
>>> > When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
>>> > current credit resulting in r.getCredit() returning 10.
>>> >
>>> > When the FLOW is then flushed to the sender, the sender seems to _add_ the
>>> > link-
>>> > credit from the FLOW to its already existing credit. Analogously, this
>>> > results in
>>> > s.getCredit() now returning 10.
>>>
>>> Correct. In proton the flow(credits) method grants additional credits.
>>>
>>> >
>>> > With this approach, it doesn't seem to be possible to stop the sender from
>>> > sending messages. The only thing a receiver can do is to wait until the
>>> > sender
>>> > has used up all its credit (which may be a lot given that with the current
>>> > approach the sender's credit can pile up substantially).
>>> >
>>> > Or am I mistaken?
>>>
>>> Granting credits is essentially giving the sender ability to send that
>>> many messages. If you are controlling credit, any 'pile up' of credit
>>> at the sender is one that you create yourself - if you dont want the
>>> sender to be able to send more than a certain number of messages at a
>>> given time, dont allow more than that number of credits to be
>>> outstanding at the time.
>>
>> So, still, there is no way to stop a sender from sending once it has credit and
>> wants to send messages, right? My understanding of the AMQP 1.0 spec is that it
>> should be possible to do so by flowing a link-credit of 0 to the sender.
>>
>
> Correct, it does. Proton doesnt really support reducing credit.
>
> https://issues.apache.org/jira/browse/PROTON-796
>
>>>
>>> One thing you may not be aware of is you can drain the link of
>>> existing credit, which essentially asks the sender to send what they
>>> can (something they typically will have already done if they have
>>> credit and anything to send) then spontaneously advance the delivery
>>> count to the extent needed to use up all outstanding credit.
>>>
>>
>> I am aware of this but it also doesn't help with stopping a sender that is
>> already sending, does it?
>>
>
> To a large extent its little different than setting credit to 0; if a
> sender already has credit and content to send you then they can
> already send it, and are likely to do so before receiving a flow frame
> setting credit back to 0.
>
>> My understanding of all of this is that a Receiver should not grant much credit
>> to a Sender (because it cannot stop the sender once it has started sending).
>> Then, when a message is coming in, the receiver should check whether there is
>> credit left for the sender (using Receiver.getCredit() ?) and if not it should
>> grant some more credit using Receiver.flow(small number) again.
>>
>> Does that make sense?
>>
>
> As above, you should grant only as much outstanding credit as you are
> actually willing for a sender to use at a given time. The above would
> be one way to do it. You can also look at getRemoteCredit, which takes
> locally-queued deliveries into account as well.
>

Or, if I took the full context into account, I would instead have
said: also look at getQueued() to consider locally queued deliveries.

>>
>>> > Also, I cannot find the code where the link credit is actually updated from a
>>> > FLOW received from a Receiver. Can you point me to the right class?
>>> >
>>>
>>> TransportSender is probably what you want.
>>>
>>> > Regards,
>>> > Kai
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>>> > For additional commands, e-mail: users-help@qpid.apache.org
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>>> For additional commands, e-mail: users-help@qpid.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Kai Hudalla <so...@gmail.com>.
On Wed, 2017-03-01 at 17:04 +0000, Gordon Sim wrote:
> On 01/03/17 16:53, Kai Hudalla wrote:
> > If the sender has e.g. 100 credits left and
> > indeed has content to send 100 messages then a drain doesn't prevent him from
> > sending all 100 messages. However, flowing 0 link-credit to the sender has
> > the
> > effect of immediately stopping him (not considering messages in flight, of
> > course). This pattern therefore has the big advantage that a receiver can be
> > generous at first, issuing e.g. 200 credits, in order to reduce the number of
> > flows exchanged while things go well, and then simply stop the sender once
> > resources become more constrained on the receiver side.
> 
> While I agree there is a difference between drain and revoking credit,�
> even if you issue a flow(0), you still have to handle N messages after�
> issuing it, where N is balance at the time you revoked it.
> 
That is true and the spec actually describes the receiver's options for this case
quite explicitly: either close the link with the sender with a "recource-limit-
exceeded" or handle the "in-flight" messages.

> (Since that many messages may already be 'inflight'. As the balance gets�
> higher it is more likely that the sender gets the flow before they have�
> exhausted the credit of course.)
> 
> A couple of hundred message credits though is not a lot in this case.�
> (In my little trial run, if the broker was filled up before I started�
> the client, it would exhaust the credit - 100 in my case - before�
> revoking it had any effect).
> 
> If you can't handle the messages normally, e.g. if suddenly wherever you�
> are putting can't accept them any more, then you can always release�
> those messages.
> 
Absolutely.

> > With the approach currently taken by proton-j this pattern is effectively
> > impossible to implement and you always end up with handing out only very few
> > credits at a time because the receiver always needs to consider potential
> > resource constraints or congestion that might occur in the future ...
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 18:04, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 16:53, Kai Hudalla wrote:
>
>> If the sender has e.g. 100 credits left and
>> indeed has content to send 100 messages then a drain doesn't prevent him
>> from
>> sending all 100 messages. However, flowing 0 link-credit to the sender
>> has the
>> effect of immediately stopping him (not considering messages in flight, of
>> course). This pattern therefore has the big advantage that a receiver can
>> be
>> generous at first, issuing e.g. 200 credits, in order to reduce the
>> number of
>> flows exchanged while things go well, and then simply stop the sender once
>> resources become more constrained on the receiver side.
>>
>
> While I agree there is a difference between drain and revoking credit,
> even if you issue a flow(0), you still have to handle N messages after
> issuing it, where N is balance at the time you revoked it.
>
> (Since that many messages may already be 'inflight'. As the balance gets
> higher it is more likely that the sender gets the flow before they have
> exhausted the credit of course.)
>
> A couple of hundred message credits though is not a lot in this case. (In
> my little trial run, if the broker was filled up before I started the
> client, it would exhaust the credit - 100 in my case - before revoking it
> had any effect).
>
> If you can't handle the messages normally, e.g. if suddenly wherever you
> are putting can't accept them any more, then you can always release those
> messages.


Only if the sender supports that outcome. It would be nice if standard
clients dealt automatically with a server "releasing" messages by simply
storing them for replay, but I have my doubts as to whether many of them do.

For added complexity, of course, if those messages are sent transactionally
and settled then the "correct" course of action might be to force the
transaction to roll-back. Or one might decide that the simplest course of
action for dealing with senders who breach their credit limits (even if
they didn't know that they had done so) would be to force a disconnection /
reconnection.


-- Rob


>
>
> With the approach currently taken by proton-j this pattern is effectively
>> impossible to implement and you always end up with handing out only very
>> few
>> credits at a time because the receiver always needs to consider potential
>> resource constraints or congestion that might occur in the future ...
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 16:53, Kai Hudalla wrote:
> If the sender has e.g. 100 credits left and
> indeed has content to send 100 messages then a drain doesn't prevent him from
> sending all 100 messages. However, flowing 0 link-credit to the sender has the
> effect of immediately stopping him (not considering messages in flight, of
> course). This pattern therefore has the big advantage that a receiver can be
> generous at first, issuing e.g. 200 credits, in order to reduce the number of
> flows exchanged while things go well, and then simply stop the sender once
> resources become more constrained on the receiver side.

While I agree there is a difference between drain and revoking credit, 
even if you issue a flow(0), you still have to handle N messages after 
issuing it, where N is balance at the time you revoked it.

(Since that many messages may already be 'inflight'. As the balance gets 
higher it is more likely that the sender gets the flow before they have 
exhausted the credit of course.)

A couple of hundred message credits though is not a lot in this case. 
(In my little trial run, if the broker was filled up before I started 
the client, it would exhaust the credit - 100 in my case - before 
revoking it had any effect).

If you can't handle the messages normally, e.g. if suddenly wherever you 
are putting can't accept them any more, then you can always release 
those messages.

> With the approach currently taken by proton-j this pattern is effectively
> impossible to implement and you always end up with handing out only very few
> credits at a time because the receiver always needs to consider potential
> resource constraints or congestion that might occur in the future ...


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 2 March 2017 at 08:56, Kai Hudalla <so...@gmail.com> wrote:

> On Wed, 2017-03-01 at 18:06 +0100, Rob Godfrey wrote:
> > On 1 March 2017 at 17:53, Kai Hudalla <so...@gmail.com> wrote:
> >
> > > On Wed, 2017-03-01 at 15:44 +0000, Robbie Gemmell wrote:
> > > > On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com>
> wrote:
> > > > > On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> > > > > > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com>
> > >
> > > wrote:
> > > > > > >
> > > I do not think that this is true. If the sender has e.g. 100 credits
> left
> > > and
> > > indeed has content to send 100 messages then a drain doesn't prevent
> him
> > > from
> > > sending all 100 messages. However, flowing 0 link-credit to the sender
> has
> > > the
> > > effect of immediately stopping him (not considering messages in
> flight, of
> > > course). This pattern therefore has the big advantage that a receiver
> can
> > > be
> > > generous at first, issuing e.g. 200 credits, in order to reduce the
> number
> > > of
> > > flows exchanged while things go well, and then simply stop the sender
> once
> > > resources become more constrained on the receiver side.
> > >
> > >
> >
> > I don't think your interpretation is correct here.  If the receiver
> issues
> > credit for 100 and the sender has 100 messages, then there is nothing
> > stopping the sender sending all 100 messages before processing the
> incoming
> > flow in either case.
> >
> No, but the semantics are different, i.e. my interpretation of the spec is
> that
> from the point in time the receiver has sent a FLOW with link-credit 0 it
> is
> entitled to do one of the following when more messages come in:
> - either close the link with the sender ("resource-limit-exceeded") or
> - process a certain amount of "in-flight" messages
> in order to behave in a spec compliant way.
>
>
I think we're probably splitting hairs here :-) As the receiver, we cannot
*know* whether the sender will use up all the credit and send all the
messages, even in the stop case (unless we are also using the session
window to also manage flow, and the session window is "smaller" than the
link credit) so we have to treat the two cases identically.  As a sender we
SHOULD treat the cases differently and endeavour to interleave reads and
writes on a connection so that we are always in possession of the most
up-to-date remote state.

I don't think anyone is disputing that sending a 0 link credit is the
"correct" thing to do; just that at the current time there is no safe way
to do that through Proton-J, and that as the receiver of the messages you
can pretty much treat the cases identically (unless you have a stupidly
large link credit and are really using session windows to manage flow).



> However, if flowing 0 link-credits would simply be considered to mean you
> can
> send 0 more messages than your actual link-credit indicates, then the
> receiver
> would need to be prepared to process all of the "outstanding" messages. Of
> course, the receiver can always release any messages but that is clearly
> not the
> intention of introducing a back-pressure method like the flow control
> specified
> in the AMQP 1.0 spec, is it?
>
>
>
As one of the authors of the AMQP spec, obviously I would prefer if the
proton[-j] implementation was capable of fully expressing all the
behaviours we wrote into the spec, however, given where we are, and the
behaviours that current implementations exhibit, using drain appears to be
the only option.

-- Rob


> > Having said that I do think that Proton[-J] should implement reducing
> > available credit (and I imagine so does Robbie - since he raised the JIRA
> > to add this feature) since a resource constrained entity may wish to
> > redistribute/remove credit on links/connections as time passes.
> >
> >
> >
> > > With the approach currently taken by proton-j this pattern is
> effectively
> > > impossible to implement and you always end up with handing out only
> very
> > > few
> > > credits at a time because the receiver always needs to consider
> potential
> > > resource constraints or congestion that might occur in the future ...
> > >
> > > As above, I think you need to do this anyway.
> >
> > -- Rob
> >
> >
> > > > > My understanding of all of this is that a Receiver should not grant
> > >
> > > much
> > > > > credit
> > > > > to a Sender (because it cannot stop the sender once it has started
> > >
> > > sending).
> > > > > Then, when a message is coming in, the receiver should check
> whether
> > >
> > > there is
> > > > > credit left for the sender (using Receiver.getCredit() ?) and if
> not it
> > > > > should
> > > > > grant some more credit using Receiver.flow(small number) again.
> > > > >
> > > > > Does that make sense?
> > > > >
> > > >
> > > > As above, you should grant only as much outstanding credit as you are
> > > > actually willing for a sender to use at a given time. The above would
> > > > be one way to do it. You can also look at getRemoteCredit, which
> takes
> > > > locally-queued deliveries into account as well.
> > > >
> > > > >
> > > > > > > Also, I cannot find the code where the link credit is actually
> > >
> > > updated
> > > > > > > from a
> > > > > > > FLOW received from a Receiver. Can you point me to the right
> class?
> > > > > > >
> > > > > >
> > > > > > TransportSender is probably what you want.
> > > > > >
> > > > > > > Regards,
> > > > > > > Kai
> > > > > > >
> > > > > > > ------------------------------------------------------------
> > >
> > > ---------
> > > > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > > > >
> > > > > >
> > > > > > ------------------------------------------------------------
> > >
> > > ---------
> > > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > > >
> > > > >
> > > > > ------------------------------------------------------------
> ---------
> > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > >
> > > >
> > > > ------------------------------------------------------------
> ---------
> > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > >
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Kai Hudalla <so...@gmail.com>.
On Wed, 2017-03-01 at 18:06 +0100, Rob Godfrey wrote:
> On 1 March 2017 at 17:53, Kai Hudalla <so...@gmail.com> wrote:
> 
> > On Wed, 2017-03-01 at 15:44 +0000, Robbie Gemmell wrote:
> > > On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
> > > > On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> > > > > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com>
> > 
> > wrote:
> > > > > > 
> > I do not think that this is true. If the sender has e.g. 100 credits left
> > and
> > indeed has content to send 100 messages then a drain doesn't prevent him
> > from
> > sending all 100 messages. However, flowing 0 link-credit to the sender has
> > the
> > effect of immediately stopping him (not considering messages in flight, of
> > course). This pattern therefore has the big advantage that a receiver can
> > be
> > generous at first, issuing e.g. 200 credits, in order to reduce the number
> > of
> > flows exchanged while things go well, and then simply stop the sender once
> > resources become more constrained on the receiver side.
> > 
> > 
> 
> I don't think your interpretation is correct here.��If the receiver issues
> credit for 100 and the sender has 100 messages, then there is nothing
> stopping the sender sending all 100 messages before processing the incoming
> flow in either case.
> 
No, but the semantics are different, i.e. my interpretation of the spec is that
from the point in time the receiver has sent a FLOW with link-credit 0 it is
entitled to do one of the following when more messages come in:
- either close the link with the sender ("resource-limit-exceeded") or
- process a certain amount of "in-flight" messages
in order to behave in a spec compliant way.

However, if flowing 0 link-credits would simply be considered to mean you can
send 0 more messages than your actual link-credit indicates, then the receiver
would need to be prepared to process all of the "outstanding" messages. Of
course, the receiver can always release any messages but that is clearly not the
intention of introducing a back-pressure method like the flow control specified
in the AMQP 1.0 spec, is it?


> Having said that I do think that Proton[-J] should implement reducing
> available credit (and I imagine so does Robbie - since he raised the JIRA
> to add this feature) since a resource constrained entity may wish to
> redistribute/remove credit on links/connections as time passes.
> 
> 
> 
> > With the approach currently taken by proton-j this pattern is effectively
> > impossible to implement and you always end up with handing out only very
> > few
> > credits at a time because the receiver always needs to consider potential
> > resource constraints or congestion that might occur in the future ...
> > 
> > As above, I think you need to do this anyway.
> 
> -- Rob
> 
> 
> > > > My understanding of all of this is that a Receiver should not grant
> > 
> > much
> > > > credit
> > > > to a Sender (because it cannot stop the sender once it has started
> > 
> > sending).
> > > > Then, when a message is coming in, the receiver should check whether
> > 
> > there is
> > > > credit left for the sender (using Receiver.getCredit() ?) and if not it
> > > > should
> > > > grant some more credit using Receiver.flow(small number) again.
> > > > 
> > > > Does that make sense?
> > > > 
> > > 
> > > As above, you should grant only as much outstanding credit as you are
> > > actually willing for a sender to use at a given time. The above would
> > > be one way to do it. You can also look at getRemoteCredit, which takes
> > > locally-queued deliveries into account as well.
> > > 
> > > > 
> > > > > > Also, I cannot find the code where the link credit is actually
> > 
> > updated
> > > > > > from a
> > > > > > FLOW received from a Receiver. Can you point me to the right class?
> > > > > > 
> > > > > 
> > > > > TransportSender is probably what you want.
> > > > > 
> > > > > > Regards,
> > > > > > Kai
> > > > > > 
> > > > > > ------------------------------------------------------------
> > 
> > ---------
> > > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > > > 
> > > > > 
> > > > > ------------------------------------------------------------
> > 
> > ---------
> > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > > 
> > > > 
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> > 
> > 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 17:53, Kai Hudalla <so...@gmail.com> wrote:

> On Wed, 2017-03-01 at 15:44 +0000, Robbie Gemmell wrote:
> > On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
> > > On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> > > > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com>
> wrote:
> > > > > Hi,
> > > > >
> > > > > we are working on the Eclipse Hono project where we use
> vertx-proton and
> > > > > (implicitly) proton-j under the hood for exchanging large amounts
> of
> > > > > messages
> > > > > using AMQP 1.0.
> > > > >
> > > > > During our tests I stumbled across the way that proton-j seems to
> handle
> > > > > link-
> > > > > credit being exchanged via FLOWs.
> > > > > My understanding is the following:
> > > > >
> > > > > Assuming that we have a link established between a Receiver (r)
> and a
> > > > > Sender
> > > > > (s)
> > > > > with a current link-credit of 4 and a delivery count of 20 on both
> sides.
> > > > >
> > > > > When invoking r.flow(6), the given credit (6) is _added_ to the
> > > > > receiver's
> > > > > current credit resulting in r.getCredit() returning 10.
> > > > >
> > > > > When the FLOW is then flushed to the sender, the sender seems to
> _add_
> > > > > the
> > > > > link-
> > > > > credit from the FLOW to its already existing credit. Analogously,
> this
> > > > > results in
> > > > > s.getCredit() now returning 10.
> > > >
> > > > Correct. In proton the flow(credits) method grants additional
> credits.
> > > >
> > > > >
> > > > > With this approach, it doesn't seem to be possible to stop the
> sender
> > > > > from
> > > > > sending messages. The only thing a receiver can do is to wait
> until the
> > > > > sender
> > > > > has used up all its credit (which may be a lot given that with the
> > > > > current
> > > > > approach the sender's credit can pile up substantially).
> > > > >
> > > > > Or am I mistaken?
> > > >
> > > > Granting credits is essentially giving the sender ability to send
> that
> > > > many messages. If you are controlling credit, any 'pile up' of credit
> > > > at the sender is one that you create yourself - if you dont want the
> > > > sender to be able to send more than a certain number of messages at a
> > > > given time, dont allow more than that number of credits to be
> > > > outstanding at the time.
> > >
> > > So, still, there is no way to stop a sender from sending once it has
> credit
> > > and
> > > wants to send messages, right? My understanding of the AMQP 1.0 spec
> is that
> > > it
> > > should be possible to do so by flowing a link-credit of 0 to the
> sender.
> > >
> >
> > Correct, it does. Proton doesnt really support reducing credit.
> >
> > https://issues.apache.org/jira/browse/PROTON-796
> >
> > > >
> > > > One thing you may not be aware of is you can drain the link of
> > > > existing credit, which essentially asks the sender to send what they
> > > > can (something they typically will have already done if they have
> > > > credit and anything to send) then spontaneously advance the delivery
> > > > count to the extent needed to use up all outstanding credit.
> > > >
> > >
> > > I am aware of this but it also doesn't help with stopping a sender
> that is
> > > already sending, does it?
> > >
> >
> > To a large extent its little different than setting credit to 0; if a
> > sender already has credit and content to send you then they can
> > already send it, and are likely to do so before receiving a flow frame
> > setting credit back to 0.
> >
>
> I do not think that this is true. If the sender has e.g. 100 credits left
> and
> indeed has content to send 100 messages then a drain doesn't prevent him
> from
> sending all 100 messages. However, flowing 0 link-credit to the sender has
> the
> effect of immediately stopping him (not considering messages in flight, of
> course). This pattern therefore has the big advantage that a receiver can
> be
> generous at first, issuing e.g. 200 credits, in order to reduce the number
> of
> flows exchanged while things go well, and then simply stop the sender once
> resources become more constrained on the receiver side.
>
>
I don't think your interpretation is correct here.  If the receiver issues
credit for 100 and the sender has 100 messages, then there is nothing
stopping the sender sending all 100 messages before processing the incoming
flow in either case.

Having said that I do think that Proton[-J] should implement reducing
available credit (and I imagine so does Robbie - since he raised the JIRA
to add this feature) since a resource constrained entity may wish to
redistribute/remove credit on links/connections as time passes.



> With the approach currently taken by proton-j this pattern is effectively
> impossible to implement and you always end up with handing out only very
> few
> credits at a time because the receiver always needs to consider potential
> resource constraints or congestion that might occur in the future ...
>
> As above, I think you need to do this anyway.

-- Rob


> > > My understanding of all of this is that a Receiver should not grant
> much
> > > credit
> > > to a Sender (because it cannot stop the sender once it has started
> sending).
> > > Then, when a message is coming in, the receiver should check whether
> there is
> > > credit left for the sender (using Receiver.getCredit() ?) and if not it
> > > should
> > > grant some more credit using Receiver.flow(small number) again.
> > >
> > > Does that make sense?
> > >
> >
> > As above, you should grant only as much outstanding credit as you are
> > actually willing for a sender to use at a given time. The above would
> > be one way to do it. You can also look at getRemoteCredit, which takes
> > locally-queued deliveries into account as well.
> >
> > >
> > > > > Also, I cannot find the code where the link credit is actually
> updated
> > > > > from a
> > > > > FLOW received from a Receiver. Can you point me to the right class?
> > > > >
> > > >
> > > > TransportSender is probably what you want.
> > > >
> > > > > Regards,
> > > > > Kai
> > > > >
> > > > > ------------------------------------------------------------
> ---------
> > > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > >
> > > >
> > > > ------------------------------------------------------------
> ---------
> > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Kai Hudalla <so...@gmail.com>.
On Wed, 2017-03-01 at 15:44 +0000, Robbie Gemmell wrote:
> On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
> > On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> > > On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
> > > > Hi,
> > > > 
> > > > we are working on the Eclipse Hono project where we use vertx-proton and
> > > > (implicitly) proton-j under the hood for exchanging large amounts of
> > > > messages
> > > > using AMQP 1.0.
> > > > 
> > > > During our tests I stumbled across the way that proton-j seems to handle
> > > > link-
> > > > credit being exchanged via FLOWs.
> > > > My understanding is the following:
> > > > 
> > > > Assuming that we have a link established between a Receiver (r) and a
> > > > Sender
> > > > (s)
> > > > with a current link-credit of 4 and a delivery count of 20 on both sides.
> > > > 
> > > > When invoking r.flow(6), the given credit (6) is _added_ to the
> > > > receiver's
> > > > current credit resulting in r.getCredit() returning 10.
> > > > 
> > > > When the FLOW is then flushed to the sender, the sender seems to _add_
> > > > the
> > > > link-
> > > > credit from the FLOW to its already existing credit. Analogously, this
> > > > results in
> > > > s.getCredit() now returning 10.
> > > 
> > > Correct. In proton the flow(credits) method grants additional credits.
> > > 
> > > > 
> > > > With this approach, it doesn't seem to be possible to stop the sender
> > > > from
> > > > sending messages. The only thing a receiver can do is to wait until the
> > > > sender
> > > > has used up all its credit (which may be a lot given that with the
> > > > current
> > > > approach the sender's credit can pile up substantially).
> > > > 
> > > > Or am I mistaken?
> > > 
> > > Granting credits is essentially giving the sender ability to send that
> > > many messages. If you are controlling credit, any 'pile up' of credit
> > > at the sender is one that you create yourself - if you dont want the
> > > sender to be able to send more than a certain number of messages at a
> > > given time, dont allow more than that number of credits to be
> > > outstanding at the time.
> > 
> > So, still, there is no way to stop a sender from sending once it has credit
> > and
> > wants to send messages, right? My understanding of the AMQP 1.0 spec is that
> > it
> > should be possible to do so by flowing a link-credit of 0 to the sender.
> > 
> 
> Correct, it does. Proton doesnt really support reducing credit.
> 
> https://issues.apache.org/jira/browse/PROTON-796
> 
> > > 
> > > One thing you may not be aware of is you can drain the link of
> > > existing credit, which essentially asks the sender to send what they
> > > can (something they typically will have already done if they have
> > > credit and anything to send) then spontaneously advance the delivery
> > > count to the extent needed to use up all outstanding credit.
> > > 
> > 
> > I am aware of this but it also doesn't help with stopping a sender that is
> > already sending, does it?
> > 
> 
> To a large extent its little different than setting credit to 0; if a
> sender already has credit and content to send you then they can
> already send it, and are likely to do so before receiving a flow frame
> setting credit back to 0.
> 

I do not think that this is true. If the sender has e.g. 100 credits left and
indeed has content to send 100 messages then a drain doesn't prevent him from
sending all 100 messages. However, flowing 0 link-credit to the sender has the
effect of immediately stopping him (not considering messages in flight, of
course). This pattern therefore has the big advantage that a receiver can be
generous at first, issuing e.g. 200 credits, in order to reduce the number of
flows exchanged while things go well, and then simply stop the sender once
resources become more constrained on the receiver side.

With the approach currently taken by proton-j this pattern is effectively
impossible to implement and you always end up with handing out only very few
credits at a time because the receiver always needs to consider potential
resource constraints or congestion that might occur in the future ...

> > My understanding of all of this is that a Receiver should not grant much
> > credit
> > to a Sender (because it cannot stop the sender once it has started sending).
> > Then, when a message is coming in, the receiver should check whether there is
> > credit left for the sender (using Receiver.getCredit() ?) and if not it
> > should
> > grant some more credit using Receiver.flow(small number) again.
> > 
> > Does that make sense?
> > 
> 
> As above, you should grant only as much outstanding credit as you are
> actually willing for a sender to use at a given time. The above would
> be one way to do it. You can also look at getRemoteCredit, which takes
> locally-queued deliveries into account as well.
> 
> > 
> > > > Also, I cannot find the code where the link credit is actually updated
> > > > from a
> > > > FLOW received from a Receiver. Can you point me to the right class?
> > > > 
> > > 
> > > TransportSender is probably what you want.
> > > 
> > > > Regards,
> > > > Kai
> > > > 
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > > For additional commands, e-mail: users-help@qpid.apache.org
> > > > 
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > > For additional commands, e-mail: users-help@qpid.apache.org
> > > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 15:29, Kai Hudalla <so...@gmail.com> wrote:
> On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
>> On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
>> > Hi,
>> >
>> > we are working on the Eclipse Hono project where we use vertx-proton and
>> > (implicitly) proton-j under the hood for exchanging large amounts of messages
>> > using AMQP 1.0.
>> >
>> > During our tests I stumbled across the way that proton-j seems to handle
>> > link-
>> > credit being exchanged via FLOWs.
>> > My understanding is the following:
>> >
>> > Assuming that we have a link established between a Receiver (r) and a Sender
>> > (s)
>> > with a current link-credit of 4 and a delivery count of 20 on both sides.
>> >
>> > When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
>> > current credit resulting in r.getCredit() returning 10.
>> >
>> > When the FLOW is then flushed to the sender, the sender seems to _add_ the
>> > link-
>> > credit from the FLOW to its already existing credit. Analogously, this
>> > results in
>> > s.getCredit() now returning 10.
>>
>> Correct. In proton the flow(credits) method grants additional credits.
>>
>> >
>> > With this approach, it doesn't seem to be possible to stop the sender from
>> > sending messages. The only thing a receiver can do is to wait until the
>> > sender
>> > has used up all its credit (which may be a lot given that with the current
>> > approach the sender's credit can pile up substantially).
>> >
>> > Or am I mistaken?
>>
>> Granting credits is essentially giving the sender ability to send that
>> many messages. If you are controlling credit, any 'pile up' of credit
>> at the sender is one that you create yourself - if you dont want the
>> sender to be able to send more than a certain number of messages at a
>> given time, dont allow more than that number of credits to be
>> outstanding at the time.
>
> So, still, there is no way to stop a sender from sending once it has credit and
> wants to send messages, right? My understanding of the AMQP 1.0 spec is that it
> should be possible to do so by flowing a link-credit of 0 to the sender.
>

Correct, it does. Proton doesnt really support reducing credit.

https://issues.apache.org/jira/browse/PROTON-796

>>
>> One thing you may not be aware of is you can drain the link of
>> existing credit, which essentially asks the sender to send what they
>> can (something they typically will have already done if they have
>> credit and anything to send) then spontaneously advance the delivery
>> count to the extent needed to use up all outstanding credit.
>>
>
> I am aware of this but it also doesn't help with stopping a sender that is
> already sending, does it?
>

To a large extent its little different than setting credit to 0; if a
sender already has credit and content to send you then they can
already send it, and are likely to do so before receiving a flow frame
setting credit back to 0.

> My understanding of all of this is that a Receiver should not grant much credit
> to a Sender (because it cannot stop the sender once it has started sending).
> Then, when a message is coming in, the receiver should check whether there is
> credit left for the sender (using Receiver.getCredit() ?) and if not it should
> grant some more credit using Receiver.flow(small number) again.
>
> Does that make sense?
>

As above, you should grant only as much outstanding credit as you are
actually willing for a sender to use at a given time. The above would
be one way to do it. You can also look at getRemoteCredit, which takes
locally-queued deliveries into account as well.

>
>> > Also, I cannot find the code where the link credit is actually updated from a
>> > FLOW received from a Receiver. Can you point me to the right class?
>> >
>>
>> TransportSender is probably what you want.
>>
>> > Regards,
>> > Kai
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> > For additional commands, e-mail: users-help@qpid.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Kai Hudalla <so...@gmail.com>.
On Wed, 2017-03-01 at 15:07 +0000, Robbie Gemmell wrote:
> On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
> > Hi,
> > 
> > we are working on the Eclipse Hono project where we use vertx-proton and
> > (implicitly) proton-j under the hood for exchanging large amounts of messages
> > using AMQP 1.0.
> > 
> > During our tests I stumbled across the way that proton-j seems to handle
> > link-
> > credit being exchanged via FLOWs.
> > My understanding is the following:
> > 
> > Assuming that we have a link established between a Receiver (r) and a Sender
> > (s)
> > with a current link-credit of 4 and a delivery count of 20 on both sides.
> > 
> > When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
> > current credit resulting in r.getCredit() returning 10.
> > 
> > When the FLOW is then flushed to the sender, the sender seems to _add_ the
> > link-
> > credit from the FLOW to its already existing credit. Analogously, this
> > results in
> > s.getCredit() now returning 10.
> 
> Correct. In proton the flow(credits) method grants additional credits.
> 
> > 
> > With this approach, it doesn't seem to be possible to stop the sender from
> > sending messages. The only thing a receiver can do is to wait until the
> > sender
> > has used up all its credit (which may be a lot given that with the current
> > approach the sender's credit can pile up substantially).
> > 
> > Or am I mistaken?
> 
> Granting credits is essentially giving the sender ability to send that
> many messages. If you are controlling credit, any 'pile up' of credit
> at the sender is one that you create yourself - if you dont want the
> sender to be able to send more than a certain number of messages at a
> given time, dont allow more than that number of credits to be
> outstanding at the time.

So, still, there is no way to stop a sender from sending once it has credit and
wants to send messages, right? My understanding of the AMQP 1.0 spec is that it
should be possible to do so by flowing a link-credit of 0 to the sender.

> 
> One thing you may not be aware of is you can drain the link of
> existing credit, which essentially asks the sender to send what they
> can (something they typically will have already done if they have
> credit and anything to send) then spontaneously advance the delivery
> count to the extent needed to use up all outstanding credit.
> 

I am aware of this but it also doesn't help with stopping a sender that is
already sending, does it?

My understanding of all of this is that a Receiver should not grant much credit
to a Sender (because it cannot stop the sender once it has started sending). 
Then, when a message is coming in, the receiver should check whether there is
credit left for the sender (using Receiver.getCredit() ?) and if not it should
grant some more credit using Receiver.flow(small number) again.

Does that make sense?


> > Also, I cannot find the code where the link credit is actually updated from a
> > FLOW received from a Receiver. Can you point me to the right class?
> > 
> 
> TransportSender is probably what you want.
> 
> > Regards,
> > Kai
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 14:31, Kai Hudalla <so...@gmail.com> wrote:
> Hi,
>
> we are working on the Eclipse Hono project where we use vertx-proton and
> (implicitly) proton-j under the hood for exchanging large amounts of messages
> using AMQP 1.0.
>
> During our tests I stumbled across the way that proton-j seems to handle link-
> credit being exchanged via FLOWs.
> My understanding is the following:
>
> Assuming that we have a link established between a Receiver (r) and a Sender (s)
> with a current link-credit of 4 and a delivery count of 20 on both sides.
>
> When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
> current credit resulting in r.getCredit() returning 10.
>
> When the FLOW is then flushed to the sender, the sender seems to _add_ the link-
> credit from the FLOW to its already existing credit. Analogously, this results in
> s.getCredit() now returning 10.

Correct. In proton the flow(credits) method grants additional credits.

>
> With this approach, it doesn't seem to be possible to stop the sender from
> sending messages. The only thing a receiver can do is to wait until the sender
> has used up all its credit (which may be a lot given that with the current
> approach the sender's credit can pile up substantially).
>
> Or am I mistaken?

Granting credits is essentially giving the sender ability to send that
many messages. If you are controlling credit, any 'pile up' of credit
at the sender is one that you create yourself - if you dont want the
sender to be able to send more than a certain number of messages at a
given time, dont allow more than that number of credits to be
outstanding at the time.

One thing you may not be aware of is you can drain the link of
existing credit, which essentially asks the sender to send what they
can (something they typically will have already done if they have
credit and anything to send) then spontaneously advance the delivery
count to the extent needed to use up all outstanding credit.

>
> Also, I cannot find the code where the link credit is actually updated from a
> FLOW received from a Receiver. Can you point me to the right class?
>

TransportSender is probably what you want.

> Regards,
> Kai
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 22:22, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 21:18, Rob Godfrey wrote:
>
>> My gut feeling says that the library (Proton) should detect the error if
>> it
>> can determine that the other party has sent beyond any limit it might
>> possibly still believe to be true... which (in the simplest form) might
>> just mean retaining a high watermark of acceptable delivery count...  I
>> don't personally think we should be expecting the application to write
>> logic to detect ill behaving producers... but I'm not sure what the
>> original intent of Proton was here.
>>
>
> I agree. I had assumed (but never explicitly verified) that proton-c did
> that.


Looking through the Proton-J code I cannot immediately see anywhere that
would do this... and if there is something then it certainly isn't using
the correct error (amqp:link:transfer-limit-exceeded) as I can see that
other than being defined in a constant, this is not used anywhere within
the Proton-J code :-(

-- Rob


>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 21:18, Rob Godfrey wrote:
> My gut feeling says that the library (Proton) should detect the error if it
> can determine that the other party has sent beyond any limit it might
> possibly still believe to be true... which (in the simplest form) might
> just mean retaining a high watermark of acceptable delivery count...  I
> don't personally think we should be expecting the application to write
> logic to detect ill behaving producers... but I'm not sure what the
> original intent of Proton was here.

I agree. I had assumed (but never explicitly verified) that proton-c did 
that.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 22:13, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 21:09, Rob Godfrey wrote:
>
>> On 1 March 2017 at 19:28, Gordon Sim <gs...@redhat.com> wrote:
>>
>> On 01/03/17 18:14, Rob Godfrey wrote:
>>>
>>> The link credit is an absolute value on the wire... but proton presents
>>>> it
>>>> in relative terms.  If you had 500 units of credit outstanding and
>>>> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
>>>> after that point... what state is your link credit in in Proton?
>>>>
>>>>
>>> I would expect it to be 0.
>>>
>>> Does it
>>>
>>>> make a difference if those 5 messages had been processed by Proton (but
>>>> not
>>>> received by the application) before the flow(2) was sent or not?
>>>>
>>>>
>>> Yes, if the flow(2) was issued after the 5 messages were processed, I
>>> would expect the credit to be 2.
>>>
>>>
>>>
>>> OK - so do we ever expect Proton to cry foul if the sender sends beyond
>> any
>> credit that it could reasonably be expected to have seen - or would we
>> leave this up to the application to detect?
>>
>
> That's a good question. I ran the test to see what would happen, half
> expecting proton to end the link with an error. If it does nothing at all
> to enforce the credit limit (even when not revoking previously granted
> credit), that is probably a concern. Would need a more involved test to
> determine that.
>
>
My gut feeling says that the library (Proton) should detect the error if it
can determine that the other party has sent beyond any limit it might
possibly still believe to be true... which (in the simplest form) might
just mean retaining a high watermark of acceptable delivery count...  I
don't personally think we should be expecting the application to write
logic to detect ill behaving producers... but I'm not sure what the
original intent of Proton was here.

-- Rob


>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 21:09, Rob Godfrey wrote:
> On 1 March 2017 at 19:28, Gordon Sim <gs...@redhat.com> wrote:
>
>> On 01/03/17 18:14, Rob Godfrey wrote:
>>
>>> The link credit is an absolute value on the wire... but proton presents it
>>> in relative terms.  If you had 500 units of credit outstanding and
>>> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
>>> after that point... what state is your link credit in in Proton?
>>>
>>
>> I would expect it to be 0.
>>
>> Does it
>>> make a difference if those 5 messages had been processed by Proton (but
>>> not
>>> received by the application) before the flow(2) was sent or not?
>>>
>>
>> Yes, if the flow(2) was issued after the 5 messages were processed, I
>> would expect the credit to be 2.
>>
>>
>>
> OK - so do we ever expect Proton to cry foul if the sender sends beyond any
> credit that it could reasonably be expected to have seen - or would we
> leave this up to the application to detect?

That's a good question. I ran the test to see what would happen, half 
expecting proton to end the link with an error. If it does nothing at 
all to enforce the credit limit (even when not revoking previously 
granted credit), that is probably a concern. Would need a more involved 
test to determine that.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 19:28, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 18:14, Rob Godfrey wrote:
>
>> The link credit is an absolute value on the wire... but proton presents it
>> in relative terms.  If you had 500 units of credit outstanding and
>> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
>> after that point... what state is your link credit in in Proton?
>>
>
> I would expect it to be 0.
>
> Does it
>> make a difference if those 5 messages had been processed by Proton (but
>> not
>> received by the application) before the flow(2) was sent or not?
>>
>
> Yes, if the flow(2) was issued after the 5 messages were processed, I
> would expect the credit to be 2.
>
>
>
OK - so do we ever expect Proton to cry foul if the sender sends beyond any
credit that it could reasonably be expected to have seen - or would we
leave this up to the application to detect?

-- Rob


>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 2 March 2017 at 13:59, Rob Godfrey <ro...@gmail.com> wrote:
> On 2 March 2017 at 13:34, Robbie Gemmell <ro...@gmail.com> wrote:
>
>> On 2 March 2017 at 12:06, Rob Godfrey <ro...@gmail.com> wrote:
>> > On 2 March 2017 at 12:56, Robbie Gemmell <ro...@gmail.com>
>> wrote:
>> >
>> >> On 1 March 2017 at 18:28, Gordon Sim <gs...@redhat.com> wrote:
>> >> > On 01/03/17 18:14, Rob Godfrey wrote:
>> >> >>
>> >> >> The link credit is an absolute value on the wire... but proton
>> presents
>> >> it
>> >> >> in relative terms.  If you had 500 units of credit outstanding and
>> >> >> flow(-500) and then flow(2), and you get 5 messages on the wire
>> arriving
>> >> >> after that point... what state is your link credit in in Proton?
>> >> >
>> >> >
>> >> > I would expect it to be 0.
>> >> >
>> >> >> Does it
>> >> >> make a difference if those 5 messages had been processed by Proton
>> (but
>> >> >> not
>> >> >> received by the application) before the flow(2) was sent or not?
>> >> >
>> >> >
>> >> > Yes, if the flow(2) was issued after the 5 messages were processed, I
>> >> would
>> >> > expect the credit to be 2.
>> >> >
>> >>
>> >> I think we need to be clearer what we mean by 'in proton' when
>> >> discussing this - at the application level, or the transport/wire
>> >> level, and before or after the application processes received
>> >> messages, as these are all potentially in different states /
>> >> presenting different views/values for credit at a given time. Indeed
>> >> doing any of this inside e.g the container/reactor will often give a
>> >> different result than it would in e.g the JMS client, since the
>> >> effects of operations will actually occur at different times.
>> >>
>> >> I'm not sure most of them will currently match your expectations,
>> >> credit will actually end up negative in a lot of them. Note in your
>> >> example, when the timer refreshed credit by doing flow(100) the link
>> >> credit on the wire actually went to 74, because 3 messages were
>> >> received/buffered and processed at the receiver before it actually
>> >> sent the flow reducing credit to 0, then 26 in flight were processed
>> >> after, making credit end up at -26 once they were all processed,
>> >> giving an effective 74 later when the flow(100) occurred to 'add 100'
>> >> credits.
>> >>
>> >> Ignore proton for a minute and consider the following at a protocol
>> >> level. If as a sender you get a flow saying delivery-count is 0 and
>> >> credit is 100, and send 50 messages in-flight, then get a flow
>> >> indicating delivery-count is 10 and credit is 0, then receive a flow
>> >> indicating delivery-count is 20 and credit is 10, what is your actual
>> >> credit at the sender and receiver when all is done?
>> >
>> >
>> >
>> > So at this point I would say that the sender considers credit to be 0
>> > (there's no point in the sender trying to store a negative link-credit
>> > amount), at the receiver the link credit is (the most recent
>> delivery-count
>> > it saw from the sender) - 30 (this value may be negative).
>> >
>>
>> The spec seems to say it MUST go negative at the sender. From
>> http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-
>> transport-v1.0-os.html#doc-flow-control
>> on link credit:
>>
>> "The sender's value MUST always be maintained in such a way as to
>> match the delivery-limit identified by the receiver. This means that
>> the sender's link-credit variable MUST be set according to this
>> formula when flow information is given by the receiver:
>>
>> link-creditsnd := delivery-countrcv + link-creditrcv - delivery-countsnd. "
>>
>> So in this case the the receivers last known delivery count was 20,
>> and the credit was 10, and the senders delivery count was already 50
>> at that point. This makes the senders credit -20 (not -30 as I
>> incorrectly stated below because I cant count, and the sender
>> delivery-count was only 20 beyond what it could ever become based on
>> the flow).
>>
>> So the sender sees -20 credit as soon as the flow arrives saying 10,
>> and the receiver ends up seeing -20 once it sees(/processes) all the
>> messages.
>>
>>
> Theoretically this may be correct, however obviously the credit value on
> the wire is a uint, so it can't actually be negative.

True, I was meaning the effective/stored/calculated value, not the
wire value...much like the spec talks of it being less than zero when
as you note it never can be on the wire.

>  If the receiver has
> sent a flow with echo=true then I would expect the sender to respond with a
> flow with the accurate delivery count and a link-credit of 0.

In the scenario I wasnt meaning for the 0 credit flow to have an echo,
since we cant do that currently, and thats why it didnt wait for the
sender to hit 0 credit before sending the next flow, in part to
show/put it in position where I see issue with how this would
currently behave.

If it did support echo, I'm not sure it would reply with credit of 0 currently.

> Given that
> the effect of -ve credit and zero credit would seem to be identical I don't
> think it really matters what the sender stores internally ... though using
> 0 would allow the library to store the credit value in a uint and not have
> to futz with the stored value every time it echoes the flow state on the
> wire.

I agree. Proton doesn't look to take either approach currently however.

>
> -- Rob
>
>>
>> >> The receivers last
>> >> flow had just said credit is 10, but the senders delivery-count is
>> >> already 30 beyond what it could ever become based on that flow, so
>> >> credit should actually be -30 at the sender now. The receiver also
>> >> doesn't just end up at 0 after getting 10 more messages based on its
>> >> last flow, and instead has to cope (or fall over and close the link)
>> >> when an additional 20 more messages arrive than it seemingly just gave
>> >> credit for; despite having previously reduced credit from 100 to 0 and
>> >> increasing it back to 10 after receiving 20 messages, 30 more messages
>> >> arrived since it never found out if the reduction to 0 took effect and
>> >> it turns out that 50 (or even up to 100) were sent using the original
>> >> credit before it adjusted the credit twice more. Suppose we say that
>> >> the receiver actually successfully processes all 50 messages despite
>> >> that, this makes its delivery-count now 50 as well, what is its
>> >> credit?
>> >>
>> >>
>> > I think here there are two separate considerations... On the wire I would
>> > think that the receiver should update its delivery count to reflect the
>> > last received delivery from the sender (unless it just decides to tear
>> down
>> > the link), and I would expect that the link-credit at this point would be
>> > zero.
>>
>> That would be fine I think, though it doenst currently do this, and to
>> your point below it would be interesting when to if it did. Currently
>> at the application level, it doesnt see credit go negative until it
>> processes enough messages to make it do so, with unprocessed messages
>> being 'queued' and not yet reflected in credit views. The transport
>> level does I think consider the credit reduced as soon as they fully
>> arrive.
>>
>> >
>> > More interesting to me is how we handle this in the interaction between
>> the
>> > library and application layers.  Does the application layer have to issue
>> > more credit before the library presents the deliveries to it (even though
>> > the library is already holding the deliveries).  If not then does the
>> > application layer have to issue retrospective credits in order to start
>> > receiving new messages?
>> >
>> > I'm not sure the accounting part is hard... it's getting the API right
>> that
>> > seems more tricky to me.
>> >
>> > -- Rob
>> >
>> >
>> >>
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> >> > For additional commands, e-mail: users-help@qpid.apache.org
>> >> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> >> For additional commands, e-mail: users-help@qpid.apache.org
>> >>
>> >>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 2 March 2017 at 13:34, Robbie Gemmell <ro...@gmail.com> wrote:

> On 2 March 2017 at 12:06, Rob Godfrey <ro...@gmail.com> wrote:
> > On 2 March 2017 at 12:56, Robbie Gemmell <ro...@gmail.com>
> wrote:
> >
> >> On 1 March 2017 at 18:28, Gordon Sim <gs...@redhat.com> wrote:
> >> > On 01/03/17 18:14, Rob Godfrey wrote:
> >> >>
> >> >> The link credit is an absolute value on the wire... but proton
> presents
> >> it
> >> >> in relative terms.  If you had 500 units of credit outstanding and
> >> >> flow(-500) and then flow(2), and you get 5 messages on the wire
> arriving
> >> >> after that point... what state is your link credit in in Proton?
> >> >
> >> >
> >> > I would expect it to be 0.
> >> >
> >> >> Does it
> >> >> make a difference if those 5 messages had been processed by Proton
> (but
> >> >> not
> >> >> received by the application) before the flow(2) was sent or not?
> >> >
> >> >
> >> > Yes, if the flow(2) was issued after the 5 messages were processed, I
> >> would
> >> > expect the credit to be 2.
> >> >
> >>
> >> I think we need to be clearer what we mean by 'in proton' when
> >> discussing this - at the application level, or the transport/wire
> >> level, and before or after the application processes received
> >> messages, as these are all potentially in different states /
> >> presenting different views/values for credit at a given time. Indeed
> >> doing any of this inside e.g the container/reactor will often give a
> >> different result than it would in e.g the JMS client, since the
> >> effects of operations will actually occur at different times.
> >>
> >> I'm not sure most of them will currently match your expectations,
> >> credit will actually end up negative in a lot of them. Note in your
> >> example, when the timer refreshed credit by doing flow(100) the link
> >> credit on the wire actually went to 74, because 3 messages were
> >> received/buffered and processed at the receiver before it actually
> >> sent the flow reducing credit to 0, then 26 in flight were processed
> >> after, making credit end up at -26 once they were all processed,
> >> giving an effective 74 later when the flow(100) occurred to 'add 100'
> >> credits.
> >>
> >> Ignore proton for a minute and consider the following at a protocol
> >> level. If as a sender you get a flow saying delivery-count is 0 and
> >> credit is 100, and send 50 messages in-flight, then get a flow
> >> indicating delivery-count is 10 and credit is 0, then receive a flow
> >> indicating delivery-count is 20 and credit is 10, what is your actual
> >> credit at the sender and receiver when all is done?
> >
> >
> >
> > So at this point I would say that the sender considers credit to be 0
> > (there's no point in the sender trying to store a negative link-credit
> > amount), at the receiver the link credit is (the most recent
> delivery-count
> > it saw from the sender) - 30 (this value may be negative).
> >
>
> The spec seems to say it MUST go negative at the sender. From
> http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-
> transport-v1.0-os.html#doc-flow-control
> on link credit:
>
> "The sender's value MUST always be maintained in such a way as to
> match the delivery-limit identified by the receiver. This means that
> the sender's link-credit variable MUST be set according to this
> formula when flow information is given by the receiver:
>
> link-creditsnd := delivery-countrcv + link-creditrcv - delivery-countsnd. "
>
> So in this case the the receivers last known delivery count was 20,
> and the credit was 10, and the senders delivery count was already 50
> at that point. This makes the senders credit -20 (not -30 as I
> incorrectly stated below because I cant count, and the sender
> delivery-count was only 20 beyond what it could ever become based on
> the flow).
>
> So the sender sees -20 credit as soon as the flow arrives saying 10,
> and the receiver ends up seeing -20 once it sees(/processes) all the
> messages.
>
>
Theoretically this may be correct, however obviously the credit value on
the wire is a uint, so it can't actually be negative.  If the receiver has
sent a flow with echo=true then I would expect the sender to respond with a
flow with the accurate delivery count and a link-credit of 0.  Given that
the effect of -ve credit and zero credit would seem to be identical I don't
think it really matters what the sender stores internally ... though using
0 would allow the library to store the credit value in a uint and not have
to futz with the stored value every time it echoes the flow state on the
wire.

-- Rob

>
> >> The receivers last
> >> flow had just said credit is 10, but the senders delivery-count is
> >> already 30 beyond what it could ever become based on that flow, so
> >> credit should actually be -30 at the sender now. The receiver also
> >> doesn't just end up at 0 after getting 10 more messages based on its
> >> last flow, and instead has to cope (or fall over and close the link)
> >> when an additional 20 more messages arrive than it seemingly just gave
> >> credit for; despite having previously reduced credit from 100 to 0 and
> >> increasing it back to 10 after receiving 20 messages, 30 more messages
> >> arrived since it never found out if the reduction to 0 took effect and
> >> it turns out that 50 (or even up to 100) were sent using the original
> >> credit before it adjusted the credit twice more. Suppose we say that
> >> the receiver actually successfully processes all 50 messages despite
> >> that, this makes its delivery-count now 50 as well, what is its
> >> credit?
> >>
> >>
> > I think here there are two separate considerations... On the wire I would
> > think that the receiver should update its delivery count to reflect the
> > last received delivery from the sender (unless it just decides to tear
> down
> > the link), and I would expect that the link-credit at this point would be
> > zero.
>
> That would be fine I think, though it doenst currently do this, and to
> your point below it would be interesting when to if it did. Currently
> at the application level, it doesnt see credit go negative until it
> processes enough messages to make it do so, with unprocessed messages
> being 'queued' and not yet reflected in credit views. The transport
> level does I think consider the credit reduced as soon as they fully
> arrive.
>
> >
> > More interesting to me is how we handle this in the interaction between
> the
> > library and application layers.  Does the application layer have to issue
> > more credit before the library presents the deliveries to it (even though
> > the library is already holding the deliveries).  If not then does the
> > application layer have to issue retrospective credits in order to start
> > receiving new messages?
> >
> > I'm not sure the accounting part is hard... it's getting the API right
> that
> > seems more tricky to me.
> >
> > -- Rob
> >
> >
> >>
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> >> > For additional commands, e-mail: users-help@qpid.apache.org
> >> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> >> For additional commands, e-mail: users-help@qpid.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 2 March 2017 at 12:06, Rob Godfrey <ro...@gmail.com> wrote:
> On 2 March 2017 at 12:56, Robbie Gemmell <ro...@gmail.com> wrote:
>
>> On 1 March 2017 at 18:28, Gordon Sim <gs...@redhat.com> wrote:
>> > On 01/03/17 18:14, Rob Godfrey wrote:
>> >>
>> >> The link credit is an absolute value on the wire... but proton presents
>> it
>> >> in relative terms.  If you had 500 units of credit outstanding and
>> >> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
>> >> after that point... what state is your link credit in in Proton?
>> >
>> >
>> > I would expect it to be 0.
>> >
>> >> Does it
>> >> make a difference if those 5 messages had been processed by Proton (but
>> >> not
>> >> received by the application) before the flow(2) was sent or not?
>> >
>> >
>> > Yes, if the flow(2) was issued after the 5 messages were processed, I
>> would
>> > expect the credit to be 2.
>> >
>>
>> I think we need to be clearer what we mean by 'in proton' when
>> discussing this - at the application level, or the transport/wire
>> level, and before or after the application processes received
>> messages, as these are all potentially in different states /
>> presenting different views/values for credit at a given time. Indeed
>> doing any of this inside e.g the container/reactor will often give a
>> different result than it would in e.g the JMS client, since the
>> effects of operations will actually occur at different times.
>>
>> I'm not sure most of them will currently match your expectations,
>> credit will actually end up negative in a lot of them. Note in your
>> example, when the timer refreshed credit by doing flow(100) the link
>> credit on the wire actually went to 74, because 3 messages were
>> received/buffered and processed at the receiver before it actually
>> sent the flow reducing credit to 0, then 26 in flight were processed
>> after, making credit end up at -26 once they were all processed,
>> giving an effective 74 later when the flow(100) occurred to 'add 100'
>> credits.
>>
>> Ignore proton for a minute and consider the following at a protocol
>> level. If as a sender you get a flow saying delivery-count is 0 and
>> credit is 100, and send 50 messages in-flight, then get a flow
>> indicating delivery-count is 10 and credit is 0, then receive a flow
>> indicating delivery-count is 20 and credit is 10, what is your actual
>> credit at the sender and receiver when all is done?
>
>
>
> So at this point I would say that the sender considers credit to be 0
> (there's no point in the sender trying to store a negative link-credit
> amount), at the receiver the link credit is (the most recent delivery-count
> it saw from the sender) - 30 (this value may be negative).
>

The spec seems to say it MUST go negative at the sender. From
http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#doc-flow-control
on link credit:

"The sender's value MUST always be maintained in such a way as to
match the delivery-limit identified by the receiver. This means that
the sender's link-credit variable MUST be set according to this
formula when flow information is given by the receiver:

link-creditsnd := delivery-countrcv + link-creditrcv - delivery-countsnd. "

So in this case the the receivers last known delivery count was 20,
and the credit was 10, and the senders delivery count was already 50
at that point. This makes the senders credit -20 (not -30 as I
incorrectly stated below because I cant count, and the sender
delivery-count was only 20 beyond what it could ever become based on
the flow).

So the sender sees -20 credit as soon as the flow arrives saying 10,
and the receiver ends up seeing -20 once it sees(/processes) all the
messages.

>
>> The receivers last
>> flow had just said credit is 10, but the senders delivery-count is
>> already 30 beyond what it could ever become based on that flow, so
>> credit should actually be -30 at the sender now. The receiver also
>> doesn't just end up at 0 after getting 10 more messages based on its
>> last flow, and instead has to cope (or fall over and close the link)
>> when an additional 20 more messages arrive than it seemingly just gave
>> credit for; despite having previously reduced credit from 100 to 0 and
>> increasing it back to 10 after receiving 20 messages, 30 more messages
>> arrived since it never found out if the reduction to 0 took effect and
>> it turns out that 50 (or even up to 100) were sent using the original
>> credit before it adjusted the credit twice more. Suppose we say that
>> the receiver actually successfully processes all 50 messages despite
>> that, this makes its delivery-count now 50 as well, what is its
>> credit?
>>
>>
> I think here there are two separate considerations... On the wire I would
> think that the receiver should update its delivery count to reflect the
> last received delivery from the sender (unless it just decides to tear down
> the link), and I would expect that the link-credit at this point would be
> zero.

That would be fine I think, though it doenst currently do this, and to
your point below it would be interesting when to if it did. Currently
at the application level, it doesnt see credit go negative until it
processes enough messages to make it do so, with unprocessed messages
being 'queued' and not yet reflected in credit views. The transport
level does I think consider the credit reduced as soon as they fully
arrive.

>
> More interesting to me is how we handle this in the interaction between the
> library and application layers.  Does the application layer have to issue
> more credit before the library presents the deliveries to it (even though
> the library is already holding the deliveries).  If not then does the
> application layer have to issue retrospective credits in order to start
> receiving new messages?
>
> I'm not sure the accounting part is hard... it's getting the API right that
> seems more tricky to me.
>
> -- Rob
>
>
>>
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> > For additional commands, e-mail: users-help@qpid.apache.org
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 2 March 2017 at 12:56, Robbie Gemmell <ro...@gmail.com> wrote:

> On 1 March 2017 at 18:28, Gordon Sim <gs...@redhat.com> wrote:
> > On 01/03/17 18:14, Rob Godfrey wrote:
> >>
> >> The link credit is an absolute value on the wire... but proton presents
> it
> >> in relative terms.  If you had 500 units of credit outstanding and
> >> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
> >> after that point... what state is your link credit in in Proton?
> >
> >
> > I would expect it to be 0.
> >
> >> Does it
> >> make a difference if those 5 messages had been processed by Proton (but
> >> not
> >> received by the application) before the flow(2) was sent or not?
> >
> >
> > Yes, if the flow(2) was issued after the 5 messages were processed, I
> would
> > expect the credit to be 2.
> >
>
> I think we need to be clearer what we mean by 'in proton' when
> discussing this - at the application level, or the transport/wire
> level, and before or after the application processes received
> messages, as these are all potentially in different states /
> presenting different views/values for credit at a given time. Indeed
> doing any of this inside e.g the container/reactor will often give a
> different result than it would in e.g the JMS client, since the
> effects of operations will actually occur at different times.
>
> I'm not sure most of them will currently match your expectations,
> credit will actually end up negative in a lot of them. Note in your
> example, when the timer refreshed credit by doing flow(100) the link
> credit on the wire actually went to 74, because 3 messages were
> received/buffered and processed at the receiver before it actually
> sent the flow reducing credit to 0, then 26 in flight were processed
> after, making credit end up at -26 once they were all processed,
> giving an effective 74 later when the flow(100) occurred to 'add 100'
> credits.
>
> Ignore proton for a minute and consider the following at a protocol
> level. If as a sender you get a flow saying delivery-count is 0 and
> credit is 100, and send 50 messages in-flight, then get a flow
> indicating delivery-count is 10 and credit is 0, then receive a flow
> indicating delivery-count is 20 and credit is 10, what is your actual
> credit at the sender and receiver when all is done?



So at this point I would say that the sender considers credit to be 0
(there's no point in the sender trying to store a negative link-credit
amount), at the receiver the link credit is (the most recent delivery-count
it saw from the sender) - 30 (this value may be negative).


> The receivers last
> flow had just said credit is 10, but the senders delivery-count is
> already 30 beyond what it could ever become based on that flow, so
> credit should actually be -30 at the sender now. The receiver also
> doesn't just end up at 0 after getting 10 more messages based on its
> last flow, and instead has to cope (or fall over and close the link)
> when an additional 20 more messages arrive than it seemingly just gave
> credit for; despite having previously reduced credit from 100 to 0 and
> increasing it back to 10 after receiving 20 messages, 30 more messages
> arrived since it never found out if the reduction to 0 took effect and
> it turns out that 50 (or even up to 100) were sent using the original
> credit before it adjusted the credit twice more. Suppose we say that
> the receiver actually successfully processes all 50 messages despite
> that, this makes its delivery-count now 50 as well, what is its
> credit?
>
>
I think here there are two separate considerations... On the wire I would
think that the receiver should update its delivery count to reflect the
last received delivery from the sender (unless it just decides to tear down
the link), and I would expect that the link-credit at this point would be
zero.

More interesting to me is how we handle this in the interaction between the
library and application layers.  Does the application layer have to issue
more credit before the library presents the deliveries to it (even though
the library is already holding the deliveries).  If not then does the
application layer have to issue retrospective credits in order to start
receiving new messages?

I'm not sure the accounting part is hard... it's getting the API right that
seems more tricky to me.

-- Rob


>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> > For additional commands, e-mail: users-help@qpid.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 18:28, Gordon Sim <gs...@redhat.com> wrote:
> On 01/03/17 18:14, Rob Godfrey wrote:
>>
>> The link credit is an absolute value on the wire... but proton presents it
>> in relative terms.  If you had 500 units of credit outstanding and
>> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
>> after that point... what state is your link credit in in Proton?
>
>
> I would expect it to be 0.
>
>> Does it
>> make a difference if those 5 messages had been processed by Proton (but
>> not
>> received by the application) before the flow(2) was sent or not?
>
>
> Yes, if the flow(2) was issued after the 5 messages were processed, I would
> expect the credit to be 2.
>

I think we need to be clearer what we mean by 'in proton' when
discussing this - at the application level, or the transport/wire
level, and before or after the application processes received
messages, as these are all potentially in different states /
presenting different views/values for credit at a given time. Indeed
doing any of this inside e.g the container/reactor will often give a
different result than it would in e.g the JMS client, since the
effects of operations will actually occur at different times.

I'm not sure most of them will currently match your expectations,
credit will actually end up negative in a lot of them. Note in your
example, when the timer refreshed credit by doing flow(100) the link
credit on the wire actually went to 74, because 3 messages were
received/buffered and processed at the receiver before it actually
sent the flow reducing credit to 0, then 26 in flight were processed
after, making credit end up at -26 once they were all processed,
giving an effective 74 later when the flow(100) occurred to 'add 100'
credits.

Ignore proton for a minute and consider the following at a protocol
level. If as a sender you get a flow saying delivery-count is 0 and
credit is 100, and send 50 messages in-flight, then get a flow
indicating delivery-count is 10 and credit is 0, then receive a flow
indicating delivery-count is 20 and credit is 10, what is your actual
credit at the sender and receiver when all is done? The receivers last
flow had just said credit is 10, but the senders delivery-count is
already 30 beyond what it could ever become based on that flow, so
credit should actually be -30 at the sender now. The receiver also
doesnt just end up at 0 after getting 10 more messages based on its
last flow, and instead has to cope (or fall over and close the link)
when an additional 20 more messages arrive than it seemingly just gave
credit for; despite having previously reduced credit from 100 to 0 and
increasing it back to 10 after receiving 20 messages, 30 more messages
arrived since it never found out if the reduction to 0 took effect and
it turns out that 50 (or even up to 100) were sent using the original
credit before it adjusted the credit twice more. Suppose we say that
the receiver actually sucessfully processes all 50 messages despite
that, this makes its delivery-count now 50 as well, what is its
credit?

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 18:14, Rob Godfrey wrote:
> The link credit is an absolute value on the wire... but proton presents it
> in relative terms.  If you had 500 units of credit outstanding and
> flow(-500) and then flow(2), and you get 5 messages on the wire arriving
> after that point... what state is your link credit in in Proton?

I would expect it to be 0.

> Does it
> make a difference if those 5 messages had been processed by Proton (but not
> received by the application) before the flow(2) was sent or not?

Yes, if the flow(2) was issued after the 5 messages were processed, I 
would expect the credit to be 2.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 18:49, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 17:19, Robbie Gemmell wrote:
>
>> How did you know they had actually stopped or that it was then safe to
>> flow them new credit, just waiting for a while?
>>
>> If you flow new credit before the link is actually stopped you need to
>> cope with that fairly specifically in case they hadnt really stopped.
>>
> >
>
>> There is scope for things to get out of whack otherwise, on both ends,
>> as they need to carefully handle the delivery-count and credit based
>> on what occurs and whether they have already exceeded the previous
>> allowances or not when the updates get sent/arrive.
>>
>
> The link credit is an absolute value. Setting it to 0 then to some other
> value should be no different that e.g. setting it to 100, then resetting it
> to 200 before the first flow is known to have been processed by the sender.
> The latest value indicated by the receiver is the valid value.
>
>
>
The link credit is an absolute value on the wire... but proton presents it
in relative terms.  If you had 500 units of credit outstanding and
flow(-500) and then flow(2), and you get 5 messages on the wire arriving
after that point... what state is your link credit in in Proton?  Does it
make a difference if those 5 messages had been processed by Proton (but not
received by the application) before the flow(2) was sent or not?

-- Rob




>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
>

Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 17:49, Gordon Sim <gs...@redhat.com> wrote:
> On 01/03/17 17:19, Robbie Gemmell wrote:
>>
>> How did you know they had actually stopped or that it was then safe to
>> flow them new credit, just waiting for a while?
>>
>> If you flow new credit before the link is actually stopped you need to
>> cope with that fairly specifically in case they hadnt really stopped.
>
>>
>>
>> There is scope for things to get out of whack otherwise, on both ends,
>> as they need to carefully handle the delivery-count and credit based
>> on what occurs and whether they have already exceeded the previous
>> allowances or not when the updates get sent/arrive.
>
>
> The link credit is an absolute value. Setting it to 0 then to some other
> value should be no different that e.g. setting it to 100, then resetting it
> to 200 before the first flow is known to have been processed by the sender.
> The latest value indicated by the receiver is the valid value.
>

Link credit is an absolute value, but its effect is relative to
another absolute value, delivery-count, which both ends track
semi-independently and reconcile the two at points, which is where the
complexity comes in with reducing credit after it is already granted
and potentially used but not yet known to be used or not used,
something I'm not sure proton currently accounts for, or at least not
in a way an application might expect.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 17:19, Robbie Gemmell wrote:
> How did you know they had actually stopped or that it was then safe to
> flow them new credit, just waiting for a while?
>
> If you flow new credit before the link is actually stopped you need to
> cope with that fairly specifically in case they hadnt really stopped.
 >
> There is scope for things to get out of whack otherwise, on both ends,
> as they need to carefully handle the delivery-count and credit based
> on what occurs and whether they have already exceeded the previous
> allowances or not when the updates get sent/arrive.

The link credit is an absolute value. Setting it to 0 then to some other 
value should be no different that e.g. setting it to 100, then resetting 
it to 200 before the first flow is known to have been processed by the 
sender. The latest value indicated by the receiver is the valid value.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 16:47, Gordon Sim <gs...@redhat.com> wrote:
> On 01/03/17 16:07, Robbie Gemmell wrote:
>>
>> The are issues around delivery count handling and the credit due to in
>> flight messages and how thats handled. It also requires echo support
>> (which proton lacks, theres another JRIA I raised for that) to do
>> properly, and you essentially need to remember you reduced the credit
>> to handle the state later when thigns actually do stop and start
>> again. None of which proton currently does.
>
>
> Not sure whether you are talking about proton-j specifically, or whether you
> are saying that proton-c won't actually work correctly here either. It would
> be good to know one way or the other whether this is a valid workaround for
> proton-c.
>

I was talking generally, I havent tried either specifically, and
couldnt say if they behave the same or not. I dont think proton-j can
handle this properly, and I doubt if proton-c does fully unless
specific support was added after proton-j was based on it.

I do think its entirely possible this may appear to work when it
doesnt really, i.e messages may arrive but the delivery counts/credit
calculations on either end become incorrect based on precisely what
occurs on the connection.

> I modified the example to re-issue credit after a timeout (I also fixed the
> revocation to account for any queued messages). I then sent 10000 messages
> to the queue and as far as I can see the example behaves as expected. A flow
> is issued with 0 credit, eventually the broker handles this by not sending
> any more messages and then after 30 seconds credit is issued again and more
> messages are received and accepted.
>
> Log and example attached. Is there any issue I am missing or that the
> example doesn't highlight?
>

How did you know they had actually stopped or that it was then safe to
flow them new credit, just waiting for a while?

If you flow new credit before the link is actually stopped you need to
cope with that fairly specifically in case they hadnt really stopped.
There is scope for things to get out of whack otherwise, on both ends,
as they need to carefully handle the delivery-count and credit based
on what occurs and whether they have already exceeded the previous
allowances or not when the updates get sent/arrive.

>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 16:07, Robbie Gemmell wrote:
> The are issues around delivery count handling and the credit due to in
> flight messages and how thats handled. It also requires echo support
> (which proton lacks, theres another JRIA I raised for that) to do
> properly, and you essentially need to remember you reduced the credit
> to handle the state later when thigns actually do stop and start
> again. None of which proton currently does.

Not sure whether you are talking about proton-j specifically, or whether 
you are saying that proton-c won't actually work correctly here either. 
It would be good to know one way or the other whether this is a valid 
workaround for proton-c.

I modified the example to re-issue credit after a timeout (I also fixed 
the revocation to account for any queued messages). I then sent 10000 
messages to the queue and as far as I can see the example behaves as 
expected. A flow is issued with 0 credit, eventually the broker handles 
this by not sending any more messages and then after 30 seconds credit 
is issued again and more messages are received and accepted.

Log and example attached. Is there any issue I am missing or that the 
example doesn't highlight?


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
The are issues around delivery count handling and the credit due to in
flight messages and how thats handled. It also requires echo support
(which proton lacks, theres another JRIA I raised for that) to do
properly, and you essentially need to remember you reduced the credit
to handle the state later when thigns actually do stop and start
again. None of which proton currently does.

On 1 March 2017 at 15:56, Gordon Sim <gs...@redhat.com> wrote:
> On 01/03/17 15:37, Gordon Sim wrote:
>>
>> On 01/03/17 14:31, Kai Hudalla wrote:
>>>
>>> Assuming that we have a link established between a Receiver (r) and a
>>> Sender (s)
>>> with a current link-credit of 4 and a delivery count of 20 on both sides.
>>>
>>> When invoking r.flow(6), the given credit (6) is _added_ to the
>>> receiver's
>>> current credit resulting in r.getCredit() returning 10.
>>>
>>> When the FLOW is then flushed to the sender, the sender seems to _add_
>>> the link-
>>> credit from the FLOW to its already existing credit. Analogously, this
>>> results in
>>> s.getCredit() now returning 10.
>>>
>>> With this approach, it doesn't seem to be possible to stop the sender
>>> from
>>> sending messages. The only thing a receiver can do is to wait until
>>> the sender
>>> has used up all its credit (which may be a lot given that with the
>>> current
>>> approach the sender's credit can pile up substantially).
>>>
>>> Or am I mistaken?
>>
>>
>> Can you specify a negative value to Receiver::flow()? I.e. would that
>> subtract from the credit and send a corresponding flow to the sender?
>
>
> That seems to work for proton-c which has a similar API. (Not ideal, but a
> workaround at least).
>
>> $ PN_TRACE_FRM=1 python revoke_credit.py
>> [0x563feb999040]:  -> SASL
>> [0x563feb999040]:  <- SASL
>> [0x563feb999040]:0 <- @sasl-mechanisms(64)
>> [sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS, :PLAIN]]
>> [0x563feb999040]:0 -> @sasl-init(65) [mechanism=:ANONYMOUS,
>> initial-response=b"anonymous@localhost.localdomain"]
>> [0x563feb999040]:0 <- @sasl-outcome(68) [code=0]
>> [0x563feb999040]:  -> AMQP
>> [0x563feb999040]:0 -> @open(16)
>> [container-id="023946f1-0197-4559-bd72-7fff5a687958", hostname="localhost",
>> channel-max=32767]
>> [0x563feb999040]:0 -> @begin(17) [next-outgoing-id=0,
>> incoming-window=2147483647, outgoing-window=2147483647]
>> [0x563feb999040]:0 -> @attach(18)
>> [name="023946f1-0197-4559-bd72-7fff5a687958-examples", handle=0, role=true,
>> snd-settle-mode=2, rcv-settle-mode=0, source=@source(40)
>> [address="examples", durable=0, timeout=0, dynamic=false],
>> target=@target(41) [durable=0, timeout=0, dynamic=false],
>> initial-delivery-count=0, max-message-size=0]
>> [0x563feb999040]:  <- AMQP
>> [0x563feb999040]:0 <- @open(16)
>> [container-id="a6022696-2483-49f5-8ea6-a6f50db0e7ae", channel-max=32767,
>> offered-capabilities=@PN_SYMBOL[:"ANONYMOUS-RELAY"],
>> properties={:product="qpid-cpp", :version="1.36.0", :platform="Linux",
>> :host="localhost.localdomain"}]
>> [0x563feb999040]:0 <- @begin(17) [remote-channel=0, next-outgoing-id=0,
>> incoming-window=2147483647, outgoing-window=2147483647]
>> [0x563feb999040]:0 <- @attach(18)
>> [name="023946f1-0197-4559-bd72-7fff5a687958-examples", handle=0, role=false,
>> snd-settle-mode=2, rcv-settle-mode=0, source=@source(40)
>> [address="examples", durable=0, timeout=0, dynamic=false,
>> distribution-mode=:move], target=@target(41) [durable=0, timeout=0,
>> dynamic=false], initial-delivery-count=0, max-message-size=0]
>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=0,
>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>> handle=0, delivery-count=0, link-credit=100, drain=false]
>> [0x563feb999040]:0 <- @transfer(20) [handle=0, delivery-id=0,
>> delivery-tag=b"\x00\x00\x00\x00", message-format=0, settled=false,
>> more=false] (46)
>> "\x00Sp\xc0\x08\x05BP\x00@@R\x03\x00St\xc1\x14\x04\xa1\x02snR\x01\xa1\x02ts\x81\x14\xa7\xccS\x8fD\x99\x84\x00Sw\xa1\x03one"
>> one
>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=1,
>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>> handle=0, delivery-count=1, link-credit=0, drain=false]
>> [0x563feb999040]:0 -> @disposition(21) [role=true, first=0, last=0,
>> settled=true, state=@accepted(36) []]
>
>
> If there are messages in flight when you revoke the credit, they will still
> be delivered from my tests.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Robbie Gemmell <ro...@gmail.com>.
On 1 March 2017 at 16:08, Rob Godfrey <ro...@gmail.com> wrote:
> On 1 March 2017 at 16:56, Gordon Sim <gs...@redhat.com> wrote:
>
>> On 01/03/17 15:37, Gordon Sim wrote:
>>
>>> On 01/03/17 14:31, Kai Hudalla wrote:
>>>
>>>> Assuming that we have a link established between a Receiver (r) and a
>>>> Sender (s)
>>>> with a current link-credit of 4 and a delivery count of 20 on both sides.
>>>>
>>>> When invoking r.flow(6), the given credit (6) is _added_ to the
>>>> receiver's
>>>> current credit resulting in r.getCredit() returning 10.
>>>>
>>>> When the FLOW is then flushed to the sender, the sender seems to _add_
>>>> the link-
>>>> credit from the FLOW to its already existing credit. Analogously, this
>>>> results in
>>>> s.getCredit() now returning 10.
>>>>
>>>> With this approach, it doesn't seem to be possible to stop the sender
>>>> from
>>>> sending messages. The only thing a receiver can do is to wait until
>>>> the sender
>>>> has used up all its credit (which may be a lot given that with the
>>>> current
>>>> approach the sender's credit can pile up substantially).
>>>>
>>>> Or am I mistaken?
>>>>
>>>
>>> Can you specify a negative value to Receiver::flow()? I.e. would that
>>> subtract from the credit and send a corresponding flow to the sender?
>>>
>>
>> That seems to work for proton-c which has a similar API. (Not ideal, but a
>> workaround at least).
>>
>
> Adding a convenience "stop()" method in the API to perform the interaction
> as described in section 2.6.10 Stopping a link
> <http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#doc-idp429232>
> would
> be a nice addition I think.
>
> -- Rob
>

Thats essentially what I've always had in mind. Theres probably more
to consider around waht people can do while the link is actually
stopping, e.g. what happens if flow() is called again before the peer
actually stops (if they reply at all..) etc.

>
>>
>> $ PN_TRACE_FRM=1 python revoke_credit.py
>>> [0x563feb999040]:  -> SASL
>>> [0x563feb999040]:  <- SASL
>>> [0x563feb999040]:0 <- @sasl-mechanisms(64) [sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS,
>>> :PLAIN]]
>>> [0x563feb999040]:0 -> @sasl-init(65) [mechanism=:ANONYMOUS,
>>> initial-response=b"anonymous@localhost.localdomain"]
>>> [0x563feb999040]:0 <- @sasl-outcome(68) [code=0]
>>> [0x563feb999040]:  -> AMQP
>>> [0x563feb999040]:0 -> @open(16) [container-id="023946f1-0197-4559-bd72-7fff5a687958",
>>> hostname="localhost", channel-max=32767]
>>> [0x563feb999040]:0 -> @begin(17) [next-outgoing-id=0,
>>> incoming-window=2147483647, outgoing-window=2147483647]
>>> [0x563feb999040]:0 -> @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
>>> handle=0, role=true, snd-settle-mode=2, rcv-settle-mode=0,
>>> source=@source(40) [address="examples", durable=0, timeout=0,
>>> dynamic=false], target=@target(41) [durable=0, timeout=0, dynamic=false],
>>> initial-delivery-count=0, max-message-size=0]
>>> [0x563feb999040]:  <- AMQP
>>> [0x563feb999040]:0 <- @open(16) [container-id="a6022696-2483-49f5-8ea6-a6f50db0e7ae",
>>> channel-max=32767, offered-capabilities=@PN_SYMBOL[:"ANONYMOUS-RELAY"],
>>> properties={:product="qpid-cpp", :version="1.36.0", :platform="Linux",
>>> :host="localhost.localdomain"}]
>>> [0x563feb999040]:0 <- @begin(17) [remote-channel=0, next-outgoing-id=0,
>>> incoming-window=2147483647, outgoing-window=2147483647]
>>> [0x563feb999040]:0 <- @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
>>> handle=0, role=false, snd-settle-mode=2, rcv-settle-mode=0,
>>> source=@source(40) [address="examples", durable=0, timeout=0,
>>> dynamic=false, distribution-mode=:move], target=@target(41) [durable=0,
>>> timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
>>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=0,
>>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>>> handle=0, delivery-count=0, link-credit=100, drain=false]
>>> [0x563feb999040]:0 <- @transfer(20) [handle=0, delivery-id=0,
>>> delivery-tag=b"\x00\x00\x00\x00", message-format=0, settled=false,
>>> more=false] (46) "\x00Sp\xc0\x08\x05BP\x00@@R\x
>>> 03\x00St\xc1\x14\x04\xa1\x02snR\x01\xa1\x02ts\x81\x14\xa7\
>>> xccS\x8fD\x99\x84\x00Sw\xa1\x03one"
>>> one
>>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=1,
>>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>>> handle=0, delivery-count=1, link-credit=0, drain=false]
>>> [0x563feb999040]:0 -> @disposition(21) [role=true, first=0, last=0,
>>> settled=true, state=@accepted(36) []]
>>>
>>
>> If there are messages in flight when you revoke the credit, they will
>> still be delivered from my tests.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
>> For additional commands, e-mail: users-help@qpid.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org


Re: [proton-j] handling of link-credit

Posted by Rob Godfrey <ro...@gmail.com>.
On 1 March 2017 at 16:56, Gordon Sim <gs...@redhat.com> wrote:

> On 01/03/17 15:37, Gordon Sim wrote:
>
>> On 01/03/17 14:31, Kai Hudalla wrote:
>>
>>> Assuming that we have a link established between a Receiver (r) and a
>>> Sender (s)
>>> with a current link-credit of 4 and a delivery count of 20 on both sides.
>>>
>>> When invoking r.flow(6), the given credit (6) is _added_ to the
>>> receiver's
>>> current credit resulting in r.getCredit() returning 10.
>>>
>>> When the FLOW is then flushed to the sender, the sender seems to _add_
>>> the link-
>>> credit from the FLOW to its already existing credit. Analogously, this
>>> results in
>>> s.getCredit() now returning 10.
>>>
>>> With this approach, it doesn't seem to be possible to stop the sender
>>> from
>>> sending messages. The only thing a receiver can do is to wait until
>>> the sender
>>> has used up all its credit (which may be a lot given that with the
>>> current
>>> approach the sender's credit can pile up substantially).
>>>
>>> Or am I mistaken?
>>>
>>
>> Can you specify a negative value to Receiver::flow()? I.e. would that
>> subtract from the credit and send a corresponding flow to the sender?
>>
>
> That seems to work for proton-c which has a similar API. (Not ideal, but a
> workaround at least).
>

Adding a convenience "stop()" method in the API to perform the interaction
as described in section 2.6.10 Stopping a link
<http://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-transport-v1.0-os.html#doc-idp429232>
would
be a nice addition I think.

-- Rob


>
> $ PN_TRACE_FRM=1 python revoke_credit.py
>> [0x563feb999040]:  -> SASL
>> [0x563feb999040]:  <- SASL
>> [0x563feb999040]:0 <- @sasl-mechanisms(64) [sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS,
>> :PLAIN]]
>> [0x563feb999040]:0 -> @sasl-init(65) [mechanism=:ANONYMOUS,
>> initial-response=b"anonymous@localhost.localdomain"]
>> [0x563feb999040]:0 <- @sasl-outcome(68) [code=0]
>> [0x563feb999040]:  -> AMQP
>> [0x563feb999040]:0 -> @open(16) [container-id="023946f1-0197-4559-bd72-7fff5a687958",
>> hostname="localhost", channel-max=32767]
>> [0x563feb999040]:0 -> @begin(17) [next-outgoing-id=0,
>> incoming-window=2147483647, outgoing-window=2147483647]
>> [0x563feb999040]:0 -> @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
>> handle=0, role=true, snd-settle-mode=2, rcv-settle-mode=0,
>> source=@source(40) [address="examples", durable=0, timeout=0,
>> dynamic=false], target=@target(41) [durable=0, timeout=0, dynamic=false],
>> initial-delivery-count=0, max-message-size=0]
>> [0x563feb999040]:  <- AMQP
>> [0x563feb999040]:0 <- @open(16) [container-id="a6022696-2483-49f5-8ea6-a6f50db0e7ae",
>> channel-max=32767, offered-capabilities=@PN_SYMBOL[:"ANONYMOUS-RELAY"],
>> properties={:product="qpid-cpp", :version="1.36.0", :platform="Linux",
>> :host="localhost.localdomain"}]
>> [0x563feb999040]:0 <- @begin(17) [remote-channel=0, next-outgoing-id=0,
>> incoming-window=2147483647, outgoing-window=2147483647]
>> [0x563feb999040]:0 <- @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples",
>> handle=0, role=false, snd-settle-mode=2, rcv-settle-mode=0,
>> source=@source(40) [address="examples", durable=0, timeout=0,
>> dynamic=false, distribution-mode=:move], target=@target(41) [durable=0,
>> timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=0,
>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>> handle=0, delivery-count=0, link-credit=100, drain=false]
>> [0x563feb999040]:0 <- @transfer(20) [handle=0, delivery-id=0,
>> delivery-tag=b"\x00\x00\x00\x00", message-format=0, settled=false,
>> more=false] (46) "\x00Sp\xc0\x08\x05BP\x00@@R\x
>> 03\x00St\xc1\x14\x04\xa1\x02snR\x01\xa1\x02ts\x81\x14\xa7\
>> xccS\x8fD\x99\x84\x00Sw\xa1\x03one"
>> one
>> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=1,
>> incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647,
>> handle=0, delivery-count=1, link-credit=0, drain=false]
>> [0x563feb999040]:0 -> @disposition(21) [role=true, first=0, last=0,
>> settled=true, state=@accepted(36) []]
>>
>
> If there are messages in flight when you revoke the credit, they will
> still be delivered from my tests.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>

Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 15:37, Gordon Sim wrote:
> On 01/03/17 14:31, Kai Hudalla wrote:
>> Assuming that we have a link established between a Receiver (r) and a
>> Sender (s)
>> with a current link-credit of 4 and a delivery count of 20 on both sides.
>>
>> When invoking r.flow(6), the given credit (6) is _added_ to the
>> receiver's
>> current credit resulting in r.getCredit() returning 10.
>>
>> When the FLOW is then flushed to the sender, the sender seems to _add_
>> the link-
>> credit from the FLOW to its already existing credit. Analogously, this
>> results in
>> s.getCredit() now returning 10.
>>
>> With this approach, it doesn't seem to be possible to stop the sender
>> from
>> sending messages. The only thing a receiver can do is to wait until
>> the sender
>> has used up all its credit (which may be a lot given that with the
>> current
>> approach the sender's credit can pile up substantially).
>>
>> Or am I mistaken?
>
> Can you specify a negative value to Receiver::flow()? I.e. would that
> subtract from the credit and send a corresponding flow to the sender?

That seems to work for proton-c which has a similar API. (Not ideal, but 
a workaround at least).

> $ PN_TRACE_FRM=1 python revoke_credit.py
> [0x563feb999040]:  -> SASL
> [0x563feb999040]:  <- SASL
> [0x563feb999040]:0 <- @sasl-mechanisms(64) [sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS, :PLAIN]]
> [0x563feb999040]:0 -> @sasl-init(65) [mechanism=:ANONYMOUS, initial-response=b"anonymous@localhost.localdomain"]
> [0x563feb999040]:0 <- @sasl-outcome(68) [code=0]
> [0x563feb999040]:  -> AMQP
> [0x563feb999040]:0 -> @open(16) [container-id="023946f1-0197-4559-bd72-7fff5a687958", hostname="localhost", channel-max=32767]
> [0x563feb999040]:0 -> @begin(17) [next-outgoing-id=0, incoming-window=2147483647, outgoing-window=2147483647]
> [0x563feb999040]:0 -> @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples", handle=0, role=true, snd-settle-mode=2, rcv-settle-mode=0, source=@source(40) [address="examples", durable=0, timeout=0, dynamic=false], target=@target(41) [durable=0, timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
> [0x563feb999040]:  <- AMQP
> [0x563feb999040]:0 <- @open(16) [container-id="a6022696-2483-49f5-8ea6-a6f50db0e7ae", channel-max=32767, offered-capabilities=@PN_SYMBOL[:"ANONYMOUS-RELAY"], properties={:product="qpid-cpp", :version="1.36.0", :platform="Linux", :host="localhost.localdomain"}]
> [0x563feb999040]:0 <- @begin(17) [remote-channel=0, next-outgoing-id=0, incoming-window=2147483647, outgoing-window=2147483647]
> [0x563feb999040]:0 <- @attach(18) [name="023946f1-0197-4559-bd72-7fff5a687958-examples", handle=0, role=false, snd-settle-mode=2, rcv-settle-mode=0, source=@source(40) [address="examples", durable=0, timeout=0, dynamic=false, distribution-mode=:move], target=@target(41) [durable=0, timeout=0, dynamic=false], initial-delivery-count=0, max-message-size=0]
> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=0, incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647, handle=0, delivery-count=0, link-credit=100, drain=false]
> [0x563feb999040]:0 <- @transfer(20) [handle=0, delivery-id=0, delivery-tag=b"\x00\x00\x00\x00", message-format=0, settled=false, more=false] (46) "\x00Sp\xc0\x08\x05BP\x00@@R\x03\x00St\xc1\x14\x04\xa1\x02snR\x01\xa1\x02ts\x81\x14\xa7\xccS\x8fD\x99\x84\x00Sw\xa1\x03one"
> one
> [0x563feb999040]:0 -> @flow(19) [next-incoming-id=1, incoming-window=2147483647, next-outgoing-id=0, outgoing-window=2147483647, handle=0, delivery-count=1, link-credit=0, drain=false]
> [0x563feb999040]:0 -> @disposition(21) [role=true, first=0, last=0, settled=true, state=@accepted(36) []]

If there are messages in flight when you revoke the credit, they will 
still be delivered from my tests.


Re: [proton-j] handling of link-credit

Posted by Gordon Sim <gs...@redhat.com>.
On 01/03/17 14:31, Kai Hudalla wrote:
> Assuming that we have a link established between a Receiver (r) and a Sender (s)
> with a current link-credit of 4 and a delivery count of 20 on both sides.
>
> When invoking r.flow(6), the given credit (6) is _added_ to the receiver's
> current credit resulting in r.getCredit() returning 10.
>
> When the FLOW is then flushed to the sender, the sender seems to _add_ the link-
> credit from the FLOW to its already existing credit. Analogously, this results in
> s.getCredit() now returning 10.
>
> With this approach, it doesn't seem to be possible to stop the sender from
> sending messages. The only thing a receiver can do is to wait until the sender
> has used up all its credit (which may be a lot given that with the current
> approach the sender's credit can pile up substantially).
>
> Or am I mistaken?

Can you specify a negative value to Receiver::flow()? I.e. would that 
subtract from the credit and send a corresponding flow to the sender?


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org