Categorygithub.com/yistabraq/gain
modulepackage
0.0.0-20230913195951-570722cda644
Repository: https://github.com/yistabraq/gain.git
Documentation: pkg.go.dev

# README


Logo

Apache 2.0 License Go Reference Go Report Card codecov

Gain

Gain is a high-performance io_uring networking framework written entirely in Go.

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Performance
  6. Contributing
  7. License
  8. Contact
  9. Relevant Articles

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:


Getting Started

See examples:


Prerequisites

Gain requires Go 1.20+


Installation

  1. Install the framework
    go get -u github.com/pawelgaczynski/[email protected]
    

(back to top)

Roadmap

  • Go liburing port
  • Reactor architecture
  • Socket sharding architecture
  • Async workers and workers pool
  • Lock-free
  • Protocols
    • TCP
    • UDP
    • Unix Domain Socket
  • Load balancing
    • Round robin
    • Least connection
    • Source IP hash
    • Support for custom implementations
  • Support for read and write deadlines
  • Further io_uring optimizations
  • More flexible connection buffer
  • Documentation
  • 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).

(back to top)

Performance

AWS EC2 instance: m6i.xlarge
vCPU: 4
RAM: 16GB
OS: Ubuntu 22.04 LTS
Kernel: 5.15.0-1026-aws
Go: go1.19.3 linux/amd64
Number of connections: 512
Benchmark type: see TechEmpower Plaintext


Logo

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

(back to top)

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the Apache 2.0 License. See LICENSE for more information.

(back to top)

Contact

Paweł Gaczyński - LinkedIn

Project Link: https://github.com/pawelgaczynski/gain

(back to top)

Relevant Articles

(back to top)

# Packages

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

# Functions

ListenAndServe starts a server with a given address and event handler.
No description provided by the author
No description provided by the author
WithArchitecture sets the architecture of gain engine.
WithAsyncHandler sets the asynchronous mode for the OnRead callback.
WithCBPF sets the CBPF filter for the gain engine.
WithCPUAffinity sets the CPU affinity option.
WithGoroutinePool sets the goroutine pool for asynchronous handler.
WithLoadBalancing sets the load balancing algorithm.
WithLoggerLevel sets the logging level.
WithMaxCQEvents sets the maximum number of entries in the completion queue.
WithMaxSQEntries sets the maximum number of entries in the submission queue.
WithPrettyLogger sets the pretty-printing zerolog mode.
WithProcessPriority sets the high process priority.
WithSocketRecvBufferSize sets the maximum socket receive buffer in bytes.
WithSocketSendBufferSize sets the maximum socket send buffer in bytes.
WithTCPKeepAlive sets the TCP keep-alive for the socket.
WithWorkers sets the number of workers.

# Constants

LeastConnections forwards the next accepted connection to the worker with the least number of active connections.
Reactor design pattern has one input called Acceptor, which demultiplexes the handling of incoming connections to Consumer workers.
RoundRobin forwards accepted connections to dedicated workers sequentially.
The Socket Sharding allow multiple workers to listen on the same address and port combination.
SourceAddrHash forwards the next accepted connection to the worker by hashing the remote peer address.

# Structs

Config is the configuration for the gain engine.
DefaultEventHandler is a default implementation for all of the EventHandler callbacks (do nothing).

# Interfaces

Conn is an interface representing a network connection.
No description provided by the author
Reader is an interface that consists of a number of methods for reading that Conn must implement.
No description provided by the author
Socket is an interface that represents a socket.
Writer is an interface that consists of a number of methods for writing that Conn must implement.

# Type aliases

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