Recommendations for WEB_CONCURRENCY or RAILS_MAX_THREADS

Your rails tutorial tells us to configure Puma to use the WEB_CONCURRENCY, however this var is not set for the container running the web service.
Do you set this variable ever or is it always at default or should we tune it ourselves?
The same goes for RAILS_MAX_THREADS and related DB connection pool sizing? Are there any recommended values for these for given instance sizes?

1 Like

Hello,

I believe the example app uses the default values, which is a good starting point. Your app will have its own resource consumption profile, so you’d need to tune these parameters yourself to get optimal performance.

Why do you then have enabling WEB_CONCURRENCY as part of the tutorial when effectively this is a no-op?

By default values, I mean we don’t see the environment variable in our example and as
4 is the default value used if the environment variable isn’t set, it uses 4 workers.

The line
workers ENV.fetch("WEB_CONCURRENCY") { 4 } will return the value of WEB_CONCURRENCY if it is set, otherwise the block { 4 } is executed, which yields 4 and 4 is used.

https://ruby-doc.org/core-3.0.1/ENV.html#method-c-fetch

I’d say you always want to be making best use of the environment available. The default for WEB_CONCURRENCY in the tutorial config is 4 - with that config my fairly vanilla Rails app consumes about 300Mb on the default instance size of 512Mb, there’s probably a bit more wiggle room there but it very much depends on the application and how it uses memory. As you scale vertically you have more resources available so you’d want to change the concurrency to suit to ensure you’re making full usage of the resources available.