From 7544eeb242d0aba2da054a1663e043feaedb9618 Mon Sep 17 00:00:00 2001 From: Zach Koopmans Date: Fri, 19 Feb 2021 17:10:27 -0800 Subject: [PATCH] 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 --- test/benchmarks/fs/fio_test.go | 36 ++++++++++++---------------------- test/benchmarks/tools/fio.go | 11 ++++------- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/test/benchmarks/fs/fio_test.go b/test/benchmarks/fs/fio_test.go index 242374e2c..cc2d1cbbc 100644 --- a/test/benchmarks/fs/fio_test.go +++ b/test/benchmarks/fs/fio_test.go @@ -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) }) } } diff --git a/test/benchmarks/tools/fio.go b/test/benchmarks/tools/fio.go index f6324c3ab..ea12436d2 100644 --- a/test/benchmarks/tools/fio.go +++ b/test/benchmarks/tools/fio.go @@ -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.