Report this

What is the reason for this report?

Disable upstream response buffering nginx

Posted on October 17, 2020

Nginx keeps logging below message on my error log

[warn] 16387#16387: *1117 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/1/32/0000000321 while reading upstream, client: 173.245.54.175, server:

this fills up my log files , i want to disable buffering completely ,

i’ve tried turning proxy_buffering proxy_buffering off; but the logs keeps showing that nginx/fastcgi is buffering responses

How do i turn off buffering all together ?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bumped into your question while figuring out my case, not sure if this helps you but there is a separate setting to disable fastcgi buffering:

fastcgi_buffering off;

See also https://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_buffering

Hello,

To add to what Jan mentioned, the discovery that setting fastcgi_buffering off; resolves the issue with responses ‘freezing’ after a certain byte size on the DigitalOcean App Platform is quite insightful.

This problem can indeed stem from how buffering is handled between Nginx and PHP-FPM, especially under the constraints or specific configurations of a managed platform like the DigitalOcean App Platform.

Understanding FastCGI Buffering

FastCGI buffering in Nginx controls whether the response to a request, which is served by a FastCGI server like PHP-FPM, should be buffered. When enabled (which is the default behavior), Nginx will buffer responses in memory or on disk before sending them to the client. This can improve performance for certain applications by freeing up FastCGI processes to handle other requests instead of waiting for clients to acknowledge receipt of data.

Why Disabling FastCGI Buffering Helped

Disabling FastCGI buffering (fastcgi_buffering off;) means that Nginx forwards the response from PHP-FPM to the client immediately as it receives it, without waiting for the entire response to be received from the backend. This approach can resolve issues in environments where buffering configurations are not optimal for the application’s response patterns, leading to problems like the one you encountered.

Potential Drawbacks

  • Performance Impact: Disabling buffering might increase the load on your PHP-FPM processes, as they now have to maintain connections longer. This can impact the application’s ability to handle high concurrency levels efficiently.
  • Increased Resource Usage: With buffering disabled, each active connection will hold onto PHP-FPM processes for a longer period, potentially increasing memory and CPU usage.
  • Throughput: The throughput of your application might decrease, especially under high load, as the system can no longer benefit from the efficiency gained by buffering responses.

The specific cause can be difficult to pinpoint without detailed knowledge of the DigitalOcean App Platform’s internal networking and configuration nuances. It could be related to the default buffer sizes and the way the platform handles network traffic between containers. The issue might not manifest in local Docker environments due to differences in network latency, available resources, or other environmental factors.

While disabling FastCGI buffering solved the immediate issue, it’s worth considering the following for a more robust solution:

  • Review Application Output: If possible, review how your application generates output. Large responses, especially JSON, might benefit from optimization or pagination.
  • Customize Buffer Sizes: Instead of disabling buffering entirely, adjusting buffer sizes with directives like fastcgi_buffers and fastcgi_buffer_size might provide a middle ground, allowing you to benefit from buffering while accommodating larger responses.
  • Monitor Performance: Keep an eye on your application’s performance and resource utilization. If disabling buffering leads to issues, reconsider the configuration or explore other optimizations.

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.