- Notifications
You must be signed in to change notification settings - Fork1.1k
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
License
panjf2000/gnet
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
English |中文
🎉🎉🎉 Feel free to jointhe channels aboutgnet
on the Discord Server.
gnet
is an event-driven networking framework that is ultra-fast and lightweight. It is built from scratch by exploitingepoll andkqueue and it can achieve much higher performance with lower memory consumption than Gonet in many specific scenarios.
gnet
andnet don't share the same philosophy in network programming. Thus, building network applications withgnet
can be significantly different from building them withnet, and the philosophies can't be reconciled. There are other similar products written in other programming languages in the community, such aslibuv,netty,twisted,tornado, etc. which work in a similar pattern asgnet
under the hood.
gnet
is not designed to displace the Gonet, 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 Gonet, 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 Gonet 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 upongnet
for building diversified network services. For instance, you get an HTTP Server if you implement HTTP protocol upongnet
while you have a Redis Server done with the implementation of Redis protocol upongnet
and so on.
gnet
derives from the project:evio
with much higher performance and more features.
- High-performance event-driven looping based on a networking model of multiple threads/goroutines
- Built-in goroutine pool powered by the libraryants
- Lock-free during the entire runtime
- Concise and easy-to-use APIs
- Efficient, reusable, and elastic memory buffer: (Elastic-)Ring-Buffer, Linked-List-Buffer and Elastic-Mixed-Buffer
- Multiple protocols/IPC mechanisms:
TCP
,UDP
, andUnix Domain Socket
- Multiple load-balancing algorithms:
Round-Robin
,Source-Addr-Hash
, andLeast-Connections
- Flexible ticker event
gnet
client- Running on
Linux
,macOS
,Windows
, and *BSD:Darwin
/DragonFlyBSD
/FreeBSD
/NetBSD
/OpenBSD
- Edge-triggered I/O support
- Multiple network addresses binding
- TLS support
- io_uring support
- KCP support
Windows version ofgnet
should only be used in development for developing and testing, it shouldn't be used in production.
gnet
is available as a Go module and we highly recommend that you usegnet
viaGo Modules, with Go 1.11 Modules enabled (Go 1.11+), you can just simply addimport "github.com/panjf2000/gnet/v2"
to the codebase and rungo mod download/go mod tidy
orgo [build|run|test]
to download the necessary dependencies automatically.
go get -u github.com/panjf2000/gnet/v2
go get -u github.com/panjf2000/gnet
The following corporations/organizations usegnet
as the underlying network service in production.
If you're also usinggnet
in production, please help us enrich this list by opening a pull request.
# 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 top50 out of486 frameworks that encompass various programming languages worldwide, in whichgnet
is rankedfirst.
This is the full framework ranking of Go andgnet
tops all the other frameworks, which makesgnet
thefastest networking framework in Go.
To see the full ranking list, visitTechEmpower BenchmarkRound 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.
# 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 settingsGo Version: go1.17.2 linux/amd64GOMAXPROCS: 8# Benchmark parametersTCP connections: 1000/2000/5000/10000Packet size: 512/1024/2048/4096/8192/16384/32768/65536 bytesTest duration: 15s
# 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 settingsGo Version: go1.16.5 darwin/amd64GOMAXPROCS: 12# Benchmark parametersTCP connections: 300/400/500/600/700Packet size: 512/1024/2048/4096/8192 bytesTest duration: 15s
The source code ofgnet
should be distributed under the Apache-2.0 license.
Please read theContributing Guidelines before opening a PR and thank you to all the developers who already made contributions tognet
!
- A Million WebSockets and Go
- Going Infinite, handling 1M websockets connections in Go
- Go netpoller 原生网络模型之源码全面揭秘
- gnet: 一个轻量级且高性能的 Golang 网络库
- 最快的 Go 网络框架 gnet 来啦!
Support us with a monthly donation and help us continue our activities.
Become a bronze sponsor with a monthly donation of $10 and get your logo on our README on GitHub.
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.
gnet
has been being developed withGoLand
IDE under thefree JetBrains Open Source license(s) granted by JetBrains s.r.o., hence I would like to express my thanks here.
About
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.