nginx学习随笔--sendfile

本文详细介绍了Nginx中sendfile指令的作用及其如何配合aio使用以优化文件传输过程。从nginx 0.8.12版本开始,aio可以用于预加载数据,提高sendfile效率。通过特定配置,可以实现不阻塞磁盘I/O的数据传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nginx学习随笔–sendfile

  • 英文原文:
Syntax: sendfile on | off;
Default:    
sendfile off;
Context:    http, server, location, if in location

Enables or disables the use of sendfile().

Starting from nginx 0.8.12 and FreeBSD 5.2.1, aio can be used to pre-load data for sendfile():

location /video/ {
    sendfile       on;
    tcp_nopush     on;
    aio            on;
}

In this configuration, sendfile() is called with the SF_NODISKIO flag which causes it not to block on disk I/O, but, instead, report back that the data are not in memory. nginx then initiates an asynchronous data load by reading one byte. On the first read, the FreeBSD kernel loads the first 128K bytes of a file into memory, although next reads will only load data in 16K chunks. This can be changed using the read_ahead directive.

Before version 1.7.11, pre-loading could be enabled with aio sendfile;.

  • 中文翻译:

允许或者禁止使用sendfile();

从nginx0.8.12和FreeBSD5.2.1开始,aio可以用来为sendfile()预加载数据。

location /video/ {
    sendfile       on;
    tcp_nopush     on;
    aio            on;
}
在上面的配置中,sendfile()和SF_NODISKIO标记一起调用,可以在不阻塞I/O的情况下,报告数据还没有到内存。nginx通过读取一个字节来启动异步数据加载。第一次读的时候,FreeBSD内核加载一个文件的第一个128K字节数据到内存中,下次再读数据时就只加载16K数据块数据。可以通过指令read_ahead来修改首次加在数据的量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值