explaingit

panjf2000/gnet

11,144GoAudience · developerComplexity · 4/5Setup · moderate

TLDR

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.

Mindmap

mindmap
  root((gnet))
    What it does
      Event-driven networking
      High-throughput servers
      Connection management
    Tech stack
      Go
      epoll
      kqueue
    Use cases
      TCP proxy servers
      Custom protocols
      Game backends
    Audience
      Go developers
      Systems programmers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a high-throughput TCP proxy server that manages tens of thousands of simultaneous connections with low memory use.

USE CASE 2

Implement a custom game server backend in Go that needs minimal latency and tight control over connection handling.

USE CASE 3

Write a specialized UDP protocol handler where Go's standard networking package is too slow for your traffic volume.

Tech stack

Go

Getting it running

Difficulty · moderate Time to first run · 30min

Requires Go 1.20+, Windows support is development-only and not suitable for production deployments.

In plain English

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.

Copy-paste prompts

Prompt 1
Using gnet, write a simple TCP echo server in Go that handles connections efficiently without a goroutine per connection.
Prompt 2
Show me how to implement a custom protocol handler in gnet that parses a fixed-length binary frame over TCP.
Prompt 3
Help me benchmark gnet against Go's standard net package for a server handling 50,000 concurrent TCP connections.
Prompt 4
Walk me through building a UDP server with gnet that uses the built-in goroutine pool and round-robin load balancing.
Open on GitHub → Explain another repo

← panjf2000 on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.