This article introduces a high-performance web framework, Gain, that can be faster than the fastest epoll-based frameworks written in Go since it is built on top of the io_uring API and was designed from the very beginning to be as fast as possible. The article covers a little bit of the basics necessary to use the framework correctly and demonstrates how to write a simple TCP application built on top of it.
io_uring is a relatively new Linux API developed to handle I/O operations. For performance reasons, it uses an asynchronous programming model.
io_uring is a pair of ring buffers shared by user space and the kernel. The first is used to make requests (submission queue or SQ) and the second is to report the result of their execution (completion queue or CQ). When a user wants to perform an operation, such as reading or writing to a file, it creates a submission queue entry that describes the requested operation and adds it to the tail of the submission queue.
The kernel is then notified using a system call that there are requests in the queue to be processed. The kernel tries to do all the work it has to do and puts the result on the tail of the completion queue under the form of completion queue events.