Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone run more than one resque worker in a Heroku Dyno?

Tags:

heroku

resque

Given that unicorn usually manages more than one Rails server process, and given that a Resque job runner probably consumes less resources than a Web request, it should be possible to run more than one resque worker on a single Heroku dyno.

Is anyone doing this successfully so far? My thoughts are, that an easy way to do so would have the Procfile runs foreman, which then runs 2 (or more) instances of the actual worker (i.e. rake resque:work)

Or is rake resque:workers up to that task? Resque itself does not recommend using that method, as this starts workers in parallel threads instead of in parallel processes.

Obviously, this makes sense only on i/o bound jobs.

like image 895
radiospiel Avatar asked Aug 11 '13 19:08

radiospiel


People also ask

How many Heroku dynos do I need?

By default, applications are limited to 100 total dynos across all process types. Additionally, a single process type that uses performance dynos can't be scaled to more than 10 dynos. Submit a request to raise this limit for your application.

What is workers in Heroku?

Heroku allows you to specify an application-specific process model, which can include background workers retrieving and processing jobs from the work queue.

How do I stop Heroku workers?

That is, log into heroku, go to your app's Resources page, and drag the "Worker Dynos" slider to zero, then save the changes via the "Save and Apply" button on the top-right.

What is web and worker in Heroku?

Web: Web dynos are dynos of the “web” process type that is defined in your Procfile. Only web dynos receive HTTP traffic from the routers. Worker: Worker dynos can be of any process type declared in your Procfile, other than “web”. Worker dynos are typically used for background jobs, queueing systems, and timed jobs.


2 Answers

One can use foreman to start multiple processes. Add foreman to your Gemfile, and then create two files:

Procfile:

worker: bundle exec foreman start -f Procfile.workers

Procfile.workers:

worker_1: QUEUE=* bundle exec rake resque:work
worker_2: QUEUE=* bundle exec rake resque:work

The same technique can be used to run a web server alongside some workers.

NOTE: while many state success using this approach, I would not suggest to use it outside of some experiments, mostly because of the risk to run into RAM limitations on small heroku instances; and once you pay for the heroku service it is probably easier to just spin up a dedicated worker machine anyways.

like image 145
radiospiel Avatar answered Sep 27 '22 19:09

radiospiel


Based on this article, it sounds like it's possible, but the biggest gotcha is that if one of the child processes dies, Heroku won't be able to restart it.

like image 43
CDub Avatar answered Sep 27 '22 20:09

CDub