Git Product home page Git Product logo

uringnet's Introduction

UringNet

Go Report Card https://codecov.io/gh/jceb/vim-orgmode Build GoDoc

logo

Introduction

Why I created this

UringNet is a high performance network I/O framework. It is light weighted and developed by Golang. The foundation of UringNet is io_uring - a new async IO interface - from Linux Kernel since version 5.1 in 2019. This project just comes from experimental projects in my edge computing and IoT research. I am just want to find a way to build a simple but high performance network package transmit tool in IoT gateways. I have tried traditional select/epoll and then tried io_uring, finally , the io_uring get much better performance. In most cases, the performance improvement ranges from 10% to 30%, while in the most extreme case, the performance improvement can reach up to 66%.

Should You adopt it in your project

Though UringNet is designed to be used in IoT platforms originally, it does provide basic TCP and UDP network functions. If your project really need to handle extremely huge data traffic, you can give it a try.

In most cases, you could just use more mature network frameworks, for example, Go net/http, netty, libuv.

Get Started

UringNet extensively references existing network frameworks such as gnet and Netty, with some usage patterns closely resembling those of gnet. Please note that UringNet is based on io_uring and, therefore, requires running on the Linux operating system with a kernel version higher than or equal to 5.1.

Install UringNet:

go get -u github.com/y001j/UringNet

echo server example

package main

import (
	"github.com/y001j/UringNet"
	socket "github.com/y001j/UringNet/sockets"
	"os"
	"sync"
)

type testServer struct {
	UringNet.BuiltinEventEngine

	testloop *UringNet.Ringloop
	//ring      *uring_net.URingNet
	addr      string
	multicore bool
}

// OnTraffic 
//  
//	@Description: OnTraffic is a hook function that runs every read event completed
//	@receiver ts
//	@param data
//	@return uring_net.Action
func (ts *testServer) OnTraffic(data *UringNet.UserData, ringnet UringNet.URingNet) UringNet.Action {
	data.WriteBuf = data.Buffer
	return UringNet.Echo
}

func (ts *testServer) OnWritten(data UringNet.UserData) UringNet.Action {
	return UringNet.None
}

func (ts *testServer) OnOpen(data *UringNet.UserData) ([]byte, UringNet.Action) {

	return nil, UringNet.None
}

func main() {
	addr := os.Args[1]


	options := socket.SocketOptions{TCPNoDelay: socket.TCPNoDelay, ReusePort: true}
	ringNets, _ := UringNet.NewMany(UringNet.NetAddress{socket.Tcp4, addr}, 3200, true, 8, options, &testServer{}) //runtime.NumCPU()

	loop := UringNet.SetLoops(ringNets, 3000)
	var waitgroup sync.WaitGroup
	waitgroup.Add(1)
	loop.RunMany()
	waitgroup.Wait()
}

Important APIs

UringNet.NewMany(UringNet.NetAddress{socket.Tcp4, addr}, 3200, true, 8, options, &testServer{})

Benchmark

Echo Stress Testing

In echo stress testing, the benchmark compared go net, gnet and UringNet

Echo test tool: rust echo bench

Test environment:

Host:

CPU:Intel Core i5 12400F 6 core 12 thread

Memory: DDR4 32GB

OS:Windows 11

Virtual Machine:

VMware® Workstation 16 Pro

Processors: 8P ; Memory 16GB; Intel VT-x

OS:Ubuntu 22.04.1 LTS, Kernel:5.19.3

Test Result

echo

HTTP Stress Testing

In HTTP stress testing, the benchmark compared gnet, fasthttp and UringNet

Echo test tool: wrk

Test Enviroment

Host:

CPU:Intel Core i5 12400F 6 core 12 thread

Memory: DDR4 32GB

OS:Windows 11

Testing Virtual Machine:

VMware® Workstation 16 Pro

Processors: 8P ; Memory 16GB; Intel VT-x

OS:Ubuntu 22.04.1 LTS, Kernel:5.19.3

wrk Virtual Machine:

VMware® Workstation 16 Pro

Processors: 4P ; Memory 8GB; Intel VT-x

OS:Ubuntu 20.04.5 LTS, Kernel:5.15.0

Test Result

image-20221212113551004

Known Issues

Warning: The project is still in development, there are still many bugs and performance issues. If you find any bugs or have any suggestions, please feel free to open an issue.

During our performance tests with wrk, we observed that UringNet requires a warm-up period during HTTP stress testing. Typically, a warm-up time of around 5 minutes is necessary to ensure that the UringNet test code reaches its peak performance, which surpasses the current fastest framework by more than 10%. I am still investigating the root cause of this behavior.

uringnet's People

Contributors

y001j avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.