From c774354379fc3c42845e5a9aee8c2ca87a9c05b3 Mon Sep 17 00:00:00 2001 From: BrennaEpp Date: Mon, 14 Aug 2023 17:46:18 -0700 Subject: [PATCH 1/5] chore(storage): add warmup option [benchmarks] --- storage/internal/benchmarks/main.go | 6 +++ storage/internal/benchmarks/warmup.go | 72 +++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 storage/internal/benchmarks/warmup.go diff --git a/storage/internal/benchmarks/main.go b/storage/internal/benchmarks/main.go index a633faeb7674..e45be2571400 100644 --- a/storage/internal/benchmarks/main.go +++ b/storage/internal/benchmarks/main.go @@ -96,6 +96,7 @@ type benchmarkOptions struct { enableTracing bool traceSampleRate float64 + warmup time.Duration } func (b *benchmarkOptions) validate() error { @@ -194,6 +195,8 @@ func parseFlags() { flag.IntVar(&opts.workload, "workload", 1, "which workload to run") flag.IntVar(&opts.numObjectsPerDirectory, "directory_num_objects", 1000, "total number of objects in directory") + flag.DurationVar(&opts.warmup, "warmup", 0, "time to warmup benchmarks; w1r3 benchmarks will be run for this duration without recording any results") + flag.Parse() if len(projectID) < 1 { @@ -283,6 +286,9 @@ func main() { log.Fatalf("populateDependencyVersions: %v", err) } + if err := warmupW1R3(ctx, opts); err != nil { + log.Fatal(err) + } recordResultGroup, _ := errgroup.WithContext(ctx) startRecordingResults(w, recordResultGroup, opts.outType) diff --git a/storage/internal/benchmarks/warmup.go b/storage/internal/benchmarks/warmup.go new file mode 100644 index 000000000000..d4a7845b1d20 --- /dev/null +++ b/storage/internal/benchmarks/warmup.go @@ -0,0 +1,72 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "context" + "fmt" + "time" + + "golang.org/x/sync/errgroup" +) + +func warmupW1R3(ctx context.Context, opts *benchmarkOptions) error { + ctx, cancel := context.WithCancel(ctx) + defer cancel() + + discardBenchmarkResults(ctx) + + warmupGroup, ctx := errgroup.WithContext(ctx) + warmupGroup.SetLimit(opts.numWorkers) + + for deadline := time.Now().Add(opts.warmup); time.Now().Before(deadline); { + warmupGroup.Go(func() error { + benchmark := &w1r3{opts: opts, bucketName: opts.bucket} + + if err := benchmark.setup(ctx); err != nil { + return fmt.Errorf("warmup setup failed: %v", err) + } + if err := benchmark.run(ctx); err != nil { + return fmt.Errorf("warmup run failed: %v", err) + } + if err := benchmark.cleanup(); err != nil { + return fmt.Errorf("warmup cleanup failed: %v", err) + } + return nil + }) + } + + return warmupGroup.Wait() +} + +// discardBenchmarkResults consumes benchmark results until the provided context +// is cancelled +func discardBenchmarkResults(ctx context.Context) { + results = make(chan benchmarkResult) + + go func() { + for { + select { + case <-ctx.Done(): + close(results) + return + case _, ok := <-results: + if !ok { + return + } + } + } + }() +} From e50ba54a0c887e65dd91e41b4a562c8bd70aeeec Mon Sep 17 00:00:00 2001 From: BrennaEpp Date: Tue, 15 Aug 2023 23:34:34 -0700 Subject: [PATCH 2/5] xml --- storage/internal/benchmarks/w1r3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/internal/benchmarks/w1r3.go b/storage/internal/benchmarks/w1r3.go index f466f657afdb..859474deaa96 100644 --- a/storage/internal/benchmarks/w1r3.go +++ b/storage/internal/benchmarks/w1r3.go @@ -149,7 +149,7 @@ func (r *w1r3) cleanup() error { func (r *w1r3) run(ctx context.Context) error { // Use the same client for write and reads as the api is the same - client := getClient(ctx, r.writeResult.params.api) + client := getClient(ctx, r.readResults[0].params.api) var span trace.Span ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "w1r3") From 673ec3a42d2cfe65cbeb7890d81afc72c9632f2b Mon Sep 17 00:00:00 2001 From: BrennaEpp Date: Wed, 16 Aug 2023 10:39:10 -0700 Subject: [PATCH 3/5] add tracing --- .../benchmarks/directory_benchmark.go | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/storage/internal/benchmarks/directory_benchmark.go b/storage/internal/benchmarks/directory_benchmark.go index 6f7f967532e3..0aca7565cedb 100644 --- a/storage/internal/benchmarks/directory_benchmark.go +++ b/storage/internal/benchmarks/directory_benchmark.go @@ -25,6 +25,9 @@ import ( "time" "cloud.google.com/go/storage" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" "google.golang.org/api/iterator" ) @@ -172,6 +175,13 @@ func (r *directoryBenchmark) cleanup() error { } func (r *directoryBenchmark) uploadDirectory(ctx context.Context, numWorkers int) (elapsedTime time.Duration, err error) { + var span trace.Span + ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "uploadDirectory") + span.SetAttributes( + attribute.KeyValue{"num_workers", attribute.IntValue(numWorkers)}, + ) + defer span.End() + benchGroup, ctx := errgroup.WithContext(ctx) benchGroup.SetLimit(numWorkers) @@ -220,6 +230,13 @@ func (r *directoryBenchmark) uploadDirectory(ctx context.Context, numWorkers int } func (r *directoryBenchmark) downloadDirectory(ctx context.Context, numWorkers int) (elapsedTime time.Duration, err error) { + var span trace.Span + ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "downloadDirectory") + span.SetAttributes( + attribute.KeyValue{"num_workers", attribute.IntValue(numWorkers)}, + ) + defer span.End() + benchGroup, ctx := errgroup.WithContext(ctx) benchGroup.SetLimit(numWorkers) @@ -299,6 +316,13 @@ func (r *directoryBenchmark) downloadDirectory(ctx context.Context, numWorkers i } func (r *directoryBenchmark) run(ctx context.Context) error { + var span trace.Span + ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "directoryBenchmark") + span.SetAttributes( + attribute.KeyValue{"api", attribute.StringValue(string(r.opts.api))}, + attribute.KeyValue{"object_size", attribute.Int64Value(r.opts.objectSize)}) + defer span.End() + // Upload err := runOneOp(ctx, r.writeResult, func() (time.Duration, error) { return r.uploadDirectory(ctx, r.numWorkers) From 920c7adef571f159a124e9fd2cc91da0810c58e1 Mon Sep 17 00:00:00 2001 From: BrennaEpp Date: Thu, 24 Aug 2023 12:40:33 -0700 Subject: [PATCH 4/5] Revert "add tracing" This reverts commit 673ec3a42d2cfe65cbeb7890d81afc72c9632f2b. --- .../benchmarks/directory_benchmark.go | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/storage/internal/benchmarks/directory_benchmark.go b/storage/internal/benchmarks/directory_benchmark.go index 0aca7565cedb..6f7f967532e3 100644 --- a/storage/internal/benchmarks/directory_benchmark.go +++ b/storage/internal/benchmarks/directory_benchmark.go @@ -25,9 +25,6 @@ import ( "time" "cloud.google.com/go/storage" - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" "google.golang.org/api/iterator" ) @@ -175,13 +172,6 @@ func (r *directoryBenchmark) cleanup() error { } func (r *directoryBenchmark) uploadDirectory(ctx context.Context, numWorkers int) (elapsedTime time.Duration, err error) { - var span trace.Span - ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "uploadDirectory") - span.SetAttributes( - attribute.KeyValue{"num_workers", attribute.IntValue(numWorkers)}, - ) - defer span.End() - benchGroup, ctx := errgroup.WithContext(ctx) benchGroup.SetLimit(numWorkers) @@ -230,13 +220,6 @@ func (r *directoryBenchmark) uploadDirectory(ctx context.Context, numWorkers int } func (r *directoryBenchmark) downloadDirectory(ctx context.Context, numWorkers int) (elapsedTime time.Duration, err error) { - var span trace.Span - ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "downloadDirectory") - span.SetAttributes( - attribute.KeyValue{"num_workers", attribute.IntValue(numWorkers)}, - ) - defer span.End() - benchGroup, ctx := errgroup.WithContext(ctx) benchGroup.SetLimit(numWorkers) @@ -316,13 +299,6 @@ func (r *directoryBenchmark) downloadDirectory(ctx context.Context, numWorkers i } func (r *directoryBenchmark) run(ctx context.Context) error { - var span trace.Span - ctx, span = otel.GetTracerProvider().Tracer(tracerName).Start(ctx, "directoryBenchmark") - span.SetAttributes( - attribute.KeyValue{"api", attribute.StringValue(string(r.opts.api))}, - attribute.KeyValue{"object_size", attribute.Int64Value(r.opts.objectSize)}) - defer span.End() - // Upload err := runOneOp(ctx, r.writeResult, func() (time.Duration, error) { return r.uploadDirectory(ctx, r.numWorkers) From 8986b37994357b0dc6bc5e5f200efd90fd1228f6 Mon Sep 17 00:00:00 2001 From: BrennaEpp Date: Mon, 28 Aug 2023 20:43:44 -0500 Subject: [PATCH 5/5] change warmup parallelism to num CPUs --- storage/internal/benchmarks/warmup.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/storage/internal/benchmarks/warmup.go b/storage/internal/benchmarks/warmup.go index d4a7845b1d20..ab289375de6d 100644 --- a/storage/internal/benchmarks/warmup.go +++ b/storage/internal/benchmarks/warmup.go @@ -17,6 +17,7 @@ package main import ( "context" "fmt" + "runtime" "time" "golang.org/x/sync/errgroup" @@ -29,7 +30,7 @@ func warmupW1R3(ctx context.Context, opts *benchmarkOptions) error { discardBenchmarkResults(ctx) warmupGroup, ctx := errgroup.WithContext(ctx) - warmupGroup.SetLimit(opts.numWorkers) + warmupGroup.SetLimit(runtime.NumCPU()) for deadline := time.Now().Add(opts.warmup); time.Now().Before(deadline); { warmupGroup.Go(func() error {