-
Notifications
You must be signed in to change notification settings - Fork 13
/
uring_bench_test.go
81 lines (72 loc) · 1.52 KB
/
uring_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package gouring
import (
"context"
"runtime"
"syscall"
"testing"
)
func BenchmarkQueueNop(b *testing.B) {
type opt struct {
name string
entries uint32
p IoUringParams
}
ts := []opt{
{"def-256", 256, IoUringParams{Flags: 0}},
{"sqpoll-256-4-10000", 256, IoUringParams{Flags: IORING_SETUP_SQPOLL, SqThreadCpu: 16, SqThreadIdle: 10_000}},
}
consumer := func(h *IoUring, ctx context.Context, count int) {
var cqe *IoUringCqe
var err error
for i := 0; i < count; i++ {
if ctx.Err() != nil {
return
}
err = h.WaitCqe(&cqe)
if err == syscall.EINTR {
continue // ignore INTR
} else if err != nil {
panic(err)
}
if cqe.Res < 0 {
panic(syscall.Errno(-cqe.Res))
}
h.SeenCqe(cqe)
}
}
for _, tc := range ts {
b.Run(tc.name, func(b *testing.B) {
h := testNewIoUringWithParams(b, tc.entries, &tc.p)
defer h.Close()
var (
j uint32
sqe *IoUringSqe
err error
submitted int
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
b.ResetTimer()
for i := 0; i < b.N; i++ {
for j = 0; j < tc.entries; j++ {
for {
// sqe could be nil if SQ is already full so we spin until we got one
sqe = h.GetSqe()
if sqe != nil {
break
}
runtime.Gosched()
}
PrepNop(sqe)
sqe.UserData.SetUint64(uint64(i + int(j)))
}
submitted, err = h.Submit()
if err != nil {
panic(err)
}
consumer(h, ctx, submitted)
}
b.StopTimer()
})
}
}