简体   繁体   English

同时等待 epoll 和 io_uring

[英]Waiting for epoll and io_uring simotaniously

I'm migrating my project to io_uring for better performance.我正在将我的项目迁移到 io_uring 以获得更好的性能。 However, some part of the system depends on epoll being event system and not movable to io_uring (ex: database drivers, they write to socket internally and I get notification read/write events, never seeing what's written to the raw sockets).但是,系统的某些部分依赖于 epoll 作为事件系统并且不能移动到 io_uring (例如:数据库驱动程序,它们在内部写入套接字,我收到通知读/写事件,从未看到写入原始套接字的内容)。 Forcing me to use epoll and io_uring together.强迫我同时使用 epoll 和 io_uring。 Creating two threads, one for epoll and another for io_uring is not an option for various reasons.出于各种原因,创建两个线程,一个用于 epoll,另一个用于 io_uring 不是一种选择。

My plan was to poll io_uring after epoll in my event loop, Like the following我的计划是在我的事件循环中在 epoll 之后轮询 io_uring,如下所示

while(keep_running) {
    epoll_wait();
    io_uring_peek_batch_cqe();

    ... // handle events
}

This turns out not viable.事实证明这是不可行的。 It's likely that there's no ongoing database activity, causing epoll_wait block until timeout, thus all operations on io_uring waiting for the same timeout.很可能没有正在进行的数据库活动,导致epoll_wait阻塞直到超时,因此 io_uring 上的所有操作都在等待相同的超时。 Nor inverting the order and call io_uring_wait_cqe any better.也不能颠倒顺序并更好地调用io_uring_wait_cqe It's possible that there's DB traffic but nothing submitted to io_uring.可能有数据库流量但没有提交给 io_uring。 Causing epoll to wait for io_uring timeout.导致 epoll 等待 io_uring 超时。

So far I've considered reducing the timeout.到目前为止,我已经考虑减少超时。 But it's not an elegant solution.但这不是一个优雅的解决方案。 It increases CPU usage and adds unnecessary latency.它会增加 CPU 使用率并增加不必要的延迟。 Is there a way to wait for epoll and io_uring at the same time?有没有办法同时等待epoll和io_uring? ie Some function that unblocks as soon as either epoll or io_uring has something to process.即一些 function 一旦 epoll 或 io_uring 有事情要处理就会解除阻塞。

io_uring can monitor file descriptors for readiness using IORING_OP_POLL_ADD. io_uring 可以使用 IORING_OP_POLL_ADD 监视文件描述符的准备情况。 Epoll fd becomes read-ready once there are some events pending.一旦有一些事件未决,epoll fd 就会变为 read-ready。 One solution is to use io_uring as the primary event notification facility.一种解决方案是使用 io_uring 作为主要的事件通知工具。 Epoll fd should be monitored by io_uring. epoll fd 应该被 io_uring 监控。

One could do it the other way around - use epoll as the primary event notification facility.可以反过来做——使用 epoll 作为主要的事件通知工具。 Configure io_uring to post readiness notifications using eventfd and add that to epoll: https://unixism.net/loti/tutorial/register_eventfd.html配置 io_uring 以使用 eventfd 发布就绪通知并将其添加到 epoll: https://unixism.net/loti/tutorial/register_eventfd.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM