Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to correctly set the number of workers and threads in a Rails application using Puma?

Is there any formula to discover the number of workers and threads in a Rails application using puma ? Worker would be the number of cores ? How about threads ?? I've tried to search in similar topics, but it was not clear to me...

like image 633
andrefurquin Avatar asked Jul 04 '16 19:07

andrefurquin


2 Answers

Even if your not on Heroku they have good doc about Puma. Like this one: link

This answer helped me when I was asking myself the same question.

Basically I set the number of workers matching the number of cores and the number of threads according to the ram amount. But I'm not doing this with a rocket science formula (maybe I should), it's more like a try and adjustment process.

As a bonus reading I would suggest this article about how to scale a rails app to 1000 req/sec, it gives interesting suggestions: link

like image 190
coding addicted Avatar answered Oct 02 '22 00:10

coding addicted


Number of Worker * Number of threads inside the worker = Database Connection pool size

For example, if you are using 2.5 GB RAM's plan and you want to make use of it up around 2 GB.

1 worker * 8 threads = 8(DB pool size)
like image 42
zawhtut Avatar answered Oct 02 '22 02:10

zawhtut