ruby-on-railsrubypumapuma-dev

puma workers vs separate ec2 instances


I am coming from Java/Tomcat stack and total newbie to RoR stack. I am trying to understand some of the concepts around puma configuration. I have read this and this but I am still unclear on workers terminology.

I understand that workers result in child process running puma. So essentially that allows you achieve parallelism, when using multi-core instance. But you can also do the same by launching as many ec2 single core instances?

Also, would it ever make sense to set workers > 0, if the instance is not multi-core.

Any info here would immensely help me. Thanks!


Solution

  • In the context of Puma workers and threads are both used to achieve concurrency so that Puma can process requests without always waiting for the previous requests to be finished. A good configuration will need to find a good balance between the amount of workers and threads and several aspects of the deployed application need to be taken into consideration:

    Comparing multiple workers to deploying to multiple EC2 instances misses a part of the picture: when using Puma with multiple workers there's a master Puma process that listens on a port and routes each request to an available worker process. When you have multiple EC2 instances then you need to take care of load balancing between them in some way - in the case of AWS that could be ELB or ALB. Deploying to multiple instances and load balancing are the right way to deploy any serious web application any way but that should not stop you utilizing instance resources better through workers and threads.

    I'd suggest experimenting with the configuration of workers and threads and starting at setting workers to the number of cores and threads to 10 - then make adjustments if you encounter problems with memory usage or under utilization of resources.