I have an actor called a TaskRunner. The tasks can take up to 1 minute to run. Because of the library I use there can only be one actor per jvm/node. I have 1000 of these nodes across various machines.
I would like to distribute tasks to these nodes using various rules but the most important one is:
The way I was thinking of doing this is have an actor on another node (lets call this the Scheduler actor) listen to registrations from the TaskRunner nodes and keep an internal state of what has been sent to where.
Presumably if I did this I could only ever have one instance of this Scheduler actor because if there was more than one they wouldn't know which TaskRunner nodes were currently busy and so we would get tasks in the queue.
Does this mean I should be using a Cluster Singleton for the Scheduler actor?
Is there a better way to achieve my goal?
I would say you need:
dispatcher actor (cluster singleton) who send task to actor from pool of idle actors
your TaskRunner actor should have two states: running, and idle. In idle state it should register itself regularly to dispatcher actor (notifying that it is idle). Regularly, because of possible state losing by dispatcher in case of node shutdown and move singleton to another node.
dispatcher itself keep list of idle actors. When new task need to be done and list is not empty, worker is taken from the list and task is sent (worker could be removed from list immediately, but safe to work with Ack to be sure that task is taken for processing, or re-send to another worker if Ack is timed out)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With