2

I have read here that the Unicorn/Gunicorn HTTP server is 'not very good at serving static files', and that Nginx is better at serving static content. Can someone explain why this is?

I understand the specialised roles of Nginx and Gunicorn, and that Nginx is a reverse proxy, and that Gunicorn can actually serve static files if necessary.

Community
  • 1
  • 1
geonaut
  • 349
  • 2
  • 14
  • I've been reading the Unicorn design specification documents [here](https://bogomips.org/unicorn/), and [here](https://bogomips.org/unicorn/DESIGN.html). Could it be that Gunicorn is simply 'un-optimised' compared to Nginx? eg. it doesn't use `sendfile()`, which allows direct server->client transer? – geonaut Mar 09 '17 at 13:50

1 Answers1

3

Primarily because Unicorn was not designed to solve the suite of problems involved in serving files to clients:

Unicorn is a server for fast clients and Unix. What is a fast client? A fast client is another application or server that can interface with the Rack server quickly, without much latency. Unicorn is not good as a standalone server: it wasn’t designed to handle slow requests that occur over network connections. It relies on Nginx or Apache to handle the buffering and queuing of web requests so that it doesn’t have to worry about concurrency and event-driven programming. Unicorn is basically the glue between nginx and rack, where Nginx is the fast client.

Source

Consider a case where you have 100 visitors on 56k modems trying to view a 400mb video. You really don't want to have to hold 100 instances of your application in memory, or load the file into memory, etc. Nginx was designed with this type of scenario in mind.

coreyward
  • 77,547
  • 20
  • 137
  • 166
  • Ok thanks @coreyward, So if I understand correctly, serving files well is a function that needs to be able to adapt to different connection speeds, and potentially, interrupted connections etc. Unicorn works with fast clients (i.e. localhost), and doesn't play nicely with laggy remote connections. I think I was kinda on the right lines when I said Unicorn is 'unoptimised' for serving files. – geonaut Mar 12 '17 at 18:30