Categorygithub.com/iceber/iouring-go
modulepackage
0.0.0-20230403020409-002cfd2e2a90
Repository: https://github.com/iceber/iouring-go.git
Documentation: pkg.go.dev

# README

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

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)
}

Request With Extra Info

prepRequest := iouring.Write(int(file.Fd()), []byte(str)).WithInfo(file.Name())

request, err := iour.SubmitRequest(prepRequest, nil)
if err != nil {
    panic(err)
}

<- request.Done()
info, ok := request.GetRequestInfo().(string)

Cancel Request

prepR := iouring.Timeout(5 * time.Second)
request, err := iour.SubmitRequest(prepR, nil)
if err != nil {
    panic(err)
}

if _, err := request.Cancel(); err != nil{
    fmt.Printf("cancel request error: %v\n", err)
    return
}

<- request.Done()
if err := request.Err(); err != nil{
    if err == iouring.ErrRequestCanceled{
        fmt.Println("request is canceled"0
        return
    }
    fmt.Printf("request error: %v\n", err)
    return
}

Submit multitude request

var offset uint64
buf1 := make([]byte, 1024)
prep1:= iouring.Pread(fd, buf1, offset)

offset += 1024
buf2 := make([]byte, 1024)
prep2:= iouring.Pread(fd, buf1, offset)

requests, err := iour.SubmitRequests([]iouring.PrepRequest{prep1,prep2}, nil)
if err != nil{
    panic(err)
}
<- requests.Done()
fmt.Println("requests are completed")

requests is concurrent execution

Link request

var offset uint64
buf := make([]byte, 1024)
prep1 := iouring.Pread(fd, buf1, offset)
prep2 := iouring.Write(int(os.Stdout.Fd()), buf)

iour.SubmitLinkRequests([]iouring.PrepRequest{prep1, prep2}, nil)

Examples

cat

concurrent-cat

cp

request-with-timeout

link-request

link-with-timeout

timer

echo

echo-with-callback

TODO

  • add tests
  • arguments type (eg. int and int32)
  • set logger

# Packages

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

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
New return a IOURing instance by IOURingOptions.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithAttachWQ new iouring instance being create will share the asynchronous worker thread backend of the specified io_uring ring, rather than create a new separate thread pool.
WithCQE32 every CQE will have 32B entry size to append IOCTL return data.
WithCQSize create the completion queue with size entries size must bue greater than entries.
WithDisableRing the io_uring ring starts in a disabled state In this state, restrictions can be registered, but submissions are not allowed Available since 5.10.
WithDrain every SQE will not be started before previously submitted SQEs have completed.
WithParams use params.
WithSQE128 every SQE will have 128B entry size to append IOCTL command.
WithSQPoll a kernel thread is created to perform submission queue polling In Version 5.10 and later, allow using this as non-root, if the user has the CAP_SYS_NICE capability.
WithSQPollThreadCPU the poll thread will be bound to the cpu set, only meaningful when WithSQPoll option.
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

timeout operation return value.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
iouring operations.
cancel operation return value.
cancel operation return value.
timeout operation return value.

# Variables

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

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
IOURing contains iouring_syscall submission and completion queue.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

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

# Type aliases

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