您的位置:首页 > 运维架构 > Nginx

nginx学习随笔--sendfile

2017-09-12 11:30 232 查看

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来修改首次加在数据的量。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx