From: Pavel Begunkov <[email protected]>
To: "Richard W.M. Jones" <[email protected]>, [email protected]
Subject: Re: Questions about usage of io-uring in a network application
Date: Sun, 17 May 2020 14:59:16 +0300 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
On 10/05/2020 11:00, Richard W.M. Jones wrote:
> Hopefully these questions are not too stupid, but I didn't find any
> answers looking over the archives of this list or in the io_uring.pdf
> document.
>
> I have an existing C library which is the client part of a
> client/server network service. It's not exactly the same as HTTP, but
> it could be thought of as like an HTTP network client where we may
> hold a few separate TCP/IP connections open to the same server, and we
> issue multiple requests in flight per TCP connection. There is one
> pthread per TCP connection usually.
>
> I want to try to see if io_uring gives us any performance benefit by
> seeing if we can use IORING_OP_SENDMSG/IORING_OP_RECVMSG +
> IOSQE_IO_LINK, as an experiment.
>
>
> (1) How many io_urings should we create?
>
> One ring per process? All of the connections share the same ring.
> Presumably there would be a lot of contention because I suppose we'd
> need to lock the ring while submitting requests from multiple threads.
> If there are multiple independent libraries or separate of the program
> all trying to use io_uring, should they try to share a single ring?
>
> One ring per pthread? It seems we could implement this without locks
> using thread-local storage to hold the the io_uring fd.
>
> One ring per physical CPU? (Not sure how to implement this race-free
> in userspace).
>
> One ring per TCP connection?
It's totally up to a user. Threads can try to share io_uring, but after some
number of IOPS you indeed may find it to be a bottleneck. It rather depends on
your system/workload/etc.
There are 2 more things you may want to consider:
1. only 1 thread can do in-kernel submission (i.e. inside io_uring_enter()) at a
time. And it can take some time, because it can to execute and complete some
requests inline (e.g. doing copying buffers, etc.).
2. there is an option to share internal thread pools between io_uring instances.
If you have multiple io_uring instances, it's a good start point to share a
single thread pool between them. see IORING_SETUP_ATTACH_WQ.
To summarise, for a really high-throughput system, I'd incline using the
per-process scheme with a single shared thread pool, and adjust then. As for
clients, and it's depends on a kind of a client you have, but an average one
would probably not bottleneck there.
I would love to see more comments from guys really using it. E.g. see
https://lore.kernel.org/io-uring/[email protected]/
>
> (2) The existing API (which we cannot change) takes user-allocated
> buffers for the data to read/write. We don't know if these were
> allocated using malloc, they might be statically allocated or even
> come from something exotic like mmap of a file. I understand that we
> cannot register these buffers using IORING_REGISTER_BUFFERS. But can
> these be passed in the io_uring_sqe->addr field? ie. Do the same
> restrictions in IORING_REGISTER_BUFFERS also apply to the addr field?
It should work as any other read(2)/write(2)/etc. A simple test with
file-backed buffers works for me.
--
Pavel Begunkov
prev parent reply other threads:[~2020-05-17 12:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-10 8:00 Questions about usage of io-uring in a network application Richard W.M. Jones
2020-05-17 11:59 ` Pavel Begunkov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox