Re: [akka-user] Help required regarding actors (and priority)

150 views
Skip to first unread message

√iktor Ҡlang

unread,
Oct 15, 2012, 1:38:26 PM10/15/12
to akka...@googlegroups.com
Hi Sachin,

On Mon, Oct 15, 2012 at 7:24 PM, Sachin <shirv...@gmail.com> wrote:
Hi all,

I am new to Scala and its Akka library and I have some doubts. If someone can clarify, it will be highly appreciated.

1. Is it possible to have some actors which have some priority (high, medium and low)?

 
For example of this scenario, if two actors are eligible to run (messages are queued in their respective mailboxes) then they should run in priority order. 

Priority on the Actors or the priority of the messages?
 

If it is possible, then how can it be achieved? Will I need to make changes in Akka/scala source code or extend the existing scheduler/dispatcher in application itself as suggested in akka documentation?

For priorization of Actors:
You'll have to create your own ExecutorServiceConfigurator which creates an ExecutorService that uses a PriorityBlockingQueue as its task queue. I wouldn't recommend doing it however, since now you've introduced starvation into your system... Also, performance and scalability will suffer due to the need of prioritizing all tasks.

For priorization of Messages: Read this section: http://doc.akka.io/docs/akka/2.0.3/scala/dispatchers.html#Mailboxes
 


2. Also please clarify what part of akka or scala executes actors and what part processes mailbox? I am going through the documentation but its a bit of learning curve there and my understanding is still hazy.

MessageDispatchers are the "engines" that make sure things get processed, and there are multiple flavors. The details is not a part of the user documentation since it is indeed implementation details, for full understanding the sourcecode should be inspected.

Cheers,
 

Thanks
Sachin

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user?hl=en.
 
 



--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

√iktor Ҡlang

unread,
Oct 15, 2012, 2:12:04 PM10/15/12
to akka...@googlegroups.com


On Mon, Oct 15, 2012 at 8:06 PM, Sachin <shirv...@gmail.com> wrote:
Dear Viktor Klang,

Thank you for your response and detailed information.
 
>> Priority on the Actors or the priority of the messages?

I wanted it to be priority on actors. 

>> ........ since now you've introduced starvation into your system...

Can you please elaborate on how can it lead to starvation? I was assuming that only ready actors (which have messages in their respective mailboxes to be processed) will be considered for re-ordering execution according to priority. Waiting actors will not be considered. Also till my actors are not blocking (they complete their message processing and wait for next message), system should not face any starvation if at some time low priority actors also get a chance to execute. If I am wrong in making such an assumption, please let me know.

Lets say you have 1 Thread and 1 of your high-priority Actors and 348792346 other Actors. If that high-priority actor sends itself a message as part of processing a message, it will now have highest priority to execute once it's done with the current message. Since it always sends itself a message when processing a message, it means that no other actor will ever be able to run. Starvation.
 

I agree that performance may have a hit due to extra processing involved in re-ordering the actors execution, but for my application I am ready to take that hit if it is not huge. Or is there any other aspect which I did not take in to consideration?

I'd probably just give that Actor a PinnedDispatcher, of if it is a bunch of actors on the same "priority" I'd have them share a dispatcher, and have all other "low priority" actors share the default dispatcher.

Cheers,
 

Thanks
Sachin

 
Reply all
Reply to author
Forward
0 new messages