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:10:27 -08:00 committed by gVisor bot
parent 5e22ab93e6
commit 7544eeb242
2 changed files with 17 additions and 30 deletions

View File

@ -34,37 +34,31 @@ func BenchmarkFio(b *testing.B) {
testCases := []tools.Fio{
{
Test: "write",
Size: b.N,
BlockSize: 4,
IODepth: 4,
},
{
Test: "write",
Size: b.N,
BlockSize: 1024,
IODepth: 4,
},
{
Test: "read",
Size: b.N,
BlockSize: 4,
IODepth: 4,
},
{
Test: "read",
Size: b.N,
BlockSize: 1024,
IODepth: 4,
},
{
Test: "randwrite",
Size: b.N,
BlockSize: 4,
IODepth: 4,
},
{
Test: "randread",
Size: b.N,
BlockSize: 4,
IODepth: 4,
},
@ -95,6 +89,8 @@ func BenchmarkFio(b *testing.B) {
b.Fatalf("Failed to parser paramters: %v", err)
}
b.Run(name, func(b *testing.B) {
b.StopTimer()
tc.Size = b.N
ctx := context.Background()
container := machine.GetContainer(ctx, b)
defer container.CleanUp(ctx)
@ -141,24 +137,18 @@ func BenchmarkFio(b *testing.B) {
}
cmd := tc.MakeCmd(outfile)
b.ResetTimer()
b.StopTimer()
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)
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()
tc.Report(b, data)
})
}
}

View File

@ -62,18 +62,15 @@ func (f *Fio) Report(b *testing.B, output string) {
// parseBandwidth reports the bandwidth in b/s.
func (f *Fio) parseBandwidth(data string, isRead bool) (float64, error) {
op := "write"
if isRead {
result, err := f.parseFioJSON(data, "read", "bw")
if err != nil {
return 0, err
}
return 1024 * result, nil
op = "read"
}
result, err := f.parseFioJSON(data, "write", "bw")
result, err := f.parseFioJSON(data, op, "bw")
if err != nil {
return 0, err
}
return 1024 * result, nil
return result * 1024, nil
}
// parseIOps reports the write IO per second metric.