Repository navigation
Description
EDIT: I have made available detailed benchmark with epoll that shows this in a reliable way: https://github.com/alexhultman/io_uring_epoll_benchmark
Don't get me wrong, since I heard about io_uring I've been all about trying to scientifically reproduce any claim that it improves performance (theoretically it should, since you can have fewer syscalls and I like that idea). I would love to add support for io_uring in my projects, but I won't touch it until someone can scientifically show me proofs of it outperforming epoll (significantly).
I've tested three different examples claiming to be faster than epoll, tested on Linux 5.7 without spectre mitigations, tested on Linux 5.8 with spectre mitigations. Tested Clear Linux, tested Fedora. All tests points towards epoll being faster for my kind of test.
What I have is a simple TCP echo server echoing small chunks of data for 40-400 clients. In all tests epoll is performing better by a measurable amount. In no single test have I seen io_uring beat epoll in this kind of test.
Some io_uring examples are horribly slow, while others are quite close to epoll perforamance. The closest I have seen it go is this one: https://github.com/frevib/io_uring-echo-server comparing to this one: https://github.com/frevib/epoll-echo-server
I have tested on two separate and different machines, both with the same outcome: epoll wins.
Can someone enlighten me on how I can get io_uring to outperform epoll in this case?
Activity
isilence commentedon Sep 2, 2020
That's definitely a great thing to do. I don't know whether anybody have time for that at the moment, though.
io_uring-echo-server looks much bulkier from the last time I've seen it.
InternalHigh commentedon Sep 13, 2020
Maybe your benchmark is full of errors
markpapadakis commentedon Sep 13, 2020
Qix- commentedon Sep 30, 2020
@markpapadakis Have you taken a look at the benchmarks that are quoted above? They use many connections at once, thus many FDs at once. uring still consistently performs worse, in conditions that mimic production usage well enough without actually being production.
Part of the scentific process is to be able to reproduce claims like those being made (60%+ increase in performance over epoll, apparently that was 99% at one point but bugs were found). These are metrics that @axboe has not refuted and has seemingly even confirmed, especially through promoting it on twitter and urging others to buy in (e.g. Netty).
Even if this were a 5% increase, I'd be for it. However, I simply do not understand where these results are coming from, and everyone on twitter seems to be more interested in patting themselves on the back rather than addressing criticisms of things (sorry if that sounds harsh).
Outrageous claims require outrageous evidence, especially when it comes to claims that could completely renovate the space.
Qix- commentedon Sep 30, 2020
@alexhultman Check netty/netty#10622 - I won't have any bandwidth for the next day or two, but maybe that will pique your interest.
InternalHigh commentedon Sep 30, 2020
I think that @axboe knows that uring is slower. Otherwise he would answer.
axboe commentedon Sep 30, 2020
I have not ignored any of this, but I've been way too busy on other items. And frankly, the way the tone has shifted in here, it's not really providing much impetus to engage. I did run the echo server benchmarks back then, and it did reproduce for me. Haven't looked at it since, it's not like I daily run echo server benchmarks.
So in short, I'm of course interested in cases where io_uring isn't performing to its full potential, it most certainly should. I have a feeling that #215 might explain some of these. Once I get myself out from under the pressure I'm at now, I'll re-run the benchmarks myself.
romange commentedon Sep 30, 2020
I can testify that io_uring is much faster than epoll. Please use kernel 5.7.15 for your benchmarks.
This server https://github.com/romange/gaia/tree/master/examples/pingserver reaches 3M qps on a single instance for redis-benchmark (ping_inline API) on c5n ec2 instances.
126 remaining items
rbernon commentedon Dec 5, 2021
https://github.com/mikesart/gpuvis
axboe commentedon Dec 6, 2021
If you see any iou-wrk workers, then something isn't working right. That's the slower async path, and should not get hit unless IOSQE_ASYNC is being explicitly set. What code is being run?
axboe commentedon Dec 6, 2021
Took a quick look at that server, and it looks like it has two modes:
Neither are great solutions, the most performant will generally be to just issue the request and have the internal poll handle it. Otherwise you're just trading an epoll readiness based model for the ditto on io_uring, which doesn't make a lot of sense. It can be useful for converting existing code, but for new code it isn't really advisable.
rbernon commentedon Dec 6, 2021
Interesting, I added the flag on the read sqe because it's not expected to succeed immediately after a write from the server (the clients are not generally spamming requests). It didn't seem to make a difference at first, but I'll try without it.
rbernon commentedon Dec 6, 2021
FWIW the server code is https://github.com/rbernon/io_uring-echo-server/blob/master/io_uring_ipc_server.c, and it only used the IOSQE_ASYNC flag on the read sqe.
I tried again without this flag, and with IOSQE_CQE_SKIP_SUCCESS, and now the spurious wakeup is gone but there's still iou workers involved, as well as the worker frenzy when exiting the test.
Here with 1 client:

And with 2:

With 4 clients, something weird started to happen, with periods of "normal" latency and periods of very high latency. Looking at gpuvis I can see that the "normal" latency periods involve server, clients, and workers talking to each other:
But after a while there's only the server left, seemingly doing nothing?

Plus a huge frenzy at the end, but kind of expected.
Unrelated note: by default gpuvis uses a millisecond resolution, I modified it to round the timestamps to us because I wanted to be able to see the latency more accurately.
isilence commentedon Dec 15, 2021
@rbernon, pipes, right? The pipes internals don't support any sane nowait behaviour so we have to force any I/O against them to io-wq (slow path). It's just a one line on io_uring side to change that, but then submission may end up waiting for I/O potentially unboundedly. Hopefully, one day we'll push good enough for a change in the pipe code.
fwiw, the benchmark up in the thread doesn't go through io-wq only because O_NONBLOCK and there is special case in io_uring for that.
Don't know what that "frenzy" with lots of rescheduling exactly is, though that's interesting.
avikivity commentedon Apr 14, 2022
Can't we register a poll on the pipe, and issue the write from the poll callback?
The same holds for other socket-like files that support poll() but aren't sockets. They can be handled in the same way as recv.
avikivity commentedon Apr 14, 2022
Now I'm not sure that recv completes without a workqueue.
Looking at the code, it ends up in io_apoll_task_func, which punts via io_req_task_submit. Is recv indeed using workqueue?
avikivity commentedon Apr 14, 2022
I'm probably lost in the maze.
axboe commentedon Apr 14, 2022
We do use poll for any file type that supports it, but since we can't issue a nonblocking read attempt on a pipe, it still has to be done from a worker. What needs to happen here is just converting pipe from using struct file_operations->read to ->read_iter. The solution is known, and patches do exist.
This isn't specific to pipes, but obviously they are one of the more important file types. Thankfully most files use ->read_iter and ->write_iter these days.
axboe commentedon Apr 14, 2022
It is not, this is task_work. That's different from thread offload. For the latter, look for io_queue_async_work().
avikivity commentedon Apr 14, 2022
Yes, sorry.
Cagoh commentedon Jul 2, 2022
I'm trying to fork() the io_uring simulation by creating parent and child process, each process have its own rings, parent for writing to the pipe, child for reading from the pipe, however I stumbled upon some error when the reader side read an empty pipe and instead of waiting for content in the pipe (if therers no error the simulation indeed run faaster), it update the CQE Async task failed. To overcome the problem, I didn't set the O_NONBLOCK in the pipe2(), this makes the reader to wait until theres content in the pipes before unblocking. But on the downside, it will call fcntl() with call syscall and the performance of the simulation is slower than the original simulation file. I wanted to know how to set reader side of pipe to be ready without syscalls
ywave620 commentedon Sep 22, 2023
This is a general question. Does replacing epoll with io_uring reduce the CPU usage for a given workload, said an nginx like http gateway? Reducing CPU usage in our production environment is the primary task rather than achieving a higher throughput or RPS in the benchmark environment.
This question comes to me because, IMO, io_uring makes socket IO purely asynchronous, but the data copying between user and kernel is preserved, assuming zero copy(IORING_OP_SEND_ZC, IORING_OP_SENDMSG_ZC) is not used.