io_getevents
通知机制乍看之下功能强大,所以我想要一些可以与它一起使用的东西。我只是找不到任何东西。在 Windows 上,这很简单:只有 TransmitFile
,它可以异步(重叠)工作,并且如果需要,还可以使用一些通知机制(IOCP、事件)。 Linux 上一定有一些等价物,对吧?或者,在某些情况下提出我的问题,我将如何在 Linux 上创建一个高效的文件服务器?
最佳答案
唉,在 Linux 上没有什么容易的事情,几乎任何事情都可能在错误的情况下阻塞(even io_submit
)。在回答您的问题时(在标题和正文中):
- (2019) Linux 中没有系统提供
sendfile
的异步版本(Linux 不是 Windows 或 FreeBSD)。有一篇精彩的文章涵盖了sendfile
blocking, caveats and ideas in a TANK distributed log issue .那笔记lighttpd came up with an "asynchronous"sendfile
hack但它很复杂并且使用线程。 - 与 Windows 相比,在 Linux 上创建高效的文件服务器需要不同的思维方式。看看this NGINX blog post about what they do to make things fast on Linux或者这个 Scylla blog post about different I/O access methods for Linux对于所涉及的权衡。
他们是休息...
future (2020+)解决方案
有人建议 future 的某些 Linux 内核(晚于 5.5,在撰写本文时已经达到 5.5-rc7)基本上可以执行 asynchronous sendfile via io_uring if io_uring gains support for splice()
。 ...
关于linux - Linux 中有异步版本的 sendfile 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48033320/