aio
要启用aio,编译时,需要带上--with-file-aio
参数
location / {
aio on;
directio 1;
output_buffers 1 128k;
}
Linux-native aio 比传统的 POSIX aio 功能更丰富一些,重要的一点是能通过内核加速提供高性能。直接用 Linux-native aio API 比较晦涩,为了方便使用和开发 Linux-native aio 应用程序我们可以用 libaio/libaio-devel 库。不过 nginx 的作者没有用这些库,因为 nginx 需要 eventfd(),而 libaio 库里只有 0.3.107 版本起才支持 eventfd;nginx 也没有用 glibc,因为 glibc 要到 2.8 版本才支持 eventfd(),为了减少对库的依赖性,nginx 干脆直接用 Linux-native aio API (system calls).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$ vi nginx-0.9.1/src/event/modules/ngx_epoll_module.c
...
#if (NGX_HAVE_FILE_AIO)
/*
* We call io_setup(), io_destroy() io_submit(), and io_getevents() directly
* as syscalls instead of libaio usage, because the library header file
* supports eventfd() since 0.3.107 version only.
*
* Also we do not use eventfd() in glibc, because glibc supports it
* since 2.8 version and glibc maps two syscalls eventfd() and eventfd2()
* into single eventfd() function with different number of parameters.
*/
...
|
这里说到了 eventfd(),eventfd 是 Linux-native aio 其中的一个 API,用来生成 file descriptors,这些 file descriptors 可为应用程序提供更高效 “等待/通知” 的事件机制。和 pipe 作用相似,但比 pipe 更好,一方面它只用到一个 file descriptor(pipe 要用两个),节省了内核资源;另一方面,eventfd 的缓冲区管理要简单得多,pipe 需要不定长的缓冲区,而 eventfd 全部缓冲只有定长 8 bytes.
只有 2.6.22 以后版本的kernel才支持 eventfd
专题:
nginx
本文发表于 2022-07-01,最后修改于 2022-07-01。
本站永久域名「 jiavvc.top
」,也可搜索「 后浪笔记一零二四 」找到我。
上一篇 « 自己动手写session
下一篇 » pg的编译安装
推荐阅读
栈
发表于2021-07-15,
全文1057字,
阅读约4分钟
Untitled
发表于0001-01-01,
全文252字,
阅读约1分钟
Untitled
发表于0001-01-01,
全文3067字,
阅读约11分钟