有多少nginx缓冲区太多? [英] How many nginx buffers is too many?

查看:165
本文介绍了有多少nginx缓冲区太多?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读nginx文档时, proxy_buffer 命令具有以下解释性消息:

Reading the nginx documentation, the proxy_buffer command has this explanatory message:

此伪指令设置缓冲区的数量和大小, 将读取从代理服务器获得的答案.默认情况下, 一个缓冲区的大小等于页面的大小.根据 平台是4K还是8K.

This directive sets the number and the size of buffers, into which will be read the answer, obtained from the proxied server. By default, the size of one buffer is equal to the size of page. Depending on platform this is either 4K or 8K.

默认值为八个4k或8k缓冲区.为什么nginx的作者选择八个而不是一个更大的数字?如果我添加更多的缓冲区或更大的缓冲区大小,怎么办?

The default is eight 4k or 8k buffers. Why did the authors of nginx choose eight, and not a higher number? What could go wrong if I add more buffers, or a bigger buffer size?

推荐答案

nginx旨在提高内存使用效率,其默认配置也可以减少内存使用量.如果添加更多的缓冲区,一切都不会出错,但是nginx会消耗更多的RAM.

nginx is built to be efficient with memory and its default configurations are also light on memory usage. Nothing will go wrong if you add more buffers, but nginx will consume more RAM.

可能选择了8个缓冲区作为最小有效计数,该计数为2的平方.四个将太少,而16个将大于nginx的默认需求.

Eight buffers was probably chosen as the smallest effective count that was a square of two. Four would be too few, and 16 would be greater than the default needs of nginx.

缓冲区过多"的答案取决于您的性能需求,内存可用性和请求并发性.要保持的良好"阈值是服务器必须将内存交换到磁盘的时间点.最好的答案是:确保nginx永远不会写入磁盘所需的缓冲区数量尽可能少(请检查您的错误日志以了解是否存在).

The "too many buffers" answer depends on your performance needs, memory availability, and request concurrency. The "good" threshold to stay under is the point at which your server has to swap memory to disk. The "best" answer is: as few buffers as are necessary to ensure nginx never writes to disk (check your error logs to find out if it is).

以下是我用于具有32 GB RAM的Web主机上的大型PHP-FPM应用程序的nginx配置:

Here are nginx configurations I use for a large PHP-FPM application on web hosts with 32 GB of RAM:

 client_body_buffer_size      2m;
 client_header_buffer_size    16k;
 large_client_header_buffers  8 8k;
 fastcgi_buffers              512 16k;
 fastcgi_buffer_size          512k;
 fastcgi_busy_buffers_size    512k;

这些配置是通过反复试验并通过增加网络上nginx配置指南的值来确定的.标头缓冲区保持较小,因为HTTP标头趋于轻量级.客户端和fastcgi缓冲区已增加,以处理复杂的HTML页面和XML API.

These configurations were determined through some trial and error and by increasing values from nginx configuration guides around the web. The header buffers remain small because HTTP headers tend to be lightweight. The client and fastcgi buffers have been increased to deal with complex HTML pages and an XML API.

这篇关于有多少nginx缓冲区太多?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆