On Wednesday, April 15, 2015 at 9:17:44 PM UTC-7, Rohit Jain wrote:
>
>
>
> On Wednesday, April 15, 2015 at 10:37:36 PM UTC+5:30, Michael Frank wrote:
>>
>>  On 04/15/15 04:47, Rohit Jain wrote:
>>  
>>  How does using akka actor helps in achieving concurrency without use of 
>> any external locks?
>>  Is it because at a moment only one message can be processed for one 
>> actor ? Hence no 2 threads can be acting upon same actor ?
>>
>>  
>
>> that is correct.  processing within the receive loop of an actor is 
>> single threaded.
>>
>> >> How does akka make sure that while processing a certain message, no 
> other message thread will be processed or there will be no context switch ? 
> Or it just uses low level constructs of locking on a certain message before 
> processing it, even though context switch for that message thread happens, 
> it wont release the lock till message is processed (This can cause trouble 
> in blocking I/O).
>

Akka uses an ordered mailbox to store messages waiting to be processed.  It 
then uses a single thread to roll through this mailbox, calling your 
actor's receive method.  You don't need locking because there can't be 
contention on this mailbox.  If the thread is context switched to handle 
another actor, that's fine.  The original actor's messages will need to 
wait until its next time slice to process another message.

If you block within your receive, you can/will have problems.  Keep your 
receive non-blocking and delegate heavy lifting (even if it isn't blocking) 
to another dispatcher to achieve max throughput. 
 

>
>>  If that is the case, then maximum number of threads we require is equal 
>> to number of actors in our system.
>>  
>>
>> if all your actors perform blocking work in their receive loop, then that 
>> would be true.  however, you should design your application to be 
>> non-blocking (http://www.reactivemanifesto.org/glossary#Non-Blocking).  
>> if you need to perform blocking work, then you should use Futures (
>> http://doc.akka.io/docs/akka/2.3.9/scala/futures.html) to schedule the 
>> work on a separate, dedicated dispatcher (
>> http://doc.akka.io/docs/akka/2.3.9/scala/dispatchers.html).  You can 
>> then pipe the result of the Future to an actor (
>> http://doc.akka.io/docs/akka/2.3.9/scala/futures.html#Use_With_Actors) 
>> for further processing if necessary.
>>
>> -Michael
>>  
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      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 unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to