Re: [shlug] 如何设置 Nginx access_log buffer 的大小

131 views
Skip to first unread message
Message has been deleted
Message has been deleted

Ray Song

unread,
Dec 7, 2016, 11:39:05 PM12/7/16
to Chaos Eternal, Shanghai Linux User Group
文件系统有不同处理方式,但我倾向于认为多数情况下
O_APPEND 只保障 seek 和 write的发起 是原子的,可能与其他进程的 write interleave

On 2016-12-08, Chaos Eternal wrote:
>http://stackoverflow.com/questions/10650861/
>atomicity-of-write2-to-a-local-filesystem
>这里讲如果O_APPEND的话,就可以避免进程之间混合写入。
>
>On Wed, Dec 7, 2016 at 11:19 AM Terry Zheng <jfh...@gmail.com> wrote:
>
> 请教一下各位,Nginx ngx_http_log_module 模块的 access_log 文档中说:
>
> The buffer size must not exceed the size of an atomic write to a disk
> file. For FreeBSD this size is unlimited.
>
> Google 了一下,说  size of an atomic write to a disk file 的大小是文件系统
> 的 block 大小,可以用 `stat -f' 看
> http://stackoverflow.com/a/29866383/1699746
> http://unix.stackexchange.com/a/279718/13514
>
> 如果 Nginx 真是使用 4KB 的 buffer 就没有疑问了,但是 access_log 的 gzip 选
> 项会默认打开 buffer,默认大小为 64K bytes。后来在 OpenResty 的邮件列表里看
> 到有人类似的问题,但是没有明确答案,
> https://groups.google.com/d/msg/openresty/NcRSb5gTmVU/uWPn_voYJ3EJ
>
> nginx是多进程写日志,write原子性很重要。在Linux下很多人说atomic size是
> PIPE_BUF,即4k。但在网上查到的资料中,我经常看到将buffer大小配置为类似
> 32k这样的大小,感到有点疑惑。写管道的时候,如果并发写大于4k,可能出现问
> 题。但如果写普通文件,经过调研,发现nginx中在文件打开flag中加入了append
> 标识,这样write其实是可以保证原子的。不知道大家觉得是否正确?
>
> 关于文件的原子性操作,看了这 2 篇笔记,了解了一下概念,
> http://note.huangz.me/os/apue/chp3.html#
> http://www.cnblogs.com/suzhou/p/4293565.html
>
> 如果 OpenResty 列表里的描述是对的,是不是 buffer 的值就不用管文件系统的
> block 大小是多少,那要根据什么因素来调整 buffer 的大小?
>
> --
> -- You received this message because you are subscribed to the Google
> Groups Shanghai Linux User Group group. To post to this group, send email
> to sh...@googlegroups.com. To unsubscribe from this group, send email to
> shlug+un...@googlegroups.com. For more options, visit this group at
> https://groups.google.com/d/forum/shlug?hl=zh-CN
> ---
> 您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组
> 。
> 要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到
> shlug+un...@googlegroups.com
> 要查看更多选项,请访问https://groups.google.com/d/optout
>
>--
>-- You received this message because you are subscribed to the Google Groups
>Shanghai Linux User Group group. To post to this group, send email to
>sh...@googlegroups.com. To unsubscribe from this group, send email to
>shlug+un...@googlegroups.com. For more options, visit this group at
>https://groups.google.com/d/forum/shlug?hl=zh-CN
>---
>您收到此邮件是因为您订阅了Google网上论坛上的“Shanghai Linux User Group”群组。
>要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到
>shlug+un...@googlegroups.com
>要查看更多选项,请访问https://groups.google.com/d/optout

--
Ray
http://maskray.me
Reply all
Reply to author
Forward
Message has been deleted
0 new messages