V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
goodboy95
V2EX  ›  问与答

求问一下 nginx 里面 proxy_buffers 的设置问题

  •  
  •   goodboy95 · 2020-06-22 16:04:12 +08:00 · 970 次点击
    这是一个创建于 1375 天前的主题,其中的信息可能已经有所发展或是发生改变。

    nginx 文档里是这么写的:

    Syntax: proxy_buffers number size;

    Default: proxy_buffers 8 4k|8k;

    Context: http, server, location

    Sets the number and size of the buffers used for reading a response from the proxied server, for a single connection. By default, the buffer size is equal to one memory page. This is either 4K or 8K, depending on a platform.

    这是不是说,如果我的系统 PAGE_SIZE 是 4K,一般情况下最大的响应是 250K,平均 QPS 是 5, 我就可以设置成 proxy_buffers 64 4k 这样的,而跟 QPS 无关?我看网上有不少把 size 写成 32k 之类的,在内存页 4k 的情况下这么搞有没有必要?

    我自己感觉写 32k 应该不会有啥优化,但搜了好几篇文章都说自己遇到 an upstream response is buffered to a temporary file 就调成 64 32k(或者 16k)了……虽然他们都没公布自己的内存页大小……

    2 条回复    2020-06-23 15:43:38 +08:00
    love
        1
    love  
       2020-06-22 18:00:07 +08:00 via Android
    为啥这里面缓存,不是指定一个总的缓存大小 ,而是要指定有几块每块多大呢?这里面有啥讲究
    goodboy95
        2
    goodboy95  
    OP
       2020-06-23 15:43:38 +08:00
    @love 说实话,我现在也有点搞不懂,能想到的就是在少浪费内存和提高性能之间找平衡了。50k 的东西缓存下来可以占 13 个缓存片,剩下的还可以让别的连接去用。然后 nginx 读取的时候根据缓存片的编号找到对应的内存地址,完成读取。
    不过这些全都是我自己的猜测,nginx 也有不少容量不小但不分块的缓存,想搞懂原因的话我可能还得花老长时间……
    (话说你回复我的时候我居然没接到消息,我一直以为没人回了)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3545 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 04:53 · PVG 12:53 · LAX 21:53 · JFK 00:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.