Mastering Nginx

(Ron) #1

Reverse Proxy Advanced Topics


[ 102 ]

Directive Explanation
proxy_buffering Activates buffering of proxied content;
when switched off, responses are sent
synchronously to the client as soon as
they are received, provided the proxy_
max_temp_file_size parameter is set
to 0. Setting this to 0 and turning proxy_
buffering to on ensures that there is no
disk usage during proxying, while still
enabling buffering.
proxy_buffers The number and size of buffers used for
responses from upstream servers.
proxy_busy_buffers_size The total size of buffer space allocated to
sending the response to the client while still
being read from the upstream server. This is
typically set to two proxy_buffers.

In addition to the preceding directives, the upstream server may influence buffering
by setting the X-Accel-Buffering header. The default value of this header is yes,


meaning that responses will be buffered. Setting the value to no is useful for Comet


and HTTP streaming applications, where it is important to not buffer the response.


By measuring the average request and response sizes going through the reverse


proxy, the proxy buffer sizes can be tuned optimally. Each buffer directive counts
per connection, in addition to an OS-dependent per-connection overhead, so we


can calculate how many simultaneous client connections we can support with the
amount of memory on a system.


The default values for the proxy_buffers directive (8 4k or 8 8k, depending on
the operating system), enable a large number of simultaneous connections. Let's


figure out just how many connections that is. On a typical 1 GB machine, where
only NGINX runs, most of the memory can be dedicated to its use. Some will be


used by the operating system for the filesystem cache and other needs, so let's be


conservative and estimate that NGINX would have up to 768 MB.


Eight 4 KB buffers is 32,768 bytes (8 4 1024) per active connection.


The 768 MB we allocated to NGINX is 805,306,368 bytes (768 1024 1024).


Dividing the two, we come up with 805306368 / 32768 = 24576 active connections.

Free download pdf