nginx做负载均衡,引起写io大的优化

服务器:DELL R710  Xeon E5620 *2/16G/300G SAS*5 raid5
系统:centos5.7 64bit
服务架构:  nginx –> squid —>存储
现在的问题:晚高峰单机流量跑到150Mbit/s 服务器的负载就上到40-50 .
1.负载高的是io引起的,用io软件分析一下,主要是io写操作. 查了一下squid命中率到80% 应该读操作大于写操作才对,百思不解.
用dstat命令分析大部份写操作原来是nginx引起的,nginx只是做转发呀并没有做cache呀,为什么会产生这么大的写io.
网上查了nginx相关资料.如下:
nginx 每次request都要先在proxy本地找一下缓存,没有的时候才去请求真实服务器,其实配置中我并没有设置proxy_stroe之类的参数,因为本身就是要负载I/O ,如果都Cache到proxy上 那就达不到真正的目的了,更何况Cache不太适合大量的不算小的文件。

proxy_buffering

syntax: proxy_buffering on|off
default: proxy_buffering on
context: http, server, location
This directive activate response buffering of the proxied server.
If buffering is activated, then nginx assumes the answer of the proxied server as fast as possible, preserving it in the buffer, assigned by directiveproxy_buffer_size and proxy_buffers.
If the response can not all be placed in memory, then parts of it will be written to disk.
If buffering is switched off, then the response is synchronously transferred to client immediately as it is received.
nginx do not attempt to count entire answer of the proxied server, maximum size of data, which nginx can accept from the server it is assigned by directiveproxy_buffer_size.
For Comet applications based on long-polling it is important to set proxy_buffering to off, otherwise the asynchronous response is buffered and the Comet does not work.
总算发现问题所在了,设置off 后reload一下, 负载从50降到5,这也太夸张了吧,不敢想像。
如果是单纯拿来做负载均衡而不做代理,此项应该是必关的,否则只有无谓的消耗。

发表评论

电子邮件地址不会被公开。 必填项已用*标注