Tuning client request buffering in ngx_http_proxy_module

Francis Daly francis at daoine.org
Fri Feb 4 00:54:16 UTC 2022


On Wed, Feb 02, 2022 at 12:42:02PM -0500, bengalih wrote:

Hi there,

> > nginx opens a temporary file, immediately deletes it, and then 
> > uses this file for disk buffering.  The file is expected to be 
> > deleted from the very start, and it is expected to grow over time 
> > as it is used for disk buffering.  

> If a file is deleted, I am not aware of how it can still be used as a
> buffer.  This must be a linux mechanism I am not familiar with.

Yes.

A web search for something like "write to deleted file" will give you
some information on how it works.

Basically, Windows filesystems and Unixy filesystems tend to do things
differently.

> I guess I don't understand the difference between the default then of
> "client_body_in_file_only off" and "client_body_in_file_only on", at least
> in the case when the file is bigger than the buffer. 

http://nginx.org/r/client_body_in_file_only

When a request comes in, nginx collects the request body somewhere. That
can be "in memory", or "in a file". If you want some (external?) part of
your config to do something with the request body, it can be useful to
just share the file name, rather than to send the whole content. That
only works if there *is* a file name; which you arrange by setting
this directive.

The value of the directive also determines whether or not you are
responsible to delete any created file, after the processing is done.

> When I have it set to
> on I can at least see the whole file on disk, but when it is off you state
> the file is deleted and yet the space the file uses still remains.

The space the file uses is taken up on the disk, until the request
handling is complete and nginx closes the file handle and the filesystem
makes the space available for something else to use.

A file is not "really" deleted (as in: the space on-disk is unavailable
for something else to use) until the last thing that has the file open,
closes it.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list