Ruby rack application on 1 CPU - how many processes should I start?

I am brand new to Ruby web applications (from java). I have a VPS that has 1 processor and 2 GB of RAM and would like to play with some rails / sinatra.

I am using Ruby 2.1.0 MRI. How does the number of processors compare with the number of web server processes that I need to run? I use puma as a web server and set the default threads (0.16). But I noticed that there is also the “workers” option, which deploys another process in order to better handle multiple requests.

Do I understand correctly that for such an installation (1 CPU) it makes no sense to run 2 web server processes? The only sensible setup is 1 process with threads?

+3
source share
1 answer

Oh, now this is a pretty big question!

The number of processes and threads is not necessarily related to the number of processors. This relates more to the amount of available memory, the number of simultaneous requests, and the number of “blocking” things that happen.

If you have long requests that block other requests, then additional processes can help. You can still have multiple processes with one processor.

There are several different servers in Ruby that handle scaling in different ways, some of them Unicorn, Puma, Thin. Doing a search on Unicorn vs Puma vs Thin may lead to some useful blog posts on this topic.

Here is a couple

http://ylan.segal-family.com/blog/2012/08/20/better-performance-on-heroku-thins-vs-unicorn-vs-puma/ https://www.engineyard.com/articles/rails-server https://www.ruby-forum.com/topic/1822610

concurrency Ruby http://merbist.com/2011/02/22/concurrency-in-ruby-explained/

TL: DR, !

+2

All Articles