Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance is so low #8

Open
awzhgw opened this issue Jul 6, 2020 · 3 comments
Open

performance is so low #8

awzhgw opened this issue Jul 6, 2020 · 3 comments

Comments

@awzhgw
Copy link

awzhgw commented Jul 6, 2020

package main

import (
	"flag"
	"fmt"
	"github.com/hodgesds/iouring-go"
	"log"
	"math/rand"
	_ "net/http/pprof"
	"os"
	"path"
	"sync/atomic"
	"time"
)

var (
	size=flag.Int64("size",64,"default write size")
	rootDir=flag.String("root","/data0","default write dir")
	uring=flag.Bool("iouring",true,"is used iouring")
	ring *iouring.Ring
)

func inita(){
	var err error
	if *uring{
		ring, err = iouring.New(
			8192,
			&iouring.Params{
				Features: iouring.FeatNoDrop,
			},
			iouring.WithID(100000),
		)
		if err!=nil{
			log.Fatalf("init failed %v",err)
		}
		iouring.FastOpenAllowed()
	}
}


func init() {
	rand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}

func main() {
	flag.Parse()

	Write()


}



func Write(){
	dst, err := os.OpenFile(path.Join(*rootDir,"1.txt"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		log.Fatal(err)
	}


	data:=make([]byte,*size)
	var cnt uint64
	go func() {
		ticker:=time.NewTicker(time.Second)
		for {
			select {
				case <-ticker.C:
					log.Println(fmt.Sprintf("iops is %v",atomic.LoadUint64(&cnt)))
					atomic.StoreUint64(&cnt,0)
			}
		}
	}()

	if *uring{
		r, err := ring.FileReadWriter(dst)
		if err!=nil {
			log.Fatal(err)
		}
		for {
			_,err=r.Write(data)
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}
	}else {
		for {
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}
	}
	dst.Close()
}


when iouring parameter is true ,,the iops is 18w    but ,when iouring parameter is false ,the iops is 88w ??


why ??????
@hodgesds
Copy link
Owner

The best throughput for doing single IO operations (Read, Write, etc) is roughly 80% of the performance of regular file IO operations. If you run the benchmarks it will show this. This is due to the fact that there is a lot more state handling that has to be done to allow for more concurrent IO. When the batching API is complete it's likely that single file IO may be slightly slower, but overall throughput on a large number of concurrent reads/writes will be far more efficient. This is the tradeoff that io_uring makes.

@derkan
Copy link

derkan commented Jul 13, 2020

I think your comparison is unfair:

  • when uring option, you're calling Write() with empty data.
               data:=make([]byte,*size)
                for {
			_,err=r.Write(data)
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}
  • when !uring option, you're not even calling Write() to file.
                for {
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}

Am I missing something?

@awzhgw
Copy link
Author

awzhgw commented Jul 14, 2020

package main

import (
	"flag"
	"fmt"
	"github.com/hodgesds/iouring-go"
	"log"
	"math/rand"
	_ "net/http/pprof"
	"os"
	"path"
	"sync/atomic"
	"time"
)

var (
	size=flag.Int64("size",64,"default write size")
	rootDir=flag.String("root","/data0","default write dir")
	uring=flag.Bool("iouring",true,"is used iouring")
	ring *iouring.Ring
)

func inita(){
	var err error
	if *uring{
		ring, err = iouring.New(
			8192,
			&iouring.Params{
				Features: iouring.FeatNoDrop,
			},
			iouring.WithID(100000),
		)
		if err!=nil{
			log.Fatalf("init failed %v",err)
		}
		iouring.FastOpenAllowed()
	}
}


func init() {
	rand.Seed(time.Now().UnixNano())
}
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
func RandStringRunes(n int) string {
	b := make([]rune, n)
	for i := range b {
		b[i] = letterRunes[rand.Intn(len(letterRunes))]
	}
	return string(b)
}

func main() {
	flag.Parse()
	inita()
	Write()


}



func Write(){
	dst, err := os.OpenFile(path.Join(*rootDir,"1.txt"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		log.Fatal(err)
	}


	data:=([]byte)(RandStringRunes(int(*size)))
	var cnt uint64
	go func() {
		ticker:=time.NewTicker(time.Second)
		for {
			select {
			case <-ticker.C:
				log.Println(fmt.Sprintf("iops is %v",atomic.LoadUint64(&cnt)))
				atomic.StoreUint64(&cnt,0)
			}
		}
	}()

	if *uring{
		r, err := ring.FileReadWriter(dst)
		if err!=nil {
			log.Fatal(err)
		}
		for {
			_,err=r.Write(data)
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}
	}else {
		for {
			_,err=dst.Write(data)
			if err!=nil {
				log.Fatalf("write error %v",err)
			}
			atomic.AddUint64(&cnt,1)
		}
	}
	dst.Close()
}


when iouring parameter is true ,,the iops is 18w    but ,when iouring parameter is false ,the iops is 88w ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants