Categorygithub.com/walkon/gnet
modulepackage
1.6.0
Repository: https://github.com/walkon/gnet.git
Documentation: pkg.go.dev

# README

gnet

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 server framework for Go that performs on par with Redis and Haproxy for networking packets handling.

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
  • Built-in memory pool with bytes powered by the library bytebufferpool
  • Lock-free during the entire runtime
  • Concise and easy-to-use APIs
  • Efficient, reusable and scalable memory buffer: Ring-Buffer
  • Supporting multiple protocols/IPC mechanism: TCP, UDP and Unix Domain Socket
  • Supporting multiple load-balancing algorithms: Round-Robin, Source-Addr-Hash and Least-Connections
  • Supporting two event-driven mechanisms: epoll on Linux and kqueue on FreeBSD/DragonFly/Darwin
  • Supporting asynchronous write operation
  • Flexible ticker event
  • SO_REUSEPORT socket option
  • Built-in multiple codecs to encode/decode network frames into/from TCP stream: LineBasedFrameCodec, DelimiterBasedFrameCodec, FixedLengthFrameCodec and LengthFieldBasedFrameCodec, referencing netty codec, also supporting customized codecs
  • Supporting Windows platform with event-driven mechanism of IOCP Go stdlib: net
  • Implementation of gnet Client

📊 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

All language

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.

Golang

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 processors, AMD EPYC 7K62 48-Core Processor
    Memory : 16.0 GiB

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

# Netwokr settings
TCP connections : 300
Test duration   : 30s

Echo Server

HTTP Server

On FreeBSD (kqueue)

Test Environment

# Machine information
        OS : macOS Catalina 10.15.7/x86_64
       CPU : 6-Core Intel Core i7
    Memory : 16.0 GiB

# Go version and configurations
Go Version : go1.15.7 darwin/amd64
GOMAXPROCS : 12

# Netwokr settings
TCP connections : 100
Test duration   : 20s

Echo Server

HTTP Server

🏛 Website

Please visit the official website for more details about architecture, usage and other information of gnet.

⚠️ License

Source code in gnet is available under the MIT 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

🎡 User 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 of user cases.

💰 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.

        

💴 Donors

Patrick Othmer Jimmy ChenZhen Mai Yang 王开帅 Unger Alejandro

💵 Paid Support

If you need a tailored version of gnet and want the author to help develop it, or bug fix/fast resolution/consultation which takes a lot of effort, you can request paid support here.

🔑 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:

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
NewDelimiterBasedFrameCodec instantiates and returns a codec with a specific delimiter.
NewFixedLengthFrameCodec instantiates and returns a codec with fixed length.
NewLengthFieldBasedFrameCodec instantiates and returns a codec based on the length field.
No description provided by the author
Serve starts handling events for the specified address.
Stop gracefully shuts down the server without interrupting any active event-loops, it waits indefinitely for connections and event-loops to be closed and then shuts down.
WithCodec sets up a codec to handle TCP stream.
WithLoadBalancing sets up the load-balancing algorithm in gnet server.
WithLockOSThread sets up LockOSThread mode for I/O event-loops.
WithLogger sets up a customized logger.
WithLogLevel is an option to set up the logging level.
WithLogPath is an option to set up the local path of log file.
WithMulticore sets up multi-cores in gnet server.
WithNumEventLoop sets up NumEventLoop in gnet server.
WithOptions sets up all options.
WithReadBufferCap sets up ReadBufferCap for reading bytes.
WithReusePort sets up SO_REUSEPORT socket option.
WithSocketRecvBuffer sets the maximum socket receive buffer in bytes.
WithSocketSendBuffer sets the maximum socket send buffer in bytes.
WithTCPKeepAlive sets up the SO_KEEPALIVE socket option with duration.
WithTCPNoDelay enable/disable the TCP_NODELAY socket option.
WithTicker indicates that a ticker is set.

# Constants

Close closes the connection.
LeastConnections assigns the next accepted connection to the event-loop that is serving the least number of active connections at the current time.
None indicates that no action should occur following an event.
RoundRobin assigns the next accepted connection to the event-loop by polling event-loop list.
Shutdown shutdowns the server.
SourceAddrHash assignes the next accepted connection to the event-loop by hashing the remote address.
Available TCP socket options.
Available TCP socket options.

# Variables

CRLFByte represents a byte of CRLF.

# Structs

No description provided by the author
No description provided by the author
DecoderConfig config for decoder.
No description provided by the author
EncoderConfig config for encoder.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Options are set when the client opens.
Server represents a server context which provides information about the running server and has control functions for managing state.

# Interfaces

Conn is a interface of gnet connection.
No description provided by the author
No description provided by the author

# Type aliases

Action is an action that occurs after the completion of an event.
LoadBalancing represents the the type of load-balancing algorithm.
Option is a function that will set up option.
TCPSocketOpt is the type of TCP socket options.