I'm managing a server witch host several ruby on rails websites. I need a cron job for every website that does :

  • send emails (notifications)
  • create thumbnails

Unfortunatly, every time the cron is executed, it takes 100% of the CPU usage, so that slows down all the websites.

I tried to use nice command in my crontab -e:

cd /home/www/manager && nice -n 19 /usr/local/bin/rake websites_cron RAILS_ENV=production

but after a little while i get rack process and passenger process with the same nice level as rake so it doesnt help at all...

Here is htop output with low usage http://img688.imageshack.us/img688/3637/capturedu20120807143520.png

Here is htop when cron job are executed http://img507.imageshack.us/img507/1736/capturedu20120807144808.png


--- Edit ---

I had an error in my code that was rebuilding all websites process The nice command is working

  • This is not cron using the CPU - it's rake running from cron - the problem is in your code. – symcbean Aug 7 '12 at 13:14
  • Why would you think this was cron, it's clearly a ruby process eating your CPU – Chopper3 Aug 7 '12 at 13:15
  • My cron is only ruby process, so i would like to limit this particullar cron/ruby process. Yeah, the title isnt really good – boby lapointe Aug 7 '12 at 13:22
  • If using nice doesn't allow the process to finish before the next invocation of the cron job starts then you either need to make the code use less CPU by improving it, or else give it more CPU by upgrading the hardware. – grifferz Aug 7 '12 at 13:51

The process has been nice'd to lower it's priority and htop reflects that. It will still gladly use 99% of the CPU if there's no contention. Can you confirm that the bottle neck is in the CPU, and not I/O? Maybe you need to increase the priority of the website processes to higher than the default?

Also, how many cores does your host have? Your overall load average at 1.6 is below capacity for a dual-core system. If it's a single-core system, you should probably consider a hardware upgrade.

  • Nice article, it's a C2D thought. By the way, how do i monitor I/O usage ? What is the difference between setting website process to high than setting the cron process to low – boby lapointe Aug 7 '12 at 15:02
  • It was just an idea that might help. Really, your cron is already set to idle priority so it shouldn't be necessary. I am more concerned that the bottleneck is I/O, so you're seeing 99% CPU since there's no contention for that resource. iotop will help see usage specific to disk reads/writes. – Aaron Copley Aug 7 '12 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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