🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。

Overview

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 and reusable 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 your project is also using gnet, feel free to open a pull request to refresh 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:

Comments
  • v1.3.2版本发现连接建立后偶发没有触发OnOpened方法

    v1.3.2版本发现连接建立后偶发没有触发OnOpened方法

    潘神,你好。 我们使用了gnet的1.3.2版本做IM的服务器,上线一段时候后,我们发现一个非常诡异的现象。

    当我们的服务运行一段时间后,会莫名其妙的造成系统内存一直增加,而且用netstat命令查看,发现很多连接的Recv-Q有大量的堆积。然后通过查询日志发现这一类有Recv-Q堆积的连接都没有触发onOpend方法,也就是说我的程序根本就没有感知到这个连接的建立(是不是因此这个连接的接收数据会一直得不到接收,一直堆在接收缓冲区上?)

    附上recv-q的图 image

    期待得到你的回复。十分感谢。

    help wanted question 
    opened by Gitforxuyang 67
  • 大量连接断开nil错误

    大量连接断开nil错误

    Steps to reproduce the behavior:

    1. 监听tcp端口,使用多核,使用端口重用
    2. 客户端打开1W个连接,并且等到1W个连接,连接成功
    3. 关掉客户端
    4. 服务器抛出一个nil错误,并且退出

    image

    System Info (please complete the following information):

    • OS (e.g. Linux): ubuntu 19.10
    • Go Version (e.g. Go 1.13): 1.13.3
    • gnet Version (e.g. v1.0.0-beta.3): v1.0.0-beta7

    Additional context 客户端协议使用 github.com/gorilla/websocket 实现,服务端协议轻微修改

    bug help wanted question waiting for response 
    opened by luyu6056 40
  • 何时加个主动close?

    何时加个主动close?

    RT,还有建议加个GID等工具,使用协程本地变量,自动判断是EVENTLOOP的协程还是其他协程,这样写和关闭连接可以只用一个接口。API里那些返回 action的close感觉代码业务只会太耦合 Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    enhancement proposal waiting for response 
    opened by lonerwolf 23
  • opt: byte alignment, optimization from 144 to 136 byte

    opt: byte alignment, optimization from 144 to 136 byte


    name: Pull request about: opt title: 'byte alignment, optimization from 144 to 136 byte' labels: '' assignees: ''

    1. Are you opening this pull request for bug-fixes, optimizations or new feature?

    optimizations

    2. Please describe how these code changes achieve your intention.

    如题,字节对齐,每创建一个 conn 结构体,可节省 8 字节

    3. Please link to the relevant issues (if any).

    4. Which documentation changes (if any) need to be made/updated because of this PR?

    connection.go

    4. Checklist

    • [x] I have squashed all insignificant commits.
    • [x] I have commented my code for explaining package types, values, functions, and non-obvious lines.
    • [ ] I have written unit tests and verified that all tests passes (if needed).
    • [ ] I have documented feature info on the README (only when this PR is adding a new feature).
    • [x] (optional) I am willing to help maintain this change if there are issues with it later.
    opened by zhongweikang 21
  • 建议实现 net.Conn

    建议实现 net.Conn

    Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

    Describe the solution you'd like A clear and concise description of what you want to happen.

    Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

    Additional context Add any other context or screenshots about the feature request here.

    enhancement proposal 
    opened by lesismal 20
  • gnet@v1.6.5/acceptor_unix.go:38 Accept() fails due to error: too many open files

    [email protected]/acceptor_unix.go:38 Accept() fails due to error: too many open files

    不知道是使用不当,还是程序的bug,出现这个后,程序出现假死,收不到消息了,但程序并未退出,问题如下: image 即出现这几行错误日志后,程序不再接收消息。我查了一下代码,调用如下 1.start后,server_unix.go的171行开始调用 image 2.然后是reactor_default_linux.go的35行调用后,返回第一个错误 image 3.调用的是acceptor_unix.go的这个方法, image

    从以上看出返回的错误是3步的38行,打印出Accept() fails due to error: too many open files这行错误日志 然后走到2是39行打印出main reactor is exiting due to error: accept a new connection error这行日志错误后,程序不再接收消息 linux是默认1024个连接,表面上看是未关闭客户端连接造成的。

    bug needs investigation 
    opened by concn 19
  • 高并发下面报文乱序问题

    高并发下面报文乱序问题

    Describe the bug 两个机器,一个机器启动一定量的client, 不停的发数据,一个机器做echo. 会出现消息跨连接错乱情况

    To Reproduce 代码如下: client:

    package main
    
    import (
    	"encoding/binary"
    	"fmt"
    	"github.com/panjf2000/gnet"
    	"sync/atomic"
    	"test/utils"
    	"time"
    )
    
    type BytesINFO struct {
    	Data  []byte
    	Index uint64
    }
    
    type Client struct {
    	gnet.EventServer
    	connS map[gnet.Conn]struct{}
    	c     *gnet.Client
    }
    
    func NewClient() *Client {
    	c := &Client{
    		connS: map[gnet.Conn]struct{}{},
    	}
    	gc, err := gnet.NewClient(c)
    	utils.Must(err)
    	c.c = gc
    	gc.Start()
    	return c
    }
    
    func (this_ *Client) Start(addr string, count int) {
    	go func() {
    		for i := 0; i < count; i++ {
    			c, err := this_.c.Dial("tcp4", addr)
    			utils.Must(err)
    			this_.connS[c] = struct{}{}
    		}
    	}()
    }
    
    const packetSize = 1024
    
    func (this_ *Client) OnOpened(c gnet.Conn) (out []byte, action gnet.Action) {
    	// startIndex := uint64(0) //atomic.AddUint64(&initIndex, 10000000)
    	startIndex := atomic.AddUint64(&initIndex, 10000000)
    	bi := &BytesINFO{Index: startIndex}
    	c.SetContext(bi)
    	go func() {
    
    		index := startIndex
    		for {
    			b := make([]byte, packetSize)
    			binary.LittleEndian.PutUint64(b, index)
    			index++
    			err := c.AsyncWrite(b)
    			if err != nil {
    				panic(err)
    			}
    			time.Sleep(time.Millisecond)
    		}
    	}()
    	return nil, gnet.None
    }
    
    var (
    	initIndex = uint64(0)
    )
    
    func (this_ *Client) React(packet []byte, c gnet.Conn) (out []byte, action gnet.Action) {
    	bi := c.Context().(*BytesINFO)
    	bi.Data = append(bi.Data, packet...)
    	temp := bi.Data
    	for len(temp) >= packetSize {
    		index := binary.LittleEndian.Uint64(temp[:8])
    		if bi.Index != index {
    			panic(fmt.Sprintf("bi.Index[%d] != index[%d]", bi.Index, index))
    		}
    		bi.Index++
    		atomic.AddUint64(&count, 1)
    		temp = temp[packetSize:]
    	}
    	if len(temp) > 0 {
    		copy(bi.Data, temp)
    		bi.Data = bi.Data[:len(temp)]
    	} else {
    		bi.Data = bi.Data[:0]
    	}
    
    	return nil, gnet.None
    }
    
    func (this_ *Client) OnClosed(c gnet.Conn, err error) (action gnet.Action) {
    	fmt.Println("close:", c.RemoteAddr(), err)
    	return 0
    }
    
    func main() {
    	Start("10.23.20.53:9922", 10)
    	oldCount := uint64(0)
    	for {
    		time.Sleep(time.Second)
    		c := atomic.LoadUint64(&count)
    		fmt.Println(c, c-oldCount)
    		oldCount = c
    	}
    }
    
    var (
    	m     = map[*Client]struct{}{}
    	count uint64
    )
    
    func Start(addr string, count int) {
    	for i := 0; i < count; i++ {
    		c := NewClient()
    		c.Start(addr, 10)
    		m[c] = struct{}{}
    	}
    }
    
    

    server:

    package main
    
    import "github.com/panjf2000/gnet"
    
    type Server struct {
    	gnet.EventServer
    }
    
    func (this_ *Server) React(packet []byte, c gnet.Conn) (out []byte, action gnet.Action) {
    	return packet, gnet.None
    }
    
    func main() {
    	s := &Server{}
    	gnet.Serve(s, "tcp://0.0.0.0:9922", gnet.WithMulticore(true))
    }
    
    

    panic截图: {98c0bd53-ca49-4fed-b77c-b09bf39dfe1d}

    Expected behavior 如上图,期望从240000000开始,但是却收到了 1400000001.这个 1400000001是其他连接的数字,不应该收到 1400000001

    System Info (please complete the following information):

    • OS : client : Ubuntu 20.04 desktop ,server: CentOS Linux release 7.9.2009 (Core)
    • Go : 1.17和1.18beta1 都出现
    • gnet version : v1.6.4-0.20211215141823-afde9cd848f6

    Additional context 我们在接入gnet之前会做大量各种情况的 高并发压测。这个bug,出现概率 25%左右,并不是每次运行都出现。 目前只晓得数据跨连接错乱了。具体是client 端导致的还是server导致的还没找到原因

    bug 
    opened by FJSDS 19
  • 关于异步任务处理的疑问

    关于异步任务处理的疑问

    感谢潘少的项目 ∩^∩ 有个疑问啊,你在文中提到如果有大量的goroutine会给go的调度带来压力,我印象中go官方提到过不会带来压力。是我理解错了吗?谢谢。

    type Poller struct {
    	fd            int    // epoll fd
    	wfd           int    // wake fd
    	wfdBuf        []byte // wfd buffer to read packet
    	asyncJobQueue internal.AsyncJobQueue
    }
    

    另外能大概解析一下上面 wfd 具体作用吗?谢谢。

    在处理EpollWait返回事件有以下代码,请问wfd有什么作用呢?

    	if fd := int(el.events[i].Fd); fd != p.wfd { // 为什么要做这个判断呢?
    		if err = callback(fd, el.events[i].Events); err != nil {
    			return
    		}
    	} else {
    		wakenUp = true
    		fmt.Println("wfdbuf: ", p.wfdBuf)
    		_, _ = unix.Read(p.wfd, p.wfdBuf)
    	}
    

    -------------分割线 补上

    了解了eventfd的用法,对应上面的wfd,为了让异步执行的任务也统一通过epollWait来处理,但有两个疑问: 1,为什么要统一通过epollWait来统一调度呢,不可以想写数据的时候直接就往connfd中write呢?这样会有什么问题呢?谢谢。 2,

    func (q *AsyncJobQueue) ForEach() (err error) {
    	q.mu.Lock()
    	jobs := q.jobs
    	q.jobs = nil
    	q.mu.Unlock()
    	for i := range jobs {
    		if err = jobs[i](); err != nil {
    			return err
    		}
    	}
    	return
    }
    

    ForEach 这个函数会遍历所有的jobs并执行,那么只要一个jobs写入的eventfd被调度了,那么就会执行所有的jobs,而且定时器也会定时触发这个调度。这样感觉会导致一些异步任务的执行并不是由这个任务本身去触发的,而是由其他的任务触发的,而且还会有多次write(eventfd)后,多次read(eventfd)没必要的情况(因为jobs一次就已经全部执行完了)。 请问是我哪里理解错了吗?谢谢。

    question waiting for response 
    opened by yiippee 17
  • Gnet cannot support large value(>10K) redis benchmark test

    Gnet cannot support large value(>10K) redis benchmark test

    Describe the bug I try to implement a redis-server by gnet, but I cannot test by redis-benchmark

    cmd: redis-benchmark -h <host> -p<port> -t set,get -n 1000000 -d 1000000 -r 1000000

    how I implement it in React:

    1. read cmd in frame // async
    2. using immemeory map set/get
    3. return value image

    React: React(frame []byte, c gnet.Conn) (out []byte, action gnet.Action) To Reproduce just run bench

    Expected behavior it can test and show the result

    Screenshots the Screenshot shows only when -d (data size) is small it can run image

    System Info (please complete the following information):

    • OS (e.g. Ubuntu 16.04 & osx1.15):
    • Go version (e.g. Go 1.16):
    • gnet version (e.g. v1.6.1):

    Additional context the code is simple, if you need, I can upload later

    bug 
    opened by slow-zhang 16
  • 出现大量的 <Error: failed to delete fd=xxx from poller in event-loop(0): epoll_ctl del: no such file or directory>

    出现大量的

    Describe the bug 服务突然出现大量的此类错误,然后整个服务不可用。 想问下什么场景会出现此类错误

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    System Info (please fill out the following information):

    • OS (e.g. Ubuntu 18.04): Debian 5.4.143
    • Go version (e.g. Go 1.13): go1.18
    • gnet version (e.g. v1.0.0): v2.1.0
    waiting for response pending development needs fix 
    opened by JemmyH 15
  • FreeBSD 系统报错:software caused connection abort

    FreeBSD 系统报错:software caused connection abort

    Describe the bug 频繁出现Main reactor is exiting due to error: accept a new connection error,会是什么问题呢? 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:40 Main reactor is exiting due to error: accept a new connection error 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(2) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(3) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(1) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(0) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(4) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(5) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(6) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:53:02.000+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(7) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:40 Main reactor is exiting due to error: accept a new connection error 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(4) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(6) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(5) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(0) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(2) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(3) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(7) is exiting normally on the signal error: server is going to be shutdown 2021-02-18T19:57:42.380+0800 INFO [email protected]/reactor_bsd.go:67 Event-loop(1) is exiting normally on the signal error: server is going to be shutdown

    System Info (please complete the following information):

    • OS (e.g. Ubuntu 18.04): FreeBSD 12.2
    • Go version (e.g. Go 1.13): go version go1.15.6 freebsd/amd64
    • gnet version (e.g. v1.0.0): v1.3.3-0.20210209145202

    Additional context Add any other context about the problem here.

    bug waiting for response 
    opened by jonsen 15
  • Is it possible to find out the number of bytes written with `conn.AsyncWrite()`?

    Is it possible to find out the number of bytes written with `conn.AsyncWrite()`?

    Please fill out the following system information before opening an issue: OS: Ubuntu 20.04.5 LTS Go version: go1.19.3 linux/amd64 gnet version: 2.1.1

    What is your question about gnet? conn.Write() returns the number of bytes written. Is it possible to find out the number of bytes written with conn.AsyncWrite()?

    help wanted question proposal pending development proposal accepted 
    opened by gvitali 1
  • byteslice.Get 内存增长导致程序OOM

    byteslice.Get 内存增长导致程序OOM

    Describe the bug

    在阿里云k8s环境部署后,进行压测,向客户端写入数据时,内存持续快速增长,导致程序OOM

    Screenshots image

    System Info (please fill out the following information):

    • OS : Docker(alpine 3.16.2 )
    • Go version : go1.19.2
    • gnet version: v2.1.2
    bug needs investigation working on it 
    opened by soukengo 22
  • feat: add multiple listener support

    feat: add multiple listener support

    1. Are you opening this pull request for bug-fixes, optimizations or new feature?

    New feature

    2. Please describe how these code changes achieve your intention.

    This PR will add multi-listener support. The user can specify multiple IP:port pairs separated by commas.

    3. Please link to the relevant issues (if any).

    4. Which documentation changes (if any) need to be made/updated because of this PR?

    The gnet.Run command will accept multiple IP:port pairs like this:

    gnet.Run(echo, "tcp://192.168.0.100:8000,192.168.0.100:8001,192.168.0.100:8002")
    

    4. Checklist

    • [x] I have squashed all insignificant commits.
    • [x] I have commented my code for explaining package types, values, functions, and non-obvious lines.
    • [ ] I have written unit tests and verified that all tests passes (if needed).
    • [ ] I have documented feature info on the README (only when this PR is adding a new feature).
    • [x] (optional) I am willing to help maintain this change if there are issues with it later.
    opened by leki75 0
  • Question about the

    Question about the "read" function of "eventloop"

    Please fill out the following system information before opening an issue:

    • OS : windows 11
    • Go version : 1.18.1
    • gnet version : v2.0.3

    What is your question about gnet? Whether it need to use lock to prevent multiple conn data confusion when fd is reused on unix.

    help wanted question 
    opened by zhu121 5
Releases(v2.2.0)
  • v2.2.0(Dec 3, 2022)

    Changelogs

    • allow creation of multiple engines on the same protocol and port (#419)
    • opt: byte alignment, optimization from 144 to 136 byte (#369)
    • fix, unix socket bind should be only used in passive mode (#373)
    • Fix gnet.Conn not compatible with net.Conn on method Close (#348)
    • fix the bug of the return value of conn.WriteTo (#344)

    🧨 Breaking changes

    • opt: redefine AsyncCallback, pass in the error message 691e07747d11e3be90fb3b2996deb19448aa1e0e

    🚀 Features

    • opt: implement Close() for gnet.Conn to make it compatible with net.Conn (#348)
    • feat: implement a new API to convert and add net.Conn into gnet.Client c296922d171e64bcd0a97b1bf7eeb7adc747dad6
    • allow creation of multiple engines on the same protocol and port (#419)
    • feat: add multicast UDP listener support (#412)

    🛩 Enhancements

    • opt: reduce the memory allocation when a connection is idle 27667f3caad72fed296f86a2a5f624253ce01a56

    🐛 Bugfixes

    • bug: set the correct number of bytes written by conn.WriteTo() (#344)
    • bug: fix the issue of discarding bytes in buffer mistakenly in Conn.Read() 02820252e2e2a74ece265379386441dd1d4df2d9
    • bug: bind socket only when it's in passive mode (#373)
    • bug: fix the compile error on linux/mips f2e2fa31adc7694bc45b62aec261ccbe6d77819f
    • bug: return io.EOF in Read(), comply with io.Reader and io.Writer 3c3c519b8c57e750231db3d191e7257b5a3cf51d
    • bug: fix the issue failing to listen on 0.0.0.0 on linux/arm64 c9eeca1ee0a2d4cce1702d6c529f523fd3786e43
    • opt: avoid the long hanging when the peer crashes c138ac53b732540dcff6364d12823f5b6a8f10a8
    • opt: put the bytes of net.Addr.Zone back to pool when connection is closed 50406b34552ef6fb86795a9ee6c0e54ad71ae322

    🗃 Misc

    • opt: refine the logic of eventfd in poller 38aa2e0a03ca438c91100c16029ee0b7e6859c07
    • opt: fieldalignment, optimization from 144 to 104 byte f70489f555c7f627fcd268907f316dd02425da61
    • opt: improve the internal packages of math and bytes f1727999f277e995e8a33319a8e772d9b17b75c9

    Full Changelog: https://github.com/panjf2000/gnet/compare/v2.0.0...v2.2.0

    Thanks to all these contributors: @0-haha, @JemmyH, @ccssrryy, @jdamick, @leki75, @panjf2000, @zhongweikang and zhongweikang for making this release possible.

    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Feb 27, 2022)

  • v1.6.0(Dec 5, 2021)

    Gnet client is now available for production!

    Features

    • Add a new event handler: AfterWrite() #242
    • Implement the gnet client 2295e8c6f3394341d28318cb6ea33f0799d52c45 a5ac95a5057fb82e2f71cb6a7f4ffed83c967efb 4db46da43d5defd5da71213c0abaebb174af642c 802fa358f2c8ac95414e36cb0afd53f6dd57bfa0 7159b95cd9ebc8fe2f9bea909844eb8c8bb37bf7
    • Implement writev and readv on BSD-like OS's 60ba6d30b04351e26c3f7c9cc496b1b849936731
    • Implement a mixed buffer of ring-buffer and list-buffer edbdf4b54b7439bfb2ac4ba9652ec6a1764e0659
    • Invoke OnClosed() when a UDP socket is closed 7be4b2a758e32af489450b6b62d8da48e471ba00
    • Implement the gnet.Conn.AsyncWritev() 9a2032f876cd8f41c554545bcbb63d3043f4946f #245

    Enhancements

    • Prevent the event-list from expanding or shrinking endlessly b220dfd3f3ff9b8ecee4a09170d4db3760393fc0
    • Reduce the potential system calls for waking pollers up 9ce41f3b921a9341081506629185e733f97defa4
    • Eliminate the code for preventing false-sharing 0bfade3aea015a7932b0e45b646a6c85a620a205
    • Support so_reuseaddr (#280)
    • Make several improvements for logger 58d2031440b1c9725e2d12aeb651aa8bc78d3489
    • Optimize the buffer management and network I/O 6aba6d7a3fc31cf749b0001dcb1c82f01c816f65
    • Improve the project layout 2e172bde78bcdb56dbec9a57d95dfa4b6213b1f2
    • Improve the logic of reading data from socket into ring-buffer a7f07b3d4eaa70a9b5c8b389d73b72ddb06b8c16
    • Get as much data read from socket per loop as possible 148ee163fb3ddd0fcd7919ab17390a3cd910933f
    • Improve the network read with ring-buffer and readv 0dcf599fd0673bc712b5409fd9a0711cb90606c0
    • Avoid memory allocations when calling readv 15611b482f50f1333fcee47b02d6ec04b4d2ede5
    • Refactor the logic of handling UDP sockets d72d3de70a0cb31c6059820dbd4ba6db6c4e23eb
    • Make the mixed-buffer more flexible 4ac906cae698b1a4483c583d0267f86f05ce595b
    • Improve the management logic of the mixed-buffer b8d571dd762cb79c2c685f16d36886f6edb40195

    Bugfixes

    • Resolve the data race of stdConn on Windows (#235)
    • Fix the data corruption in some default codecs a56d2f3f50981107ae6b2bd2653fe19dc75d4e18
    • Fix the issue of panic: runtime error: slice bounds out of range 30311e936869d8685c8c06ff98170f0adb68bc8b

    Docs

    • Update the benchmark data 21f55a6832d82b88073c51ccfbed8a0e627399c3 24e4ce06a4c4e1d3990eec9945c98175763c027f 1b4ae56edf45bb3bc165c183a089fb0a8144ca67 81d984236401fb42d2f75c8989b87321804f4503
    • Add the echo benchmarks on macOS f429e7afaf3745574c95bf03d60baeaec2ecd9c1
    • Change the license from MIT to Apache 2.0 a900c8f21958eb8096443125afafb672d9f1218e

    Misc

    • Add a new patron 0c9f965f24a6a706ddcfbcc2ba2dd8339e611e8e
    • Create FUNDING.yml 1989eda4cc668e548f8572ac9fb07cef8c8f612d 7b29795db5fe184da0939490f8bf4ec39d3c27db
    • Remove the irrelevant articles bbdc1bcc76138feb3529d639e63ebe9374c22165
    • Correct the wrong logging function 10c619f3a42c4f8397464a7a45daff24bfa873ea
    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Jul 11, 2021)

    Features

    • Move the logging module out of the internal package and refactor to make it serviceable for users d566061586adfda7efbf58feec0bd8ebf7534479 b6b1cfb53400540000efb0f858d001437bc3d4f9 8837a92308f41805d38a2377da32530c6c79646d

    Enhancements

    • Support writev and readv in eventloop f299a8e39a1d5601afc3ddca6eec149e6aa3cf7b
    • Reduce GC pause frequency for Conn.AsyncWrite (#218) 477bb4fe46c38accf993fb11a9ba816bfa9fdc0b
    • Improve logging module 8837a92308f41805d38a2377da32530c6c79646d b6b1cfb53400540000efb0f858d001437bc3d4f9
    • Refactor the inside AsyncTaskQueue to make it more generic 2d1a4639d18dbd8faeb43649a3e4859378cc95e6
    • Reduce GC pause frequency for accepting connections 2d1a4639d18dbd8faeb43649a3e4859378cc95e6

    Docs

    • Add a new user case: Tencent Games b7ea839d959face861aca90ea493e5d3f8dfb205
    • Add a new donor ee965a1453d07300bf14749ea874a5d06ffc660e

    Misc

    • Add debugging log when error occurs in Accept() (#222)
    • Make some trivial changes to ring-buffer 1bdd3aa77da3827268e1145a07443460e1f01bd5
    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Feb 17, 2021)

    Features

    • Support TCP_NODELAY socket option 525df8ed1e734ac8d9a8f7fc4d28853a3f1e9cb3
    • Implement the lock-free queue for dispatching tasks faster (#181)

    Enhancements

    • Shrink the ring-buffer for saving memory 14fd04a041994e35393a2abf5c039db4e9f29f60
    • Improve event poll fc042ccde2d57697eafe278b2d6d9c056246e251
    • Improve the buffered channels 83b96eda98cb0ea311d776537a502151a029dab6
    • Shrink the poll event list when it need to 158763823c0c155bd3750c18d58cf887c7f2a813
    • Improve the I/O in event-loop c554f4ec298f76c6bb5710a62db710161189d239
    • Prioritize writable events 0f08c8f351c1cb60e83db1b6edf1babdb853767d
    • Make it more robust when running async jobs 6509b85eca7847abf8919829857e05851a408d0c
    • Improve the poller waking logic 4d8accba64f9c8e9da621409c5fa42d1aa3bea51

    Bugfixes

    • Re-enqueue the subsequent jobs when a error occurs 1af3f6c4734f41f424de4b929407ed401ddbc830
    • Close and release a socket when error occurs 9d86c92a224a3ce0b670070dd4256099c0dedcff
    • Check outbound buffer in case the socket has been released 035f6140a187f58c62d3d9e023f22fbdb81cd66f
    • Avoid starving sockets e3152523da481e8e59f1ac137e89b5c669287010

    Docs

    • Enrich the doc about using UDP packets 0047c15c6ccf98fddf985bbb254ab22abd2463ce
    • Add more user cases of gnet 076b16c68f52de65fb059ec9b81d03f0e7ef06f4
    • Update benchmark results 028bab284f63babd203b44dc59e2e0bde3ee2691
    • Update the description about ring-buffer 38b086af35cf57e9bc08f3655eefacab7985dd5a

    Misc

    • Add one more donor 12bfa5cfa7742859ad75f8117d3deadebeb7f12c
    • Refine code 2aee5a9ea2d86d2eabf2964be96cbf8ce643bc48
    • Add comments on those core code 2404edde0031ac52bf1dcb803708e347080b9e47
    • Refine code and add comments 4ecbc501c2cfa05773e338cd07d967bb1d0afad5
    • Add a warning comment for OnOpened 0bddd003d7d8934df7ab65389c8975e155c72440
    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Sep 20, 2020)

    Features

    • Determine logging mode by environment variable 2a7977feb33ba18f0c9d788dc611e85154df8548
    • Support locking each I/O event-loop goroutine to an OS thread 6fd6413920618f8cd9906923bd5768a43ce1c3b7

    Enhancements

    • Improve the implementation of Least-Connections load-balancing b6a5f564a9eea9c3fbb977c5ef3c8163689a63d0
    • Speed up the Least-Connections load-balancing b5fbbdac59588572b4a6e8c26bb6049cfd9b7211
    • Leverage system calls instead of net package to create listeners ccc8c649f380c546242251911040c8935a2cbb57
    • Refine the logging module f46da440d6435831558a1e8cbbd3f20a5ed2d773
    • Reorg errors in gnet 1c2f4b0c5127a4f40b5f635d604212a33e45a220
    • Move logging module into internal package 00af504ed00ab0ecb6477956ef4fe81f1dadd66e
    • Take off the codec from eventloop bc85c34e5f347fa055b5fea1ecb84fbbdf85ef91
    • Refactor for buffer in Conn 455c5ae5241e0875fc79a9338fefc38b4a5c17bc
    • Refactor the load-balancing algorithm of source addr hash abbf5820c1d264fa22e8bf8d00755d6093a86767
    • Make channel buffered if necessary 43f93ca57010dbb9b87f07928400301e487af65e

    Bugfixes

    • Fix a bug that led to negative counter of sync.WaitGroup on Windows 16ed4ab6719b70b396b47d5d51c1f70f44e1205a
    • Add "windows" build tag under SO_REUSEPORT mode 7862f3e2cb60554928c2d22f66213916dd69dbee
    • Supplement all the formal protocol formats of TCP and UDP 258253c7813a6577e338561f0c3da1bd7c5e57da
    • Resolve the issue of closing one fd twice b5a5c715ca07f8b4e3c371a8460274e77953bbdf
    • Fix concurrent loopCloseConn causes panic (#111)
    • Eliminate duplicate calls to loopCloseConn a72f5fd30757fa51cad4ad10c9583468c450b68e

    Docs

    • Add a customized codec example (#90)
    • Add placeholder for user cases and new relevant article 5197f186792670851ddcfdbe94b5317196e3ef6a
    • Renew results of techempower benchmark 61eee8fa29105002d2e1af17d2c1afc54001c6be
    • Add the list of donors 42e04ddc6ba2299ab89d107d2731725dacb31dcf
    • Add xs:code 33a3e5744e0c3c6c3ac1d3d965eabc5c5a93307d
    • Build an official website for gnet 49363cd41c73852bf52807a59b980ff2968f2e46
    • Move the majority of content to website and simplify READMEs 903ff8433d2d635f86b366b79eb304915c3fa662

    Misc

    • Fix a typo and improve code comments 37d75cce99609c9c17f25df2f6cfbfd3cf212ef8
    • Use SyscallError to wrap system calls errors c3907e00e2bb725cc4616587fb2e52f1c74c5999
    • Refine go build tags of operating systems 637144b487d4fa4f0a3ef40a2dada40586e188b5
    • Format copyright info 6872c20ab7c97342512149843322ff6111003ec3
    • Remove all examples from the source-code repo a704e0683e9c261c9f1e49c7443086068160fed2
    • refine the usage of os.NewSyscallError 2d54d80f42a6fa8e293db63a35033e1daa60cd56
    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(May 11, 2020)

    Features

    • Support graceful shutdown with OS signals (Fixes #82)

    Enhancements

    • Improve the creation processes of netpoller (Fixes #72) ccc6c25923404195e7fba960d6cdfb57d3a7cea4
    • Reuse slice struct when resetting buffer 916c255de373b3ff73eaa10cb1f0bacc2c1b6e3f
    • Make a big allocation on ring-buffer at the first time 61963bd439beba73ef29c74b9870442c867e192a

    Docs

    • Update Features section in READMEs a0d53f5061405901e17df4fa9760633edd9f1d98
    • Add a new article about gnet d500bf449f7808df210ff859014387a833c2f9f2
    • Supplement the missing acknowledgment item b031357ed623f630048a9222229e76c05cb7e6ef

    Misc

    • Enable ReadN(int) to handle corner cases 2e89e255fd636371c0671542387e807bcd18a496
    • Leverage reviewdog as automated code review tool 5db42f9413a7f17b6e6d8383f0e9c7c6dbf3a9d7
    • Use customized logger to log errors instead of std log package 3a697014af6c6a61828147d2def1f7a543e149b6
    • Remove useless field of server 47817a0b7098443d141e8857cbfc4d30f13b3965
    • Unexport some errors 5287bd8bde31bbcdfc482810479cd6c773afdeeb
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Apr 3, 2020)

    Features

    • Support new load-balancing algorithm of least-connections (#63)
    • Support new load-balancing algorithm of source-addr-hash (#64)
    • Add a new API to get the number of currently active connections 5ae4849ac2941394b21254950ec7101081add782

    Bugfixes

    • Fix an issue of not recycling byte-buffers 3b6edfdd933abab07a823bc0760c3d24b61b0879
    • Fix a bug of reading data from the full ring-buffer a9caa26689f9ecb46a98feb3bb5513639c8beb98

    Enhancements

    • Improve several methods of ring-buffer 828e845558c49918a647a1144eab8d9ca35887de
    • Refine the range indexes when re-slicing 008c0c9e4c702431db6b3d4372be94ea99ac5a5e
    • Lazily allocate memory for ring-buffers 095ef52c9275b5382b7e557da7bb40c5a3b156ca

    Docs

    • Switch go doc to pkg.go.dev b973741b7415e2e42b16e8dcf4adf6553c41ed40
    • Add TechEmpower benchmarks 65d859b02a7766808151db5a809f8776ba708cfd 9bd48a348281542d3cac008b5525a693981ec525 04b473e20f51afe4b798d54b336fc72a7c5cd7b0 3743d0f26ff38fec6872be0d13eac7e7d370d4b9
    • Improve some statements cc4ccd470b0a4fabf902896df714b7fd07346216

    Misc

    • Rename the eventloop_group.go to load_balancing.go 24203f4d936374666ef73c1ff7d96656c4de5fcb
    • Add unit test for ring-buffer ecf3473072d1c02ca69b469d24c5581eae041d2f 94246dc0fa7c0fcd02e0498e2a355f661b1403c8
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Mar 13, 2020)

    🚀 Features

    • [x] High-performance event-loop under networking model of multiple threads/goroutines
    • [x] Built-in load balancing algorithm: Round-Robin
    • [x] Built-in goroutine pool powered by the library ants
    • [x] Built-in memory pool with bytes powered by the library bytebufferpool
    • [x] Concise APIs
    • [x] Efficient memory usage: Ring-Buffer
    • [x] Supporting multiple protocols/IPC mechanism: TCP, UDP and Unix Domain Socket
    • [x] Supporting two event-driven mechanisms: epoll on Linux and kqueue on FreeBSD
    • [x] Supporting asynchronous write operation
    • [x] Flexible ticker event
    • [x] SO_REUSEPORT socket option
    • [x] 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
    • [x] Supporting Windows platform with ~~event-driven mechanism of IOCP~~ Go stdlib: net
    • [ ] Additional load-balancing algorithms: Random, Least-Connections, Consistent-hashing and so on
    • [ ] TLS support
    • [ ] Implementation of gnet Client
    Source code(tar.gz)
    Source code(zip)
Owner
Andy Pan
A front-line programmer based in South China. I mostly write server-side code. Also a modern agnostic.
Andy Pan
Netpoll is a high-performance non-blocking I/O networking framework, which focused on RPC scenarios, developed by ByteDance.

Netpoll is a high-performance non-blocking I/O networking framework, which focused on RPC scenarios, developed by ByteDance. RPC is usually heavy on processing logic and therefore cannot handle I/O serially. But Go's standard library net designed blocking I/O API, so that the RPC framework can only follow the One Conn One Goroutine design.

CloudWeGo 3.3k Jan 2, 2023
🚀Gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily build high-performance servers.

gev 中文 | English gev is a lightweight, fast non-blocking TCP network library based on Reactor mode. Support custom protocols to quickly and easily bui

徐旭 1.5k Jan 6, 2023
Native macOS networking for QEMU using vmnet.framework and socket networking.

qemu-vmnet Native macOS networking for QEMU using vmnet.framework and socket networking. Getting started TODO -netdev socket,id=net0,udp=:1234,localad

Alessio Dionisi 28 Jan 5, 2023
High performance async-io(proactor) networking for Golang。golangのための高性能非同期io(proactor)ネットワーキング

gaio Introduction 中文介绍 For a typical golang network program, you would first conn := lis.Accept() to get a connection and go func(net.Conn) to start a

xtaci 474 Dec 29, 2022
the pluto is a gateway new time, high performance, high stable, high availability, easy to use

pluto the pluto is a gateway new time, high performance, high stable, high availability, easy to use Acknowledgments thanks nbio for providing low lev

mobus 2 Sep 19, 2021
Fast event-loop networking for Go

evio 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 pac

Josh 5.5k Dec 31, 2022
Event driven modular status-bar for dwm; written in Go & uses Unix sockets for signaling.

dwmstat A simple event-driven modular status-bar for dwm. It is written in Go & uses Unix sockets for signaling. The status bar is conceptualized as a

Navaz Alani 1 Dec 25, 2021
Packiffer is a lightweight cross-platform networking toolkit that let you sniff/analyze/inject/filter packets.

Packiffer is a lightweight cross-platform networking toolkit that let you sniff/analyze/inject/filter packets.

Massoud Asadi 62 Dec 19, 2022
An event driven remote access trojan for experimental purposes.

erat An event driven remote access trojan for experimental purposes. This example is very simple and leverages ssh failed login events to trigger erat

siovador 0 Jan 16, 2022
Package event-driven makes it easy for you to drive events between services

Event-Driven Event-driven architecture is a software architecture and model for application design. With an event-driven system, the capture, communic

Ramooz 3 Apr 20, 2022
A fast, high performance Cross-platform lightweight Nat Tracker Server,

NatTrackerServer A fast, high performance Cross-platform lightweight Nat Tracker Server suport IPv4 and IPv6 Tracker Server protocol 1、get NAT public

51pwn 2 Apr 15, 2022
Network-wide ads & trackers blocking DNS server

Privacy protection center for you and your devices Free and open source, powerful network-wide ads & trackers blocking DNS server. AdGuard.com | Wiki

AdGuard 15.3k Dec 31, 2022
meek is a blocking-resistant pluggable transport for Tor.

meek is a blocking-resistant pluggable transport for Tor. It encodes a data stream as a sequence of HTTPS requests and responses. Requests are reflect

Clair de Lune 1 Nov 9, 2021
Middleware for Blocking IP ranges by inserting CIDR Blocks and searching IPs through those blocks

firewall Middleware for Blocking IP ranges by inserting CIDR Blocks and searching IPs through those blocks. Features Easy to use Efficient and Fast Co

Golang libraries for everyone 6 Oct 9, 2022
A decentralized P2P networking stack written in Go.

noise noise is an opinionated, easy-to-use P2P network stack for decentralized applications, and cryptographic protocols written in Go. noise is made

Perlin Network 1.7k Dec 29, 2022
YoMo 46 Nov 9, 2022
Fake server, Consumer Driven Contracts and help with testing performance from one configuration file with zero system dependencies and no coding whatsoever

mockingjay server Mockingjay lets you define the contract between a consumer and producer and with just a configuration file you get: A fast to launch

Chris James 530 Jan 6, 2023
High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.9k Jan 1, 2023