2

I'm running rake tasks each minute that are instantiating the Rails environment about every minute presently as workers with Foreman and a cron gem. I'm concerned as just firing up Rails alone consumes about 90% of one of the processors for roughly 20 seconds each time. What would be the most efficient way of handling something like this that needs the Rails environment for db access and some libraries, but should not be having to fire up the entire system so constantly?

There are also, on top of this, a few other workers that need to start so it compounds the situation.

ylluminate
  • 12,102
  • 17
  • 78
  • 152

2 Answers2

1

If I were you I'd check out some async messaging frameworks: Resque vs Sidekiq?. With those Rails does only need to be loaded once and the processes can reuse that Rails when necessary. I think this is done by forking. Not too sure tho.

Community
  • 1
  • 1
Sascha Kaestle
  • 1,293
  • 12
  • 15
1

We had a similar issue for a odds scraper we run every 30 seconds, switching to resque & resque-scheduler was a better way.

https://github.com/bvandenbos/resque-scheduler

http://railscasts.com/episodes/271-resque

http://railscasts.com/episodes/366-sidekiq

Nath
  • 6,774
  • 2
  • 28
  • 22