I need to execute some (let’s say 10) tasks with less (i.e.) 3 actors.
But I don’t want to distribute all the tasks in the beginning, because time of execution may vary. That’s why I need to send all of them 1 task and when any finishes he’ll be given a new task. This way when first task takes 3 seconds and rest only ~ 0.5s job can be done in 3 sec.
Having 10 tasks list:
(() => Thread.sleep(3000); println("done long"}) :: (1..9).map({() => println("done short")})
I want to have output:
done short
done short
done short
done short
done short
done short
done short
done short
done short
done long
I could write the manager actor, returning actors to manager and redistributing the work again, but I was hoping to find a fixed solution in Scala or Akka.
Akka supports Dispatchers and in particular work stealing. Look this post for the details.