nginx fastcgi_buffers设置
2016-09-09 17:15
148 查看
打开nginx的warn级别error_log,看到如下信息:
2011/04/23 17:24:08 [warn] 9639#0: *44 an upstream response is buffered to a temporary file /tmp/fastcgi_temp/8/0/0000000008 while reading upstream, client: 118.118.118.118, server: sealinger.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000",
host: "www.sealinger.com"
参考《分析 fastcgi_temp 错误以及 Nginx 的 Buffer 机制》一文:
先简单的说一下 Nginx 的 buffer 机制,对于来自 FastCGI Server 的 Response,Nginx 将其缓冲到内存中,然后依次发送到客户端浏览器。缓冲区的大小由 fastcgi_buffers 和 fastcgi_buffer_size 两个值控制。
比如如下配置:
fastcgi_buffers 8 4K;
fastcgi_buffer_size 4K;
fastcgi_buffers 控制 nginx 最多创建 8 个大小为 4K 的缓冲区,而 fastcgi_buffer_size 则是处理 Response 时第一个缓冲区的大小,不包含在前者中。所以总计能创建的最大内存缓冲区大小是 8*4K+4K = 36k。而这些缓冲区是根据实际的 Response 大小动态生成的,并不是一次性创建的。比如一个 8K 的页面,Nginx 会创建 2*4K 共 2 个 buffers。
当 Response 小于等于 36k 时,所有数据当然全部在内存中处理。如果 Response 大于 36k 呢?fastcgi_temp 的作用就在于此。多出来的数据会被临时写入到文件中,放在这个目录下面。同时你会在 error.log 中看到一条类似 warning。
显然,缓冲区设置的太小的话,Nginx 会频繁读写硬盘,对性能有很大的影响,但也不是越大越好,没意义,呵呵!
一步步调整参数,直到没有这个warn信息:
#syntax: fastcgi_buffers the_number is_size
#default: fastcgi_buffers 8 4k/8k
#context: http, server, location
#fastcgi_buffers 256 4k; # Sets the buffer size to 4k + 256 * 4k = 1028k
fastcgi_buffers 32 4k;
-----------------------------------------------------------
参考:http://wiki.nginx.org/HttpFcgiModule
fastcgi_buffer_size
syntax: fastcgi_buffer_size the_size
default: fastcgi_buffer_size 4k/8k
context: http, server, location
This directive sets the buffer size for reading the header of the backend FastCGI process.
By default, the buffer size is equal to the size of one buffer in
fastcgi_buffers
. This directive allows you to set it to an arbitrary value.
fastcgi_buffers
syntax: fastcgi_buffers the_number is_size
default: fastcgi_buffers 8 4k/8k
context: http, server, location
This directive sets the number and the size of the buffers into which the reply from the FastCGI process in the backend is read.
By default, the size of each buffer is equal to the OS page size. Depending on the platform and architecture this value is one of 4k, 8k or 16k.
On Linux you can get the page size issuing:
getconf PAGESIZE
it returns the page size in bytes.
Example:
fastcgi_buffers 256 4k; # Sets the buffer size to 4k + 256 * 4k = 1028k
This means that any reply by the FastCGI process in the backend greater than 1M goes to disk. Only replies below 1M are handled directly in memory.
转自:https://blog.gesha.net/archives/350/
2011/04/23 17:24:08 [warn] 9639#0: *44 an upstream response is buffered to a temporary file /tmp/fastcgi_temp/8/0/0000000008 while reading upstream, client: 118.118.118.118, server: sealinger.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000",
host: "www.sealinger.com"
参考《分析 fastcgi_temp 错误以及 Nginx 的 Buffer 机制》一文:
先简单的说一下 Nginx 的 buffer 机制,对于来自 FastCGI Server 的 Response,Nginx 将其缓冲到内存中,然后依次发送到客户端浏览器。缓冲区的大小由 fastcgi_buffers 和 fastcgi_buffer_size 两个值控制。
比如如下配置:
fastcgi_buffers 8 4K;
fastcgi_buffer_size 4K;
fastcgi_buffers 控制 nginx 最多创建 8 个大小为 4K 的缓冲区,而 fastcgi_buffer_size 则是处理 Response 时第一个缓冲区的大小,不包含在前者中。所以总计能创建的最大内存缓冲区大小是 8*4K+4K = 36k。而这些缓冲区是根据实际的 Response 大小动态生成的,并不是一次性创建的。比如一个 8K 的页面,Nginx 会创建 2*4K 共 2 个 buffers。
当 Response 小于等于 36k 时,所有数据当然全部在内存中处理。如果 Response 大于 36k 呢?fastcgi_temp 的作用就在于此。多出来的数据会被临时写入到文件中,放在这个目录下面。同时你会在 error.log 中看到一条类似 warning。
显然,缓冲区设置的太小的话,Nginx 会频繁读写硬盘,对性能有很大的影响,但也不是越大越好,没意义,呵呵!
一步步调整参数,直到没有这个warn信息:
#syntax: fastcgi_buffers the_number is_size
#default: fastcgi_buffers 8 4k/8k
#context: http, server, location
#fastcgi_buffers 256 4k; # Sets the buffer size to 4k + 256 * 4k = 1028k
fastcgi_buffers 32 4k;
-----------------------------------------------------------
参考:http://wiki.nginx.org/HttpFcgiModule
fastcgi_buffer_size
syntax: fastcgi_buffer_size the_size
default: fastcgi_buffer_size 4k/8k
context: http, server, location
This directive sets the buffer size for reading the header of the backend FastCGI process.
By default, the buffer size is equal to the size of one buffer in
fastcgi_buffers
. This directive allows you to set it to an arbitrary value.
fastcgi_buffers
syntax: fastcgi_buffers the_number is_size
default: fastcgi_buffers 8 4k/8k
context: http, server, location
This directive sets the number and the size of the buffers into which the reply from the FastCGI process in the backend is read.
By default, the size of each buffer is equal to the OS page size. Depending on the platform and architecture this value is one of 4k, 8k or 16k.
On Linux you can get the page size issuing:
getconf PAGESIZE
it returns the page size in bytes.
Example:
fastcgi_buffers 256 4k; # Sets the buffer size to 4k + 256 * 4k = 1028k
This means that any reply by the FastCGI process in the backend greater than 1M goes to disk. Only replies below 1M are handled directly in memory.
转自:https://blog.gesha.net/archives/350/
相关文章推荐
- Keepalived + nginx实现高可用性和负载均衡
- tenginx+ImageMagick+Lua+FastDfs分布式自动缩略图
- tenginx+ImageMagick+Lua+FastDfs分布式自动缩略图
- nginx File not found
- nginx安装php和php-fpm
- 整理nginx.conf配置详细
- ubuntu 编译nginx时出错解决办法
- Nginx 服务器安装及配置文件详解
- nginx配置完全解读
- nginx配置完全解读
- Nginx编译安装
- nginx中配置跨域支持功能
- nginx、php-fpm、mysql用户权限解析
- CentOS 7 用户怎样安装 LNMP(Nginx+PHP+MySQL)
- [CentOS 7] 安装nginx
- 在Centos7下源代码安装配置Nginx
- Nginx官方文档学习
- nginx跳转+ssl加密 域名也跳转
- PHP实现简单的监控nginx日志文件功能
- 自动安装nginx