References:
https://gist.github.com/magnetikonline/11312172
https://easyengine.io/tutorials/nginx/tweaking-fastcgi-buffers/
Tweaking fastcgi-buffers
ACCESS_LOG="access.log"
echo "Average Response Size:" $(( $(awk '($9 ~ /200/)' ${ACCESS_LOG} | awk '{print $10}' | awk '{s+=$1} END {print s}') / $(awk '($9 ~ /200/)' ${ACCESS_LOG} | wc -l) ))
echo "Maximum Response Size:" $(awk '($9 ~ /200/)' ${ACCESS_LOG} | awk '{print $10}' | sort -nr | head -n 1)
Please note we taking HTTP 200 OK response only into consideration.
Based on above result, we found following values:
Avg. 24807
Max. 629622
So we are using:
fastcgi_buffers 32 32k;
fastcgi_buffer_size 32k;
Rahul Bansal says: December 18, 2013 at 12:37 pm " As far as I know, Nginx won’t allocate 1mb in one go. fastcgi_buffers 32 32k; will allocate buffers in pages of size 32k. First 32 will limit number of buffers/pages allowed to use in memory. We used 32k because average response size was around 24k as shown from calculation in article above. We limited max to 1mb because top most response was over 600k. Idea is to set default single buffer size for average response size so that multiple buffer allocation won’t be needed for average size. It is controlled using fastcgi_buffer_size. Then use fastcgi_buffers to provision additional buffers, in chunks, to hold max response in memory. "