gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go.
gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。
https://gnet.host/
English | 中文
📖 Introduction
gnet
is an event-driven networking framework that is fast and lightweight. It makes direct epoll and kqueue syscalls rather than using the standard Go net package and works in a similar manner as netty and libuv, which makes gnet
achieve a much higher performance than Go net.
gnet
is not designed to displace the standard Go net package, but to create a networking client/server framework for Go that performs on par with Redis and Haproxy for networking packets handling (although it does not limit itself to these areas), therefore, gnet
is not as comprehensive as Go net,
it only provides the core functionalities (by a concise API set) of a
networking application and it is not planned on being a full-featured
networking framework, as I think net has done a good enough job in this area.
gnet
sells itself as a high-performance,
lightweight, non-blocking, event-driven networking framework written in
pure Go which works on transport layer with TCP/UDP protocols and Unix
Domain Socket , so it allows developers to implement their own
protocols(HTTP, RPC, WebSocket, Redis, etc.) of application layer upon gnet
for building diversified network applications, for instance, you get
an HTTP Server or Web Framework 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
while having a much higher performance and more features.
🚀 Features
- High-performance event-loop under networking model of multiple threads/goroutines
- Built-in goroutine pool powered by the library ants
- 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
- Supporting multiple protocols/IPC mechanism:
TCP
,UDP
andUnix Domain Socket
- Supporting multiple load-balancing algorithms:
Round-Robin
,Source-Addr-Hash
andLeast-Connections
- Supporting two event-driven mechanisms:
epoll
on Linux andkqueue
on FreeBSD/DragonFly/Darwin - Flexible ticker event
- Implementation of
gnet
Client
🎬 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"
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 companies/organizations use gnet
as the underlying network service in production.
If you have gnet
integrated into projects, feel free to open a pull request refreshing this list.
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 Plaintext Benchmark.
Contrasts to the similar networking libraries
On Linux (epoll)
Test 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
Relevant Articles
- A Million WebSockets and Go
- Going Infinite, handling 1M websockets connections in Go
- Go netpoller 原生网络模型之源码全面揭秘
- gnet: 一个轻量级且高性能的 Golang 网络库
- 最快的 Go 网络框架 gnet 来啦!
JetBrains OS licenses
gnet
had 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.
from https://github.com/panjf2000/gnet
No comments:
Post a Comment