Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 571
aporat Avatar asked Jun 20 '11 17:06

aporat


People also ask

Are cron jobs scalable?

Cron jobs aren't designed for the cloud. If the machine image holding your cron job scales out to 20 instances, your cron job will be executed 20 times more often. This is fine if the scope of your cron job is limited to the instance itself, but if the scope is larger, the above becomes a serious problem.

Can 2 cron jobs run at the same time?

You can use two options to set multiple commands in the same cron job. 1. Use the &&: the double ampersand specifies that the second command should only run if the one before it is successful.

Where should I put my Cronjobs?

Cron jobs are typically located in the spool directories. They are stored in tables called crontabs. You can find them in /var/spool/cron/crontabs. The tables contain the cron jobs for all users, except the root user.

What is * * * * * In cron job?

What does * mean in Cron? The asterisk * is used as a wildcard in Cron. * sets the execution of a task to any minute, hour, day, weekday, or month.


1 Answers

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

like image 81
datasage Avatar answered Oct 21 '22 05:10

datasage