gnet
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
A Go library for building extremely fast network servers that handles thousands of simultaneous connections using event-driven I/O instead of one goroutine per connection.
gnet is a Go library for building high-performance network services. It works at the transport layer, meaning it handles the low-level mechanics of accepting and managing network connections for protocols like TCP and UDP, while leaving it to you to implement the application-level protocol on top, such as HTTP, WebSocket, or Redis.
Most Go programs use the standard library's built-in networking package, which handles each connection with a dedicated goroutine. gnet takes a different approach: it uses event-driven I/O based on operating system primitives (epoll on Linux, kqueue on macOS and BSD) to handle many connections without a goroutine per connection. This design reduces memory use and can improve throughput in scenarios where a server needs to manage very large numbers of simultaneous connections.
The library is not intended to replace Go's standard net package for everyday use. It is aimed at situations where raw performance is a priority, such as building a high-throughput proxy, a custom game server, or a specialized protocol handler. It provides an internal goroutine pool, elastic memory buffers, multiple load-balancing strategies, support for timed events, and edge-triggered I/O, all behind a concise API.
gnet runs on Linux, macOS, Windows, and BSD variants, though the Windows version is noted as suitable for development use only rather than production. The library is used in production by several large Chinese technology companies including Tencent, iQiyi, Xiaomi, Baidu Tieba, and JD.com.
Go 1.20 or higher is required. The library is added to a project as a standard Go module with a single import line.
Where it fits
- Build a high-throughput TCP proxy server that manages tens of thousands of simultaneous connections with low memory use.
- Implement a custom game server backend in Go that needs minimal latency and tight control over connection handling.
- Write a specialized UDP protocol handler where Go's standard networking package is too slow for your traffic volume.