Book Image

Nginx Essentials

By : Valery Kholodkov, Valery I Kholodkov
Book Image

Nginx Essentials

By: Valery Kholodkov, Valery I Kholodkov

Overview of this book

Table of Contents (13 chapters)

Optimizing static file retrieval


Static file retrieval performance directly affects visitors' perceived website performance. This happens because web pages usually contain numerous references to dependent resources. These resources need to be quickly retrieved before the entire page can be rendered. The faster the web server can start returning a static file (lower latency) and the higher the parallelism of retrieval, the higher the perceived performance of the website.

When the latency is the driving factor, it is important that files are returned predominantly from the main memory, as it has much lower latency compared to hard drives.

Fortunately, the operating system already takes very good care of that through filesystem cache. You only need to stimulate cache usage by specifying some advisory parameters and eliminating waste:

location /css {
    sendfile on;
    sendfile_max_chunk 1M;
    [...]
}

By default, Nginx reads the content of a file into the user space before sending to the client...