2

I am using the whenever gem to call rake-based cron tasks, however... when the tasks are run, the whole site (Passenger on Nginx) stops responding for the duration of the task.

Is there anyway to control the load of these rake tasks to take a lesser tole on server performance?

2 Answers2

3

Using the 'whenever' gem, inside config/schedule.rb, you can override the rake task definition to add a "nice -n 19" command before rake is executed, making it run at low priority.

job_type :rake, "cd :path && RAILS_ENV=:environment nice -n 19 bundle exec rake :task --silent :output"
1

That's little info, but here are some pointers:

  • Running rake will load the entire Rails stack. Make sure you have a system that can handle that load. What happens with memory usage when you run the rake tasks?
  • What does your rake task do? Does it call a URL from your app, causing it to block?

If the rake task you perform is eating up a lot of CPU or memory you should consider scaling up. Either vertically, by adding more RAM/CPU cores or horizontally, by running the rake task on another machine instead.

Ariejan
  • 10,910
  • 6
  • 43
  • 40
  • OK, but is there any way to perhaps set the "nice" value of the rake process to allow the web server to continue processing requests relatively unhindered? We are basically looping through DB objects and sending emails. – brett-richardson Oct 21 '11 at 14:40