Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play 2 Java scheduled Akka jobs in clustered setup

I have some Akka jobs running on my Play 2.0.4 dev setup. For production the application will be deployed to a clustered setup and I would need to ensure some scheduled jobs happen do not happen in paralel - for example the import happens only in single node and no new import will be started before it finishes.

Any suggestions or pointers? Or is Akka wrong tool for such?

like image 403
Petteri H Avatar asked Dec 06 '25 02:12

Petteri H


2 Answers

Is this a proper Akka cluster?

You can use a cluster-singleton to to enforce the job only happens 1 time

http://doc.akka.io/docs/akka/snapshot/contrib/cluster-singleton.html

If your work load is too much for 1 actor to do, then you will want to still use a cluster-singleton.. but use him as a master, and have him dish out work to slaves to do the actual work. If you keep only 1 master and N slaves, you can be sure to only do the job one time.

like image 138
bwawok Avatar answered Dec 09 '25 20:12

bwawok


My guess is that you should separate the "front-end" from the "back-end". Let the clustered Play application handle the web-requests and build another app that takes care of the background jobs.

It might also be possible to tweak the Akka configuration in a way that the Actor that takes care of the background jobs is always looked up on a single cluster node. Probably this would only make sense if you need an easy way to communicate with this actor, though. Check the Akka documentation on Remoting for more details on this.

like image 27
Lunikon Avatar answered Dec 09 '25 19:12

Lunikon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!