- 类别:Go
- 项目标题:UringNet新一代基于io_uring的超高性能网络库
- 项目描述:UringNet由于采用了最新的异步框架,因此在同等硬件配置条件下,UringNet比目前性能最好的基于select/epoll的框架的网络I/O的峰值数据还要高10%-30%,在极端情况下有可能高出60%以上。
-
亮点1:采用了最新的Linux内核的io_uring异步IO接口,网络传输性能大大增加。在树莓派上的对比测试结果:https://zhuanlan.zhihu.com/p/659504322
-
亮点2:发布在raddit的r/golang社区的项目发布帖子 UringNet - an Ultra-Fast Network I/O Framework with Power of io_uring raddit的golang社区版主jerf的评论:
-
示例代码:HTTP压测代码
package main
import ( "bytes" "github.com/y001j/UringNet" "github.com/y001j/UringNet/sockets" "os" "runtime" "sync" "time" )
type testServer struct { UringNet.BuiltinEventEngine
testloop *UringNet.Ringloop
//ring *uring_net.URingNet
addr string
multicore bool
}
type httpCodec struct { delimiter []byte buf []byte }
func appendResponse(hc []byte) { hc = append(hc, "HTTP/1.1 200 OK\r\nServer: uringNet\r\nContent-Type: text/plain\r\nDate: "...) hc = time.Now().AppendFormat(hc, "Mon, 02 Jan 2006 15:04:05 GMT") hc = append(*hc, "\r\nContent-Length: 12\r\n\r\nHello World!"...) }
var ( errMsg = "Internal Server Error" errMsgBytes = []byte(errMsg) )
func (ts testServer) OnTraffic(data UringNet.UserData, ringnet UringNet.URingNet) UringNet.Action {
buffer := ringnet.ReadBuffer
count := bytes.Count(buffer, []byte("GET"))
if count == 0 {
return UringNet.None
} else {
for i := 0; i < count; i++ {
appendResponse(&data.WriteBuf)
}
}
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) {
ts.SetContext(&httpCodec{delimiter: []byte("\r\n\r\n")})
return nil, UringNet.None
}
func main() { addr := os.Args[1] //runtime.GOMAXPROCS(runtime.NumCPU())
options := socket.SocketOptions{TCPNoDelay: socket.TCPNoDelay, ReusePort: true}
ringNets, _ := UringNet.NewMany(UringNet.NetAddress{socket.Tcp4, addr}, 3200, true, runtime.NumCPU(), options, &testServer{})
loop := UringNet.SetLoops(ringNets, 4000)
var waitgroup sync.WaitGroup
waitgroup.Add(1)
loop.RunMany()
waitgroup.Wait()
}
- 截图:
- 后续更新计划:重构代码,提高可读性和规范性。