Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine the right number of Puma workers and threads to run on a Heroku Performance dyno?

I've read all of the articles I can find on Heroku about Puma and dyno types and I can't get a straight answer.

I see some mentions that the number of Puma workers should be determined by the number of cores. I can't find anywhere that Heroku reveals how many cores a performance-M or performance-L dyno has.

In this article, Heroku hinted at an approach: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server

I think they're suggesting to set the threads to 1 and increase the number of Puma workers until you start to see R14 (memory) errors, then back off. And then increase the number of threads until the CPU maxes out, although I don't think Heroku reports on CPU utilization.

Can anyone provide guidance?

(I also want to decide whether I should use one performance-L or multiple performance-M dynos, but I think that will be clear once I figure out how to set the workers & threads)

like image 878
Keith Schacht Avatar asked Nov 02 '16 06:11

Keith Schacht


People also ask

Is Puma multi threaded?

Puma is a multi-threaded web server and our replacement for Unicorn. Unlike other Ruby Webservers, Puma was built for speed and parallelism. Puma is a small library that provides a very fast and concurrent HTTP 1.1 server for Ruby web applications. It is designed for running Rack apps only.

How many requests can a dyno handle?

The maximum number of processes/threads that can exist in a dyno at any one time depends on dyno type: free , hobby and standard-1x dynos support no more than 256. standard-2x and private-s dynos support no more than 512. performance-m and private-m dynos support no more than 16384.

Is one dyno enough for Heroku?

Heroku provides enough free hours to run a single dyno continuously for a month, but if we need a worker dyno for background processing (most apps do), we will not have enough free dyno hours. Free dynos are for great for demos, experimentation, and perhaps a staging app.


1 Answers

The roadmap I currently figured out like this:

  1. heroku run "cat /proc/cpuinfo" --size performance-m --app yourapp
  2. heroku run "cat /proc/cpuinfo" --size performance-l --app yourapp
  3. Write down the process information you have
  4. Googling model type, family, model, step number of Intel processor, and looking for how many core does this processor has or simulates.
  5. Take a look this https://devcenter.heroku.com/articles/dynos#process-thread-limits
  6. Do some small experiments with standard-2X / standard-1X to determine PUMA_WORKER value.
  7. Do your math like this:

(Max Threads of your desired dyno type could support) / (Max Threads of baseline dyno could support) x (Your experiment `PUMA_WORKER` value on baseline dyno) - (Number of CPU core)

For example, if the PUMA_WORKER is 3 on my standard-2X dyno as baseline, then the PUMA_WORKER number on performance-m I would start to test it out would be:

16384 / 512 * 3 - 4 = 92

You should also consider how much memory your app consumes and pick the lowest one.

EDIT: Previously my answer was written before ps:exec available. You could read the official document and learn how to ssh into running dyno(s). It should be quite easier than before.

like image 189
Ming Hsieh Avatar answered Sep 29 '22 01:09

Ming Hsieh