Nginx configuring uwsgi and gzip buffers for different usage scenarios

buffergzipnginxuwsgi

I'm trying to configure two URL path groups for relatively different usage scenarios and resource consumption in nginx. Both are served by same uwsgi application.

  • Group 1: Regular HTML pages up to cca 128k in size, default
  • Group 2: Large XML "files" up to many MB in size (created by the app on the fly)

The requirement is for both to be gzipped, and the XMLs should be cached 1hr as well.

What I don't quite understand is the meaning of the number of buffers and how to optimally set their number and sizes according to expected traffic and content size, both for uwsgi and gzip.

Also, for the below configuration I get error from nginx:

"uwsgi_busy_buffers_size" must be less than the size of all "uwsgi_buffers" minus one buffer in /etc/nginx/nginx.conf:113

uwsgi_busy_buffers_size appears to be undocumented.

location ~ /path/to/(.+)\.xml {
    uwsgi_hide_header       "Set-Cookie";
    uwsgi_ignore_headers    "Set-Cookie";
    uwsgi_buffers           2 8M;
    uwsgi_cache             xmlfiles;
    uwsgi_cache_key         $request_uri;
    uwsgi_cache_valid       200 1h;
    uwsgi_cache_valid       04 5m;
    uwsgi_cache_use_stale   error;
    expires                 +1h;

    gzip                    on;
    gzip_types              application/xml;
    gzip_buffers            2 8M;

    try_files               $uri @backend;
}

location / {
    try_files       $uri @backend;
    gzip            on;
    gzip_buffers    8 256k;
    uwsgi_buffers   8 256k;

    try_files       $uri @backend;
}

location @backend {
    include      uwsgi_params;
    uwsgi_pass   unix:///tmp/uwsgi-app.sock;
}

Please help. nginx 1.0.14

Best Answer

uwsgi_busy_buffers_size has the same meaning as fastcgi_busy_buffers_size, but for uwsgi.

Limits the total size of buffers that can be busy sending a response to the client while the response is not yet fully read. In the mean time, the rest of the buffers can be used for reading a response and, if needed, buffering part of a response to a temporary file. By default, size is limited by two buffers set by the uwsgi_buffer_size and uwsgi_buffers directives.

p.s. default values of the buffers related directives in nginx have optimal values for most cases. So, you should tune them only if you are fully understand what you're doing and why.