Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rather large and slow (complex data, complex frontend) web application build in RoR and served by Puma with nginx as reverse proxy. Looking at the nginx error log I see quite a few entries like:

2014/04/08 09:46:08 [warn] 20058#0: *819237 an upstream response is buffered to a temporary file /var/lib/nginx/proxy/8/47/0000038478 while reading upstream, client: 5.144.169.242, server: engagement-console.foo.it, request: "GET /elements/pending?customer_id=2&page=2 HTTP/1.0", upstream: "http://unix:///home/deployer/apps/conversationflow/shared/sockets/puma.sock:/elements/pending?customer_id=2&page=2", host: "ec.reputationmonitor.it", referrer: "http://ec.foo.it/elements/pending?customer_id=2&page=3"

I find it rather curious as it's very unlikely that that page remains the same for different users and different user interactions, and I would not think that buffering the response on disk necessary/useful.

I know about proxy_max_temp_file_size and setting it to 0, but it seems to me I little bit awkward to me (my proxy tries to buffer but has no file where to buffer to... how can that be faster?).

My questions are:

1) How can I remove the [warn] and avoid buffering responses? Is it better to turn off proxy_buffering or set proxy_max_temp_file_size to 0? Why?

2) If nginx buffers a response when does it serve the buffered response, to whom and why?

3) Why nginx turns proxy_buffering on by default and then [warn]s you if it actually buffers a response?

4) When does a response triggers that option? When it takes > than some seconds (how many?) to serve the response? Is this configurable?

TIA, ngw

share|improve this question
    
I have a feeling that you are confusing buffering with caching. The buffering is the procedure that allows loading more data than allowed by memory allocation. – Slavic Jul 25 at 15:32
up vote 32 down vote accepted

1) How can I remove the [warn] and avoid buffering responses? Is it better to turn off proxy_buffering or set proxy_max_temp_file_size to 0? Why?

You should set proxy_max_temp_file_size to 0 in order to remove it. The proxy_buffering directive isn't directly related to the warning. You can can switch it off to stop any buffering at all but that isn't recommended in general (unless it's needed for Comet).

2) If nginx buffers a response when does it serve the buffered response, to whom and why?

It servers immediately, but a client usually has much slower connection and can't consume the response data as fast as it produced by your application. Nginx tries to buffer the whole response in order to release your application ASAP.

See also: http://aosabook.org/en/nginx.html

3) Why nginx turns proxy_buffering on by default and then [warn]s you if it actually buffers a response?

As I already mentioned, the proxy_buffering isn't directly related to the warning. It's generally needed for optimized proxy operations and turning it off degrades performance and throughput.

Nginx only warns you when a response doesn't fit into configured memory buffers. You may ignore the warning if it's ok for you.

4) When does a response triggers that option? When it takes > than some seconds (how many?) to serve the response? Is this configurable?

It triggers when memory buffers are full. Please, look at the docs, the whole mechanism is explained: http://nginx.org/r/proxy_max_temp_file_size

You may want to increase memory buffers.

share|improve this answer

The following configuration works fine on my server.

proxy_buffers 16 16k;  
proxy_buffer_size 16k;
share|improve this answer
    
Is the second directive redundant, i.e. the 16k in the first line is doing the exact same as the second line? – EoghanM Jul 5 at 10:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.