Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad to use unicorn without nginx? why?

I read that unicorn is fast to serve static content, slow users, making redirects.

Why is better nginx+unicorn vs running unicorn only, and scale the number of unicorn workers when needed?

Do you have any numbers showing how much fast is nginx on each of these things(redirecting, proxying, serving static content)?

like image 793
sites Avatar asked Mar 16 '23 01:03

sites


1 Answers

As Heroku DevCenter claims, Unicorn workers are vulnerable to slow clients.

Each worker is only able to process a single request, and if the client is not ready to accept the entire answer (aka "slow client"), the Unicorn worker is blocked on sending out the response and cannot handle the next one. Since each Unicorn worker takes up a substantial amount of RAM (again, see Heroku, it claims to handle 2-4 processes at 512 MiB RAM), you cannot rely on number of workers, since it's about the number of clients that can render your application inoperable by pretending to have slow connections.

When behind nginx, Unicorn is able to dump the entire answer into nginx's buffer and switch immediately to handling the next request.

That said, nginx with a single Unicorn worker behind is much more reliable than a bunch of Unicorn workers exposed directly.

NB: for the folks using ancient Rubies out there: if you'll be using a set of Unicorn workers, consider migrating to at least Ruby 2.0 to reduce RAM consumption by sharing common data across forked processes (ref).

like image 83
D-side Avatar answered Apr 23 '23 07:04

D-side