Alwin Doss Alwin Doss - 1 month ago 16
Scala Question

When to create an Akka Actor

I have a REST service which services only one POST request. I want to use an actor to process the request. However I don't know if I should create one actor and derive all the requests using this actor or should I create an actor every time I get a request. What are the pros and cons of these choices.
Also, how is it parallel execution when I create one actor and use that actor to process all my requests. It certainly looks like sequential execution. I would want to understand this as well.

Answer

If you use one Actor requests are queued inside the actor mail box and are processed one by one by the actor. This is sequential and not recommended.

Thats why it is said

One actor is no actor.

Create a manager Actor which manages other actors. As actors are quite cheap you can create one actor for every request without any problem. Do db interactions and other heavy computation using a future and direct results of the future to request handling actor using pipeTo pattern.

Use actors only to divide and distribute work and use Futures to do compute intensive work.

Comments