How many instances do you need?
There's a theoretical tool we can use, the number of instances must obey Little's Law. The definition from Wikipedia is so hard to understand. So, basically, we just need to know the formula
Number of application instances = Average number of requests per second (requests/second) * Average response time (second)
Application Instances, its job is process a single request dependently and send it back to client. When using Puma in threaded mode, application instance is the entire Puma process, when using MRI, JRuby,each thread counts as an application instance. When using Unicorn, Puma (clustered) or Passenger, your application instance is each worker process.
For example:
My application haves:
- Average rps (request per second): 153
- Average response time: 300ms
So the application instance: 153 * 0.3 =~ 46 instances