How to determine the optimal number of Puma workers when there are multiple Rails application in one server? #3087
-
I have a server with four CPU cores and two rails applications served with Puma web server. I've done some research and found out that for multithreaded case, I am supposed to set the number of workers equal to the number of CPU cores available. I assume this setting is for one application per server. If there are two applications on my server, should I set four worker for both application or should I divide the CPU core for each app and set two worker per application? I hope someone can help me with what is the optimal choice and explain the reason behind it. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
The optimal number is always 1 Puma worker process per 1 CPU core, then tune thread count so that the CPU core is well-utilized at maximum load. So, if I have 4 cores and 2 applications, I would configure 2 workers for the first application and 2 workers for the second application. |
Beta Was this translation helpful? Give feedback.
-
@nateberkopec so there is no sense to set 2 workers when there is one core? Heroku docs says: so they recommends 2 workers on instance with one core if there is enough RAM, this make any sense? |
Beta Was this translation helpful? Give feedback.
-
As you said, to set the number of worker -> 1:n /app where n is equal to CPU core and the whole divided by number of running applications. |
Beta Was this translation helpful? Give feedback.
The optimal number is always 1 Puma worker process per 1 CPU core, then tune thread count so that the CPU core is well-utilized at maximum load.
So, if I have 4 cores and 2 applications, I would configure 2 workers for the first application and 2 workers for the second application.