Search code examples
phpzend-frameworkcentosamazon-sqs

Scaling cronjobs over multiple servers


right now, we have a single server with a cronjob tab that sends out daily emails. We would like to scale that server. The application is standard zend framework application deployed on centos server in amazon cloud.

We already took care of the load balancing, content management and managing deployment. However, the cronjob is still an issue for us, as we need to grantee that some jobs are performed only once.

For example, the daily emails cronjob must only be executed once by a single server. I'm looking for the best method to grantee only one server will execute it only once.

I'm thinking about 2 solutions, but i was wondering if someone else had the same issue.

  1. Make one of the servers "master", who only sends out the daily emails. That will be an issue, if the server malfunction, and generally we don't want to have a "special" server. It would also means we will need to keep track which server is master.
  2. Have a queue of schedule tasks to be performed. Each server open that queue and sees which tasks needed to be performed. The first server who "grab" the task, will preform the task and mark it as done. I was looking at amazon simple queuing service as a solution for the queue.

Both these solutions have advantages and disadvantages, and i was wondering if someone thought about someone else that might help us here.


Solution

  • When you need to scale out cron jobs, you are better off using a job manager like Gearman