Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx client_body_buffer_size and client_max_body_size optimizations for large POST requests

Tags:

nginx

I have an API that receives anywhere from 1K to 20MB of data in each transmission. I also have a website that would only ever receive less than 10K in a single transmission. Both the API and the website are behind the same Nginx proxy server.

From the docs for client_body_buffer_size

If the request body size is more than the buffer size, then the entire (or partial) request body is written into a temporary file."

This means that any time I receive a request over the default, it will be written to disk.

Given that I can receive large payloads, would it be best to set the client_body_buffer_size equal to client_max_body_size, which for me is 20MB? I assume this would prevent nginx from writing the request to disk every time.

Are there any consequences to setting the client_body_buffer_size so high? Would this affect the website, which never receives such large requests?

like image 233
Matthew Moisen Avatar asked Jan 26 '16 00:01

Matthew Moisen


1 Answers

It depends on your server memory and how many traffic you have.

A simple formula: MAX_RAM = client_body_buffer_size X concurrent_traffic - OS_RAM - FS_CACHE.

(exactly the same thing with php-fpm pool tuning or even mysql/elasticsearch).

The key is to monitor all the things (RAM/CPU/Traffic) and change settings according your usage, star little of course then increase until you can.

like image 89
Thomas Decaux Avatar answered Nov 16 '22 02:11

Thomas Decaux