Tour to Ruby WebServer
Bài đăng này đã không được cập nhật trong 8 năm
Introduction
Nowaday applications developed using Ruby can be exposed to the World-Wide-Web through one of the many available web servers. Choosing which web server to use for your web application might be hard, so I'm going to do a little run over and point out each features that each web server offer.
Phusion Passenger: Fast web server & app server
Passenger is a mature feature rich which aims to cover necessary needs and areas of application deployment whilst greatly simplifying the set-up and getting-started procedures. It works by integrate directly within Apache and NGINX web servers which eliminate the need for middleware server. For this very reason it is also referred to as modrails / modrack amongst the Ruby and Rails community.
Passenger provides the ability to work with multiple applications hosted on the same server and capable of handling slow clients. Requests and responses are fully buffered make it immune to attacks targeting to clog systems' resources.
Passenger come with two flavors, open-source and enterprise. Open-source version has multi-process single-threaded operation mode while enterprise version can be configured to work either single-threaded or multi-threaded.
Puma: A Modern, Concurrent Web Server
Puma is a Rack exclusive Ruby web application server. It was designed to support true parallelism and as "the go-to server" for Rubinius, but works well on MRI as well as JRuby. Since MRI has global interpreter lock which prevent application from running truly in concurrent, it's recommended that we use puma with Rubinius or JRuby.
Puma has quite a small foot print, both in size and execution resources consumption. It has several working modes: it allows you to set the amount of minimum and maximum threads it can use to do its job and also works in a clustered mode whereby you can use forked processes to handle requests concurrently. It comes with a simple, yet significant configuration option set to adapt the web server both for production and development needs in many ways.
Thin: Tiny & Fast HTTP Server
Thin is a very popular application server which claims itself to be the most "secure, stable, fast and extensible Ruby web server". It was built based on three ruby libraries:
- Mongrel's parser
- Event Machine network I/O library
- Rack middleware
Thin HTTP server is designed to work with any framework implementing Rack specification. As an Event / Machine based application server, Thin is capable of handling long running requests without the help of a front facing reverse-proxy solution.
Unicorn: Rack HTTP Server for Fast Clients
Unicorn is a very mature fully-featured web application server. It denies by design trying to do everything: Unicorn's principal is doing what needs to be done and delegating rest of the responsibilities to those which do them better. Unicorn has a master process that spawns workers, as per your requirements, to serve the requests. This master process also monitors the workers in order to prevent memory and process related staggering issues. Much like NGINX, with Unicorn you can perform and deploy your applications without dropping alive connections and clients. All workers run within a given isolated address space, serving one request at a time.
Conslusion
For someone who just looking a quick start on deploying ruby application to production server I would recommended that you go with Passenger as it porvides easy configuration and tool for you to manage your application, but if your application is in a need for highly concurrentcy then go with Puma + Rubinius/JRuby. As for Thin and Unicorn I haven't try it myself yet so I can't tell you how good it is, so took your time play around with it yourself and share with me what you think.
All rights reserved