Breaking the Thread Barrier: Boosting I/O Performance with io_uring and FS2
- Mentors
- armanbilge, Fred Honório, Christopher Davenport, Daniel Spiewak
- Organization
- Scala Center
- Technologies
- scala, Typelevel, Cats Effect, FS2, io_uring
- Topics
- functional programming, Asynchronous I/O, Thread Model Optimization
The current state of the asynchronous I/O on the JVM involves using separate selector threads to manage I/O events through system functions like epoll or kqueue. Although frameworks like Netty and NIO2 make this approach seem reasonable, the use of separate event loop threads is not without cost. In high-RPS services, these threads can compete for CPU time with worker threads executing application tasks, leading to resource contention and potentially significant performance loss. In contrast, Cats Effect offers a different threading model, integrating I/O and application tasks into a single runtime system, reducing contention an enhancing overall efficiency.
io_uring, the key component of this project, offers two major advantages: (1) it enables all supported syscalls to become asynchronous from the application’s perspective, allowing for multiple syscalls to be initiated in parallel without blocking the calling thread, and (2) it uses a pair of ring buffers for syscall submission and completion events that are shared between the application and the kernel, dramatically reducing the overhead of calling from userspace into kernelspace. When integrated with Cats Effect, io_uring can significantly improve the efficiency of syscalls, requiring fewer calls into kernelspace during the worker loop.
This proposal brings two key innovations together: a new threading model and a new I/O API. By integrating Cats Effects and FS2 with io_uring, we aim to develop an alternative solution to minimize the inefficiencies found in the traditional model, offering a more efficient and performant solution for I/O-intensive applications.