nio4r (New I/O for Ruby) is a cross-platform library providing high-performance event-driven I/O using native operating system selectors. It offers a Ruby interface to kqueue, epoll, and IOCP, enabling efficient monitoring of multiple I/O streams simultaneously. The gem provides the building blocks for creating non-blocking, event-driven network applications and servers.
The library centers around a selector that monitors multiple I/O objects (sockets, pipes, files) for readability, writability, and errors without blocking. It implements the reactor pattern, allowing applications to handle thousands of concurrent connections with a single thread. nio4r includes support for timeouts, cross-platform compatibility, and minimal overhead through its C extension wrapping native system calls. The gem serves as the I/O layer for Puma and other Ruby servers requiring concurrent connection handling.
nio4r is primarily used as a foundation for building high-performance network servers, WebSocket implementations, and async I/O libraries. While most applications consume it indirectly through web servers like Puma, developers building custom network protocols, proxy servers, or real-time communication systems benefit from its low-level control over I/O multiplexing. The gem's ability to handle massive concurrent connections makes it essential for applications requiring scalable network I/O.
gem install nio4r Run this gem instantly in your browser without any installation:
Open in RunRuby.dev →All 48 versions available for installation