Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UnboundedStablePriorityMailbox #2652

Closed
yahyanajar opened this issue May 9, 2017 · 11 comments
Closed

Add UnboundedStablePriorityMailbox #2652

yahyanajar opened this issue May 9, 2017 · 11 comments
Milestone

Comments

@yahyanajar
Copy link

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

@yahyanajar
Copy link
Author

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?

@Danthar
Copy link
Member

Danthar commented May 18, 2017

@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.

@Aaronontheweb
Copy link
Member

@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.

@Danthar
Copy link
Member

Danthar commented May 19, 2017

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.

@maurelio1234
Copy link

maurelio1234 commented May 19, 2017 via email

@maurelio1234
Copy link

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

@spankr
Copy link
Contributor

spankr commented Aug 8, 2017

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"

@spankr
Copy link
Contributor

spankr commented Aug 8, 2017

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.

@maurelio1234
Copy link

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.

@spankr
Copy link
Contributor

spankr commented Aug 9, 2017

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.

AndreSteenbergen added a commit to AndreSteenbergen/akka.net that referenced this issue Jul 5, 2018
…priority. Messages with the same priority will be send using the same order as they appear. akkadotnet#2652 is the related issue.
@Aaronontheweb Aaronontheweb added this to the 1.3.13 milestone Mar 20, 2019
Aaronontheweb pushed a commit that referenced this issue Mar 21, 2019
* Added an UnboundStablePriorityMailbox, sending messages according to priority. Messages with the same priority will be send using the same order as they appear. #2652 is the related issue.

* added PropertyTest for StableListPriorityQueue

* forgot to add spec

* verified that the UnboundedStablePriorityMailbox can be loaded and used

* validate4d that UnboundedStablePriorityMailbox supports stashing

* added API approval for core
@Aaronontheweb
Copy link
Member

closed via #3536

This was referenced Apr 30, 2019
madmonkey pushed a commit to madmonkey/akka.net that referenced this issue Jul 12, 2019
* Added an UnboundStablePriorityMailbox, sending messages according to priority. Messages with the same priority will be send using the same order as they appear. akkadotnet#2652 is the related issue.

* added PropertyTest for StableListPriorityQueue

* forgot to add spec

* verified that the UnboundedStablePriorityMailbox can be loaded and used

* validate4d that UnboundedStablePriorityMailbox supports stashing

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

No branches or pull requests

5 participants