Akka.net: Add UnboundedStablePriorityMailbox

Created on 9 May 2017  Â·  11Comments  Â·  Source: akkadotnet/akka.net

"UnboundedStablePriorityMailbox": an unbounded mailbox that allows for prioritization of its contents and preserves ordering for messages of equal priority

Most helpful comment

Maybe I'm wrong, but it's looks like a heap implementation, so your step 4 is a little bit more complicated than "sorting" elements.

The 'solution' would be either using the order of arrival of messages along with their priority to compare element with the same priority, or something like the StablePriorityQueue they have in scala Akka.

All 11 comments

I need a mailbox that allows for prioritization of its contents and preserves ordering for messages of equal priority. I am aware that, in akka .NET, I need to implement "UnboundedPriorityMailbox" to have a mailbox that allows for prioritization of its contents; however this latter would not preserve a FIFO ordering for messages of equal priority.

Am I missing something? Is there any workaround?

@yahyanajar Have you read the docs regarding the UnboundedPriority Mailbox ?

http://getakka.net/docs/working-with-actors/Mailbox

If you implement a PriorityGenerator you should have sufficient control to achieve what you want.

@danthar the key bit is this:

"UnboundedStablePriorityMailbox": an unbounded mailbox that allows for prioritization of its contents and preserves ordering for messages of equal priority

Currently not implemented; will need a different priority queue implementation than what we have at the moment.

Messages ordered by the same number will remain in delivery order.

Thats whats in the docs. Seems to me thats exactly whats requested ?

If im misunderstanding, its always a possibility to implement your own prioritymailbox @yahyanajar .
Using the existing code as a template, it should not be to hard to do.

Yes it is in the docs but that's not how it works, since it is implemented
as a simple priority heap that is not stable. Would you like us to provide
a simple code that shows the t doesn't work ?

Le ven. 19 mai 2017 à 12:31, Arjen Smits notifications@github.com a
écrit :

Messages ordered by the same number will remain in delivery order.

Thats whats in the docs. Seems to me thats exactly whats requested ?

—
You are receiving this because you are subscribed to this thread.

Reply to this email directly, view it on GitHub
https://github.com/akkadotnet/akka.net/issues/2652#issuecomment-302668651,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFyNcHdgnMgKK4t_UqtYvGvljEaI3Qx-ks5r7W9xgaJpZM4NVTdd
.

Hi,

there goes a sample code illustrating the obtained/expected message handling order, and also showing that it comes from the implementation of ListPriorityQueue.

https://gist.github.com/maurelio1234/724df2a39058b12730fc63d49b681a32

The current documentation/comment on UnboundedPriorityMailbox should probably be updated.
The current comment states,
_"Messages ordered by the same number will remain in delivery order."_

akka.io's documentation states
_"Delivery order for messages of equal priority is undefined"_

I'm looking at ListPriorityQueue and one thing I'm not following is if it is sorting on insert (Enqueue), why is it sorting on Dequeue?

I'm also not following the logic (in Dequeue) of

  1. Take first item off the list
  2. Copy last item in the list to the first position (this violates delivery order on equal items)
  3. Truncate last item off the list.
  4. Sort items

Why can't we just do: (assuming there is something to dequeue)

var frontItem = _data[0];   // fetch the front
_data.RemoveAt(0);
return frontItem;

Edit: Well, shoot...I guess I'm under the assumption that the priority calculation is static. If (for example) age of the message was a consideration, then deque-time ordering would be important. Moving the last item to the front still seems odd.

Maybe I'm wrong, but it's looks like a heap implementation, so your step 4 is a little bit more complicated than "sorting" elements.

The 'solution' would be either using the order of arrival of messages along with their priority to compare element with the same priority, or something like the StablePriorityQueue they have in scala Akka.

Yeah, its using a heap implementation so its not really a true sort. akka.io says that ordering is indeterminate (in their implementation) so the comment here should probably state something similar?
It looks like we will likely make our own implementation that honors delivery order.

EDIT: I pushed it here. It's pretty simplistic but there it is.

closed via #3536

Was this page helpful?
0 / 5 - 0 ratings