How do proxy_module response buffering options work?

Maxim Dounin mdounin at
Fri Nov 18 14:00:18 UTC 2011


On Thu, Nov 17, 2011 at 09:52:57PM -0500, liuzhida wrote:

> > Additionally, there is proxy_max_temp_file_size,
> > which controls how 
> > much data may be written to disk.  Once temp file
> > size becomes 
> > bigger - nginx pauses reading data from upstream
> > until data from 
> > temporary file is sent to client.
> do you mean if a response size is larger than all the proxy buffers,
> after some part of the response been written into buffers, the rest of
> data which can't be written into buffers will be written into temp_file?

Yes, as long as it's not possible to write data to client fast 

> for every single response? the proxy_max_temp_file_size are global or
> per request?

Per request.  It limits maximum size of a temporary file used to 
buffer a request.

> for example the upstream response is 2000 bytes. Nginx is configured
> with 4 buffers, each 100 bytes in size. is that nginx deal with this
> single response with written the 400 bytes of response into buffer and
> written the 1600 bytes into temp_file?

Roughly yes.  (There are some nuances though, as you can't write 
data to file without using in-memory buffers, and that's why some 
memory buffers will be reserved for reading response from upstream 
and writing it to disk.  And again, this all assumes it's not 
possible to write anything to client, while 2000 bytes usually 
just fit into socket buffer and will be passed to kernel 
immediately even if client isn't reading at all.)

> and after the buffer is
> completely send, Nginx will read the rest of response data from the
> temp_file and written into buffer? 

It will follow usual procedure to send file-backed data (the same 
one which is used for static files), i.e either it will use 
sendfile() or read data to output_buffers and send them.

Maxim Dounin

More information about the nginx mailing list