nginx access_log buffer大小设置

access_log 的buffer设置多大,看官网说是不能超过原子写入磁盘的大小。这个值在Linux里边是没有变量或者环境变量来设置的。

The access_log directive sets the path, format and buffer size for the access log file. Using "off" as the only parameter clears allaccess_log directives for the current level. If the format is not indicated, it defaults to"combined". The size of buffer must not exceed the size of the atomic record for writing into the disk file. This size is not limited for FreeBSD 3.0-6.0.

为啥有这个限制呢,看一下其代码

 n = ngx_write_fd(file->fd, buffer->start, len);
#endif

    if (n == -1) {
        ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
                      ngx_write_fd_n " to \"%s\" failed",
                      file->name.data);

    } else if ((size_t) n != len) {
        ngx_log_error(NGX_LOG_ALERT, log, 0,
                      ngx_write_fd_n " to \"%s\" was incomplete: %z of %uz",
                      file->name.data, n, len);
    }


发现他写不完整不会while里边循环写,直接丢弃和报错了。

这个atomtic write size到底多少,压测试试,设置access_log buffer=4096k, 结果一直写到1G还没有报错。


其它相关信息:

huanglq@hadoop99 conf]$  grep PIPE_BUF /usr/include/linux/limits.h
#define PIPE_BUF        4096    /* # bytes in atomic write to a pipe */

PIPE_BUF  是指pipe的buf,而不是文件的,所以不是该值

另外磁盘buf是8M

sudo hdparm -i /dev/sda

/dev/sda:

 Model=ST3250318AS                             , FwRev=CC37    , SerialNo=            6VY3FTLF
 Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% }
 RawCHS=16383/16/63, TrkSize=0, SectSize=0, ECCbytes=4
 BuffType=unknown, BuffSize=8192kB



再将日志改成8.3M,超过磁盘的buffsize,写了1.5G还是没有报错

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值