Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why rails 5 using puma instead of webrick for development purpose?

I tried to find out the difference between the Puma and Webrick, but didn't get it or satisfied with it.

So could any one please share information regarding it.

like image 623
Kishor Vyavahare Avatar asked Apr 05 '18 14:04

Kishor Vyavahare


2 Answers

This is a question for Ruby on Rails developers rather than broad audience, because I don't understand reasons any other that putting development environment closer to production where Puma is a solid choice.

To correct the current answer however, I must say that Webrick is, and always has been, a multi-threaded web server. It now ships with Ruby language (and also a rubygem is available). And it is definitely good enough to serve Rails applications for development or for lower-scale production environments.

On the other hand it is not as configurable as other web servers like Puma. Also it is based on the old-school new thread per request design. This can be a problem under heavy load which can lead to too many threads created. Modern web servers solve this by using thread pools, worker processes or combination of the two or other techniques. This includes Puma, however for development spawning a new thread per request is totally fine.

I have no hard feelings for any of the two, both are great Ruby web servers and in our project we actually use them both in production. Anyway, if you like using Webrick for RoR development, you indeed can still use it:

rails server webrick
like image 25
lzap Avatar answered Oct 24 '22 23:10

lzap


By default WEBrick is single threaded, single process. This means that if two requests come in at the same time, the second must wait for the first to finish.

The most efficient way to tackle slow I/O is multithreading. A worker process spawns several worker threads inside of it. Each request is handled by one of those threads, but when it pauses for I/O - like waiting on a db query - another thread starts its work. This rapid back & forth makes best use of your RAM limitations, and keeps your CPU busy.

So, multithreading is achieved using Puma and that is why it is used as a default App Server in Rails App.

like image 87
Rohan Avatar answered Oct 24 '22 22:10

Rohan