5

I'm an iOS developer and my back end is all written in Django. I use gunicorn as my HTTP server. I have three workers running on a small EC2 instance.

My iOS app does not require any images or static content. At most, I am sending 1-20 JSON objects at a time per request. Each JSON object has at most about 5-10 fields.

I'm quite new to NGINX. I heard it can do proxy buffering. I would like to add proxy buffering for slow clients, but I don't know the appropriate specific settings to use for the following modules:

proxy_buffers
Syntax:     proxy_buffers number size
Default:    8 4k|8k
Context:    http server location
Reference:  proxy_buffers


proxy_busy_buffers_size
Syntax:     proxy_busy_buffers_size size
Default:    8k|16k
Context:    http server location
Reference:  proxy_busy_buffers_size

proxy_buffer_size
Syntax:     proxy_buffer_size size
Default:    4k|8k
Context:    http server location
Reference:  proxy_buffer_size

The only setting which I know how to use (which is pretty sad) is the one below:

proxy_buffering
Syntax:     proxy_buffering on | off
Default:    on
Context:    http server location
Reference:  proxy_buffering

Your expertise in this area would be greatly appreciated by this kind lost soul!

deadlock
  • 7,048
  • 14
  • 67
  • 115

1 Answers1

7

proxy_buffers

The number defines how many buffers nginx will create and the size how big each buffer will be. When nginx starts receiving data from the upstream it starts filling up those buffers, either until the buffers are full or the upstream sends EOF or EOT. If any of those two conditions is met, nginx will send the contents of the buffers to the client.

If the client isn’t reading the buffers quickly enough, it will attempt to write the contents of them to disk and send them when the client is able to receive.

Take the average size of your JSON responses. Modern disks and file systems can handle even huge buffer sizes, but you should use something to the power of two and by creating a good balance between the number and size you can speed up the buffering process.

proxy_busy_buffers_size

These are buffers that were already passed downstream but not yet completely send and therefor they can’t be reused. This directive limits the maximum total size of such buffers and thus allows remaining buffers to be used to read upstream responses.

proxy_buffer_size

The main buffer that is always in use. Even if you disable proxy_buffering, nginx will still fill up this buffer and flush it as soon as it’s full or EOF/EOT.

proxy_max_temp_file_size

This directive controls how many data might be written to disk if the buffers are full (still utilizing in-memory buffers, because you need them to communicate with the disk). If all buffers and this file are full, nginx stops reading from upstream and has to wait for downstream to fetch the data before it can continue with the same procedure.

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
  • is there any specific settings that you would recommend for my case? How can I measure the size of the JSON objects to begin with? – deadlock Jun 19 '13 at 13:29
  • Measure the size of the files and determine the values of your environment. There are many good answers on how to find the perfect buffer size here on Stackoverflow, e.g. http://stackoverflow.com/questions/236861/ – Fleshgrinder Jun 19 '13 at 13:44
  • Btw. it’s impossible to give you an example configuration. Simply because one does not have the JSON files, nor access to the computer running nginx. One would need this information to create one. But even if one has access to these things, I’d recommend using the default values. Simply activate it. – Fleshgrinder Jun 20 '13 at 07:38