Description
gnet is an Event-Loop networking framework that is fast and small. It makes direct epoll and kqueue syscalls rather than using the standard Go net package, and works in a similar manner as libuv and libevent.
The goal of this project is to create a server framework for Go that performs on par with Redis and Haproxy for packet handling.
gnet sells itself as a high-performance, lightweight, nonblocking network library written in pure Go which works on transport layer with TCP/UDP/Unix-Socket protocols, so it allows developers to implement their own protocols of application layer upon gnet for building diversified network applications.
For instance, you get a 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.
gent derives from project evio while having higher performance.
gnet alternatives and similar packages
Based on the "Networking" category.
Alternatively, view gnet alternatives based on common mentions on social networks and blogs.
-
fasthttp
Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http -
Netmaker
Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks. -
mqttPaho
The Paho Go Client provides an MQTT client library for connection to MQTT brokers via TCP, TLS or WebSockets. -
fortio
Fortio load testing library, command line tool, advanced echo server and web UI in go (golang). Allows to specify a set query-per-second load and record latency histograms and other useful stats. -
nbio
Pure Go 1000k+ connections solution, support tls/http1.x/websocket and basically compatible with net/http, with high-performance and low memory cost, non-blocking, event-driven, easy-to-use. -
gev
πGev is a lightweight, fast non-blocking TCP network library / websocket server based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers. -
gmqtt
Gmqtt is a flexible, high-performance MQTT broker library that fully implements the MQTT protocol V3.x and V5 in golang -
easytcp
:sparkles: :rocket: EasyTCP is a light-weight TCP framework written in Go (Golang), built with message router. EasyTCP helps you build a TCP server easily fast and less painful. -
peerdiscovery
Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman: -
raw
DISCONTINUED. Package raw enables reading and writing data at the device driver level for a network interface. MIT Licensed. -
ethernet
Package ethernet implements marshaling and unmarshaling of IEEE 802.3 Ethernet II frames and IEEE 802.1Q VLAN tags. MIT Licensed. -
buffstreams
A library to simplify writing applications using TCP sockets to stream protobuff messages
CodeRabbit: AI Code Reviews for Developers
Do you think we are missing an alternative of gnet or a related project?
Popular Comparisons
README
English | [δΈζ](README_ZH.md)
β οΈ Before you file any Github issues about gnet
Please read How To Ask Questions The Smart Way before you file an issue formally.
Furthermore, please comply with the issue template instead of just filling it out yourself, otherwise your issue may not be accepted or may even be closed outright.
π 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
- [x] [High-performance](#-performance) event-loop under networking model of multiple threads/goroutines
- [x] Built-in goroutine pool powered by the library ants
- [x] Lock-free during the entire runtime
- [x] Concise and easy-to-use APIs
- [x] Efficient, reusable and elastic memory buffer: (Elastic-)Ring-Buffer, Linked-List-Buffer and Elastic-Mixed-Buffer
- [x] Supporting multiple protocols/IPC mechanism:
TCP
,UDP
andUnix Domain Socket
- [x] Supporting multiple load-balancing algorithms:
Round-Robin
,Source-Addr-Hash
andLeast-Connections
- [x] Supporting two event-driven mechanisms:
epoll
on Linux andkqueue
on FreeBSD/DragonFly/Darwin - [x] Flexible ticker event
- [x] 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.
π Performance
Benchmarks on TechEmpower
# Hardware Environment
CPU: 28 HT Cores Intel(R) Xeon(R) Gold 5120 CPU @ 2.20GHz
Mem: 32GB RAM
OS : Ubuntu 18.04.3 4.15.0-88-generic #88-Ubuntu
Net: Switched 10-gigabit ethernet
Go : go1.14.x linux/amd64
This is the top 50 on the framework ranking of all programming languages consists of a total of 422 frameworks from all over the world where gnet
is the runner-up.
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
Echo benchmark
On MacOS (kqueue)
Test 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
Echo benchmark
β οΈ License
Source code of gnet
should be distributed under the Apache-2.0 license.
π Contributors
Please read the [Contributing Guidelines](CONTRIBUTING.md) before opening a PR and thank you to all the developers who already made contributions to gnet
!
β Relevant Articles
- A Million WebSockets and Go
- Going Infinite, handling 1M websockets connections in Go
- Go netpoller εηη½η»ζ¨‘εδΉζΊη ε ¨ι’ζη§
- gnet: δΈδΈͺθ½»ιηΊ§δΈι«ζ§θ½η Golang η½η»εΊ
- ζεΏ«η Go η½η»ζ‘ζΆ gnet ζ₯ε¦οΌ
π° Backers
Support us with a monthly donation and help us continue our activities.
π Sponsors
Become a bronze sponsor with a monthly donation of $10 and get your logo on our README on Github.
βοΈ 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.
π΄ Patrons
π 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.
π Sponsorship
This project is supported by:
*Note that all licence references and agreements mentioned in the gnet README section above
are relevant to that project's source code only.