Correctly set and respect b.N in fio benchmark.

fio should scale by written/read bytes and not iterate runs
of the fio container.

PiperOrigin-RevId: 358511771
This commit is contained in:
Zach Koopmans
2021-02-19 17:12:42 -08:00
committed by gVisor bot
parent 5e22ab93e6
commit 7544eeb242
2 changed files with 17 additions and 30 deletions
+13 -23
View File
@@ -34,37 +34,31 @@ func BenchmarkFio(b *testing.B) {
testCases := []tools.Fio{ testCases := []tools.Fio{
{ {
Test: "write", Test: "write",
Size: b.N,
BlockSize: 4, BlockSize: 4,
IODepth: 4, IODepth: 4,
}, },
{ {
Test: "write", Test: "write",
Size: b.N,
BlockSize: 1024, BlockSize: 1024,
IODepth: 4, IODepth: 4,
}, },
{ {
Test: "read", Test: "read",
Size: b.N,
BlockSize: 4, BlockSize: 4,
IODepth: 4, IODepth: 4,
}, },
{ {
Test: "read", Test: "read",
Size: b.N,
BlockSize: 1024, BlockSize: 1024,
IODepth: 4, IODepth: 4,
}, },
{ {
Test: "randwrite", Test: "randwrite",
Size: b.N,
BlockSize: 4, BlockSize: 4,
IODepth: 4, IODepth: 4,
}, },
{ {
Test: "randread", Test: "randread",
Size: b.N,
BlockSize: 4, BlockSize: 4,
IODepth: 4, IODepth: 4,
}, },
@@ -95,6 +89,8 @@ func BenchmarkFio(b *testing.B) {
b.Fatalf("Failed to parser paramters: %v", err) b.Fatalf("Failed to parser paramters: %v", err)
} }
b.Run(name, func(b *testing.B) { b.Run(name, func(b *testing.B) {
b.StopTimer()
tc.Size = b.N
ctx := context.Background() ctx := context.Background()
container := machine.GetContainer(ctx, b) container := machine.GetContainer(ctx, b)
defer container.CleanUp(ctx) defer container.CleanUp(ctx)
@@ -141,24 +137,18 @@ func BenchmarkFio(b *testing.B) {
} }
cmd := tc.MakeCmd(outfile) cmd := tc.MakeCmd(outfile)
b.ResetTimer() if err := harness.DropCaches(machine); err != nil {
b.StopTimer() b.Fatalf("failed to drop caches: %v", err)
for i := 0; i < b.N; i++ {
if err := harness.DropCaches(machine); err != nil {
b.Fatalf("failed to drop caches: %v", err)
}
// Run fio.
b.StartTimer()
data, err := container.Exec(ctx, dockerutil.ExecOpts{}, cmd...)
if err != nil {
b.Fatalf("failed to run cmd %v: %v", cmd, err)
}
b.StopTimer()
b.SetBytes(1024 * 1024) // Bytes for go reporting (Size is in megabytes).
tc.Report(b, data)
} }
// Run fio.
b.StartTimer()
data, err := container.Exec(ctx, dockerutil.ExecOpts{}, cmd...)
if err != nil {
b.Fatalf("failed to run cmd %v: %v", cmd, err)
}
b.StopTimer()
tc.Report(b, data)
}) })
} }
} }
+4 -7
View File
@@ -62,18 +62,15 @@ func (f *Fio) Report(b *testing.B, output string) {
// parseBandwidth reports the bandwidth in b/s. // parseBandwidth reports the bandwidth in b/s.
func (f *Fio) parseBandwidth(data string, isRead bool) (float64, error) { func (f *Fio) parseBandwidth(data string, isRead bool) (float64, error) {
op := "write"
if isRead { if isRead {
result, err := f.parseFioJSON(data, "read", "bw") op = "read"
if err != nil {
return 0, err
}
return 1024 * result, nil
} }
result, err := f.parseFioJSON(data, "write", "bw") result, err := f.parseFioJSON(data, op, "bw")
if err != nil { if err != nil {
return 0, err return 0, err
} }
return 1024 * result, nil return result * 1024, nil
} }
// parseIOps reports the write IO per second metric. // parseIOps reports the write IO per second metric.