Syntax: | aio
|
---|---|
Default: | aio off; |
Context: | http , server , location |
This directive appeared in version 0.8.11.
Enables or disables the use of asynchronous file I/O (AIO) on FreeBSD and Linux:
location /video/ { aio on; output_buffers 1 64k; }
On FreeBSD, AIO can be used starting from FreeBSD 4.3. Prior to FreeBSD 11.0, AIO can either be linked statically into a kernel:
options VFS_AIO
or loaded dynamically as a kernel loadable module:
kldload aio
On Linux, AIO can be used starting from kernel version 2.6.22. Also, it is necessary to enable directio, or otherwise reading will be blocking:
location /video/ { aio on; directio 512; output_buffers 1 128k; }
On Linux, directio can only be used for reading blocks that are aligned on 512-byte boundaries (or 4K for XFS). File’s unaligned end is read in blocking mode. The same holds true for byte range requests and for FLV requests not from the beginning of a file: reading of unaligned data at the beginning and end of a file will be blocking.
When both AIO and sendfile are enabled on Linux, AIO is used for files that are larger than or equal to the size specified in the directio directive, while sendfile is used for files of smaller sizes or when directio is disabled.
location /video/ { sendfile on; aio on; directio 8m; }
Finally, files can be read and sent using multi-threading (1.7.11), without blocking a worker process:
location /video/ { sendfile on; aio threads; }
Read and send file operations are offloaded to threads of the specified pool. If the pool name is omitted, the pool with the name “default
” is used. The pool name can also be set with variables:
aio threads=pool$disk;
By default, multi-threading is disabled, it should be enabled with the --with-threads
configuration parameter. Currently, multi-threading is compatible only with the epoll, kqueue, and eventport methods. Multi-threaded sending of files is only supported on Linux.
See also the sendfile directive.
Please login to continue.