Any guide to set values for fastcgi_buffers in Nginx config?

9,909

No, it means that if your scripts often generate less than 256K responses - the buffer will often be half-empty, and you just waste the memory :)

Beffer works like this: nginx reads min(buffer_size,response_size) bytes from FCGI script, sends it to a client and empties the buffer's contents. If there's more responce data - it reads & sends again.

If your site often provides small script-generated pages, the optimal value is a bit more than the size of a typical script responce size: headers + contents.

Share:
9,909

Related videos on Youtube

rahul286
Author by

rahul286

A geek (wordpress & nginx), blogger (tech) & entrepreneur (rtCamp) Currently leading EasyEngine Project - a CLI tool to manage WordPress-Nginx sites & more!

Updated on September 17, 2022

Comments

  • rahul286
    rahul286 over 1 year

    I just moved our blog-network to ngnix (from apache) which is powered by WPMU. Everything is running smoothly and fine.

    During my quest to optimize server to the max level - I came across this thread on nginx forum http://forum.nginx.org/read.php?2,2649

    I would really like to know: Answer to the original question...

    For example, to prevent the warning when serving a 6144 kilobyte file, which of the three methods would yield the best performance?

    1. A large number of small buffers: fastcgi_buffers 768 8k
    2. A small number of large buffers: fastcgi_buffers 8 768k
    3. A near balance between the buffers and size: fastcgi_buffers 64 96k

    And also one more thing: In my ngnix.config - my setting is:

    fastcgi_buffers 64 4k;

    i.e. 256K buffer size (I am on 32-bit platform). Does this mean if my PHP scripts generates response larger than 256K, nginx will throw some error?

    I know ngnix forum seems better place to ask this but as no ngnix forum is more active than serverfault, I'm posting this question here.

    I hope I will get some inputs/guidance from experts here.

    Thanks,

    -Rahul

  • rahul286
    rahul286 over 14 years
    Thanks. It really gives me useful hints. Now I guess warnings i.e. [warn] lines, we see in ngnix error_log regarding FCGI buffer are generated when ngnix does read & send again multiple times. Can it be safely ignored? Also if possible please answer my first question too. Thanks. :-)
  • streetlight
    streetlight over 14 years
    The warning means nginx tried to fetch the whole response and it did not fit into the buffer. This is not good unless happens not so frequent: disk is slow, you should avoid using it instead of buffering.
  • rahul286
    rahul286 over 14 years
    Thanks. I got answer to this from Igor (creator of nginx) himself as well. You further made it clear to me. :-)