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來修改首次加在資料的量。