gnet README

The project's README from github.com/panjf2000/gnet. As one markdown file: README.md.

gnet

panjf2000%2Fgnet | Trendshift

English | 中文

🎉🎉🎉 Feel free to join the channels about gnet on the Discord Server.

📖 Introduction

gnet is an event-driven networking framework that is ultra-fast and lightweight. It is built from scratch by exploiting epoll and kqueue and it can achieve much higher performance with lower memory consumption than Go net in many specific scenarios.

gnet and net don't share the same philosophy in network programming. Thus, building network applications with gnet can be significantly different from building them with net, and the philosophies can't be reconciled. There are other similar products written in other programming languages in the community, such as libuv, netty, twisted, tornado, etc. which work in a similar pattern as gnet under the hood.

gnet is not designed to displace the Go net, but to create an alternative in the Go ecosystem for building performance-critical network services. As a result of which, gnet is not as comprehensive as Go net, it provides only the core functionality (via a concise set of APIs) required by a network application and it doesn't plan on becoming a coverall networking framework, as I think Go net has done a good enough job in that area.

gnet sells itself as a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go which works on the transport layer with TCP/UDP protocols and Unix Domain Socket. It enables developers to implement their own protocols(HTTP, RPC, WebSocket, Redis, etc.) of application layer upon gnet for building diversified network services. For instance, you get an HTTP Server if you implement HTTP protocol upon gnet while you have a Redis Server done with the implementation of Redis protocol upon gnet and so on.

gnet derives from the project: evio with much higher performance and more features.

🚀 Features

🦖 Milestones

🕊 Roadmap

Windows version of gnet should only be used in development for developing and testing, it shouldn't be used in production.

🎬 Getting started

gnet is available as a Go module and we highly recommend that you use gnet via Go Modules, with Go 1.11 Modules enabled (Go 1.11+), you can just simply add import "github.com/panjf2000/gnet/v2" to the codebase and run go mod download/go mod tidy or go [build|run|test] to download the necessary dependencies automatically.

With v2

go get -u github.com/panjf2000/gnet/v2

With v1

go get -u github.com/panjf2000/gnet

🎡 Use cases

The following corporations/organizations use gnet as the underlying network service in production.

If you're also using gnet in production, please help us enrich this list by opening a pull request.

📊 Performance

Benchmarks on TechEmpower

# Hardware Environment
* 28 HT Cores Intel(R) Xeon(R) Gold 5120 CPU @ 3.20GHz
* 32GB RAM
* Dedicated Cisco 10-gigabit Ethernet switch
* Debian 12 "bookworm"
* Go1.19.x linux/amd64

This is a leaderboard of the top 50 out of 486 frameworks that encompass various programming languages worldwide, in which gnet is ranked first.

This is the full framework ranking of Go and gnet tops all the other frameworks, which makes gnet the fastest networking framework in Go.

To see the full ranking list, visit TechEmpower Benchmark Round 22.

Note that the HTTP implementation of gnet on TechEmpower is half-baked and fine-tuned for benchmark purposes only and far from production-ready.

Contrasts to the similar networking libraries

On Linux (epoll)

Environment

# Machine information
        OS : Ubuntu 20.04/x86_64
       CPU : 8 CPU cores, AMD EPYC 7K62 48-Core Processor
    Memory : 16.0 GiB

# Go version and settings
Go Version : go1.17.2 linux/amd64
GOMAXPROCS : 8

# Benchmark parameters
TCP connections : 1000/2000/5000/10000
Packet size     : 512/1024/2048/4096/8192/16384/32768/65536 bytes
Test duration   : 15s

On MacOS (kqueue)

Environment

# Machine information
        OS : MacOS Big Sur/x86_64
       CPU : 6 CPU cores, Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory : 16.0 GiB

# Go version and settings
Go Version : go1.16.5 darwin/amd64
GOMAXPROCS : 12

# Benchmark parameters
TCP connections : 300/400/500/600/700
Packet size     : 512/1024/2048/4096/8192 bytes
Test duration   : 15s

Combat with Rust

⚠️ License

The source code of gnet should be distributed under the Apache-2.0 license.

👏 Contributors

Please read the Contributing Guidelines before opening a PR and thank you to all the developers who already made contributions to gnet!

⚓ Relevant Articles

☕️ Buy me a coffee

Please be sure to leave your name, GitHub account, or other social media accounts when you donate by the following means so that I can add it to the list of donors as a token of my appreciation.

By me coffee Patreon OpenCollective

🔑 JetBrains OS licenses

gnet has been being developed with GoLand IDE under the free JetBrains Open Source license(s) granted by JetBrains s.r.o., hence I would like to express my thanks here.

JetBrains logo.

🔋 Sponsorship

DigitalOcean Referral Badge

gnet (panjf2000/gnet)

Searching Database…

11.2K ·GitHub
这是什么?gnet 是一个用纯 Go 编写的高性能、轻量级、非阻塞、事件驱动的网络框架。它基于 epoll 和 kqueue 构建,工作在传输层,支持 TCP、UDP 和 Unix 域套接字。
这是个框架,还是只是 Go 的 net 包的一层封装?它是一个独立的框架,有自己的设计理念,并不是 Go 的 net 包的直接替代品。你可以在 gnet 提供的 TCP/UDP/Unix 套接字核心之上,构建自己的应用层协议(如 HTTP、RPC、WebSocket、Redis 等)。
怎样把它添加到 Go 项目中?在你的代码中添加 import 'github.com/panjf2000/gnet/v2',然后运行 go mod download / go mod tidy(或直接运行 go build、go run、go test)来获取它,因为 gnet 是以 Go 模块的形式发布的。
我需要特定的 Go 版本吗?需要 Go 1.11+ 并启用 Go Modules;使用它不需要其他外部依赖。
在生产环境中依赖它之前,有哪些需要注意的坑?Windows 版本明确仅用于开发和测试,不适用于生产环境;TLS 支持仍在规划中,目前尚不可用。
它实际能在哪些操作系统上运行?它可以在 Linux、macOS、Windows 以及多个 BSD 变体(Darwin、DragonFlyBSD、FreeBSD、NetBSD、OpenBSD)上运行,其中 Linux 使用 epoll,BSD 和 macOS 使用 kqueue。
为什么要用 gnet,而不用 Go 标准库的 net 包?在对性能要求苛刻的场景中,gnet 以牺牲 net 的通用性为代价,换取更高的速度和更低的内存占用:它直接利用 epoll/kqueue,而不是使用 Go 那种阻塞式的 net API。
用 gnet 到底能构建哪些协议?只要是在 TCP/UDP/Unix 套接字之上的应用层协议都可以:README 中给出了直接基于 gnet 实现的 HTTP、RPC、WebSocket 和 Redis 服务器等示例。
gnet 和其他框架相比有多快?在 TechEmpower Benchmark Round 22 排行榜上,gnet 在 486 个跨语言框架中名列第一,并被称为 Go 中最快的网络框架。
内置的 goroutine 池有什么作用?gnet 内置了一个由 ants 库驱动的 goroutine 池,并在整个运行期间无锁运行,这有助于它避免为每个连接创建一个 goroutine 所带来的开销。
What are similar projects?libuv, libevent, workerman, vert.x, muduo, swoole-src, tokio, zenc
Creator
panjf2000
Size
44.4 MB
Stars
11.2K
Age
7y
Commits · 90 Days