What is io_uring

io_uring

io_uring-wahtsnew

LWN io_uring

Lord of the io_uring

【译】高性能异步 IO —— io_uring (Effecient IO with io_uring)

Go 与异步 IO – io_uring 的思考

Features

  • register a file set for io_uring instance
  • support file IO
  • support socket IO
  • support IO timeout
  • link request
  • set timer
  • add request extra info, could get it from the result
  • set logger
  • register buffers and IO with buffers
  • support SQPoll

OS Requirements

  • Linux Kernel >= 5.6

Installation

go get github.com/iceber/iouring-go

doc

Quickstart

<div class="highlight highlight-source-go position-relative" data-snippet-clipboard-copy-content="package main

import (
" fmt" "os" "github.com iceber iouring-go" ) var str="io with iouring" func main() { iour, err := iouring.New(1) if err != nil { panic(fmt.Sprintf("new IOURing error: %v", err)) } defer iour.Close() file, err := os.Create("./tmp.txt") if err != nil { panic(err) } ch := make(chan iouring.Result, 1) prepRequest := iouring.Write(int(file.Fd()), []byte(str)) if _, err := iour.SubmitRequest(prepRequest, ch); err != nil { panic(err) } result :=

package main

import (
        "fmt"
        "os"

        "github.com/iceber/iouring-go"
)

var str = "io with iouring"

func main() {
        iour, err := iouring.New(1)
        if err != nil {
                panic(fmt.Sprintf("new IOURing error: %v", err))
        }
        defer iour.Close()

        file, err := os.Create("./tmp.txt")
        if err != nil {
                panic(err)
        }

        ch := make(chan iouring.Result, 1)

        prepRequest := iouring.Write(int(file.Fd()), []byte(str))
        if _, err := iour.SubmitRequest(prepRequest, ch); err != nil {
                panic(err)
        }

        result := <-ch
        i, err := result.ReturnInt()
        if err != nil {
                fmt.Println("write error: ", err)
                return
        }

        fmt.Printf("write byte: %d\n", i)
}