Gain
Gain is a high-performance io_uring networking framework written entirely in Go.
Install / Use
/learn @pawelgaczynski/GainREADME
<a name="readme-top"></a>
<br /> <div align="center"> <a href="https://github.com/pawelgaczynski/gain"> <img src="images/gain.png" alt="Logo" width="495" height="327"> </a> <h2 align="center">Gain</h2> <p align="center"> Gain is a high-performance io_uring networking framework written entirely in Go. <br /> <br /> <a href="https://github.com/pawelgaczynski/gain/issues">Report Bug</a> · <a href="https://github.com/pawelgaczynski/gain/issues">Request Feature</a> </p> </div> <details> <summary>Table of Contents</summary> <ol> <li> <a href="#about-the-project">About The Project</a> </li> <li> <a href="#getting-started">Getting Started</a> <ul> <li><a href="#prerequisites">Prerequisites</a></li> <li><a href="#installation">Installation</a></li> </ul> </li> <li><a href="#usage">Usage</a></li> <li><a href="#roadmap">Roadmap</a></li> <li><a href="#performance">Performance</a></li> <li><a href="#contributing">Contributing</a></li> <li><a href="#license">License</a></li> <li><a href="#contact">Contact</a></li> <li><a href="#relevant-articles">Relevant Articles</a></li> </ol> </details> <br/>About The Project
Gain is a high-performance networking framework written entirely in Go. It uses io_uring - a new asynchronous I/O API for Linux created by Jens Axboe from Facebook. Currently only Linux is supported.
WARNING: This is an alpha version so it is not yet stable enough to use in a production environment.
Articles about the project:
- Medium - Meet Gain - the New Fastest Go TCP Framework
- Medium - Writing High-performance TCP Applications Using the Gain Web Framework
Getting Started
See examples:
<br/>Prerequisites
Gain requires Go 1.20+
<br/>Installation
- Install the framework
go get -u github.com/pawelgaczynski/gain@v0.4.0-alpha
Roadmap
- [x] Go liburing port
- [x] Reactor architecture
- [x] Socket sharding architecture
- [x] Async workers and workers pool
- [x] Lock-free
- [ ] Protocols
- [x] TCP
- [x] UDP
- [ ] Unix Domain Socket
- [ ] Load balancing
- [x] Round robin
- [x] Least connection
- [x] Source IP hash
- [ ] Support for custom implementations
- [ ] Support for read and write deadlines
- [ ] Further io_uring optimizations
- [x] More flexible connection buffer
- [x] Documentation
- [x] Support for kernels older than 5.15
- [ ] Support for Windows - IoRing (documentation)
See the open issues for a full list of proposed features (and known issues).
<p align="right">(<a href="#readme-top">back to top</a>)</p>Performance
AWS EC2 instance: m6i.xlarge <br/> vCPU: 4 <br/> RAM: 16GB <br/> OS: Ubuntu 22.04 LTS <br/> Kernel: 5.15.0-1026-aws <br/> Go: go1.19.3 linux/amd64 <br/> Number of connections: 512 <br/> Benchmark type: see TechEmpower Plaintext <br/>
<br/> <a href="https://github.com/pawelgaczynski/gain"> <img src="images/benchmark_result.png" alt="Logo" width="710" height="454"> </a> <br/> <br/>Perfect locality
Run this script on the server machine before starting Gain. The first parameter is the name of network interface (e.g. eth0, ens5).
#!/bin/bash
systemctl stop irqbalance.service
export IRQS=($(grep $1 /proc/interrupts | awk '{print $1}' | tr -d :))
for i in ${!IRQS[@]}; do echo $i > /proc/irq/${IRQS[i]}/smp_affinity_list; done;
export TXQUEUES=($(ls -1qdv /sys/class/net/$1/queues/tx-*))
for i in ${!TXQUEUES[@]}; do printf '%x' $((2**i)) > ${TXQUEUES[i]}/xps_cpus; done;
To understand how it was achieved read an excellent article: Extreme HTTP Performance Tuning
<p align="right">(<a href="#readme-top">back to top</a>)</p>Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the Apache 2.0 License. See LICENSE for more information.
Contact
Paweł Gaczyński - LinkedIn
Project Link: https://github.com/pawelgaczynski/gain
<p align="right">(<a href="#readme-top">back to top</a>)</p>Relevant Articles
- Lord of the io_uring
- Ringing in a new asynchronous I/O API
- The rapid growth of io_uring
- An Introduction to the io_uring Asynchronous I/O Framework
- How io_uring and eBPF Will Revolutionize Programming in Linux
- Missing Manuals - io_uring worker pool
- IO_uring Continues Advancing In 2022 With New Features For Pushing Linux I/O
- Getting Hands on with io_uring using Go
- liburing Github
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
