Tweaking FastCGI buffers settings
Igor Sysoev
igor at sysoev.ru
Thu Nov 26 16:51:25 MSK 2009
On Thu, Nov 26, 2009 at 03:14:48AM -0500, rahul286 wrote:
> First let me show my understanding of ngnix working till now...
>
> In my ngnix.conf - inside php-fastcgi handler block I have settings...
> fastcgi_buffers 64 4k;
> i.e. 256K buffer size (I am on 32-bit platform). This means that if php scripts generate more than 256K size responses nginx will read first 256K sends it to a client and empties the buffer's contents. If there's more responce data - it reads & sends again.
>
> At this point when ngnix performs multiple reads does it writes to the error_log a line like an "upstream response is buffered to a temporary file /var/lib/nginx/fastcgi/"
> Is this something to worry about?
This depends on typical repsonse size.
> As ngnix uses a function like below to allocate memory while sending PHP script response to client
> min(buffer_size,response_size)
> If site often provides small script-generated response, large buffer_size will waste a lot of memory.
> But using large fastcgi_buffers removed warning "upstream response is buffered to a temporary file /var/lib/nginx/fastcgi/" from error_logs.
>
> I really lots of free RAM but I wanted to allocated buffers in most optimized way and use rest of my free RAM to start more php-cgi child processes (I think it will help me handle more traffic bursts)
>
> Any inputs on this greatly appreciated.
If a response is 12k then "fastcgi_buffers 64 4k" will allocated 3 buffers
of 4k. This is why fastcgi_buffers has two parameters, while
fastcgi_buffer_size (used for response header and first part) has just
one paramter. BTW, after fastcgi_buffer_size has been emptied, it used
together with fastcgi_buffers.
--
Igor Sysoev
http://sysoev.ru/en/
More information about the nginx
mailing list