Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm installing a bunch of Magento shops on a webserver. Every website has a cron job that Magento uses to update its stuff -- it takes 3-4 seconds to complete. The instructions tell to set it to run every 5 minutes.

I was asking to myself if is it advisable, for performance reasons, to set every cron to run at different minutes (e.g.: minute 0, 5, 10, etc for the first website -- minute 1, 6, 11, etc for the second and so on), to reduce overlapping, or if this is useless because linux executes multiple cron jobs at the same minute in order, avoiding concurrency.

share|improve this question
2  
Short answer is yes : It is advisable : If you have one cron entry per magento instance, cron jobs will run concurrently –  coincoin Feb 6 '13 at 12:03

3 Answers 3

up vote 1 down vote accepted

Depends on.

If it isn't a problem to run these cron jobs simultaneously, so they don't interfere on each other by overwriting each-others files, etc... and if your machine can handle the peak load you can run them simultaneously.

If you wan't to smear the load on your server and your scripts handle well (don't depend on when it is run) then you can run them in different minutes. Also you can also add some randomness to it if you want with sleep $(( $RANDOM%100 )); somecommand to wait 1 to 100 random seconds before executing the script.

share|improve this answer
    
Thank you very much! Thanks also to Sonassi, I have chose the answer from Stone because he introduced this good idea of randomness ;) –  flip79 Feb 7 '13 at 12:00

The best thing to do here is test it.

Linux is capable of running multiple jobs at the same time. Depending on how resource intensive each job is there may be some contention if you start many jobs at the same time. Splitting them up doesn't cause any problems and would certainly reduce potential problems caused by multiple jobs starting at the same time.

share|improve this answer

Our shared hosting servers run up to 12 stores on a single machine - all of which are running their own cron tasks.

There is no problem at all doing this.

In terms of run schedules, we've found some modules are intolerant of the cron being executed at anything other than exactly 5 minute intervals, starting at 5 minutes past the hour.

So we advise against the typical Magento cron of

*/5 * * * * /home/path/public_html/cron.sh

And instead be more explicit

0,5,10,15,20,25,30,35,40,45,50,55  * * * * /home/path/public_html/cron.sh

Running the cron at other intervals may cause problems with some modules and the queued tasks could be flushed from the cron table in the DB and never executed.

share|improve this answer
    
"We've found some modules are intolerant..." - which ones? –  nickgrim Feb 6 '13 at 17:34
    
Camiloo Amazon comes to mind - but to be fair, we've seen hundreds of stores - with even more extensions. So as a guide to all our customers, we always recommend the latter format. –  Ben Lessani - Sonassi Feb 6 '13 at 17:36
    
*/5 means exactly the same thing as 0,5,10,15,20,25,30,35,40,45,50,55. –  mgorven Feb 6 '13 at 18:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.