Skip to content

Instantly share code, notes, and snippets.

@jim-minter
Created September 13, 2019 03:44
Show Gist options
  • Save jim-minter/18bc1ddbcdf8a937831e7673a3cf7cc1 to your computer and use it in GitHub Desktop.
Save jim-minter/18bc1ddbcdf8a937831e7673a3cf7cc1 to your computer and use it in GitHub Desktop.
dumb iops
package main
import (
"flag"
"fmt"
"os"
"runtime"
"sync/atomic"
"syscall"
"time"
)
var (
goroutines = flag.Int("goroutines", 32, "goroutines")
)
func main() {
flag.Parse()
runtime.GOMAXPROCS(2 * *goroutines)
var count int32
for i := 0; i < *goroutines; i++ {
go func(i int) {
fn := fmt.Sprintf("testfile-%d", i)
f, _ := os.Create(fn)
j := 0
for {
f.Seek(0, 0)
fmt.Fprintln(f, j)
syscall.Fdatasync(int(f.Fd()))
j++
atomic.AddInt32(&count, 1)
}
}(i)
}
var old int32
tick := time.Tick(time.Second)
for {
<-tick
new := atomic.LoadInt32(&count)
fmt.Println(new - old)
old = new
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment