Actors may not be that cheap.

They are ~400 bytes for an Actor; plus whatever you put inside one of
course, but that’s your state, not the Actor’s fault ;)

I tried to create a worker actor every time the master actor received a
start job message and found out that it created a new thread to run it.
Seems to me that the default dispatcher is an unbounded thread pool. It
doesn't look good to me -- it falls back to the thread per request model???

That’s not true. Actors share a thread-pool, the pool may decide more
threads would be a good idea ;-)

if you are doing blocking operations, please follow the advice which I
already posted in the previous email, read about managing blocking:

https://doc.akka.io/docs/akka/current/dispatchers.html#blocking-needs-careful-management

Since the jobs are CPU intensive, I have to control the number of
concurrent jobs.

Sure, which is why I suggested the master actor who can control how many
workers are active at any given time.

Number of threads you can limit by following the docs above, in dispatchers.

Here's an update of the code. It works to me. Just want to clarify if this
a right way to do.

// When master actor receive startJob message, creates a new worker actor
with a predefined dispatcher with a fixed thread pool to control the number
of concurrent jobs.
ActorRef worker =
getContext().actorOf(Props.create(Worker.class).withDispatcher("my-blocking-dispatcher"));
worker.tell(job, self());


Yes, that’s the bigger part of it, read above docs to understand why.

-- 
Cheers,
Konrad 'ktoso <http://kto.so>' Malawski
Akka <http://akka.io/> @ Lightbend <http://lightbend.com/>

-- 
>>>>>>>>>>      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 https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to