Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(storage): add warmup option [benchmarks] #8418

Merged
merged 9 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions storage/internal/benchmarks/directory_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
BrennaEpp marked this conversation as resolved.
Show resolved Hide resolved
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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions storage/internal/benchmarks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ type benchmarkOptions struct {

enableTracing bool
traceSampleRate float64
warmup time.Duration
}

func (b *benchmarkOptions) validate() error {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion storage/internal/benchmarks/w1r3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
72 changes: 72 additions & 0 deletions storage/internal/benchmarks/warmup.go
Original file line number Diff line number Diff line change
@@ -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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I guess this uses the same level of parallelism as was specified for the main workload? I am wondering if it makes more sense to have a fixed/higher level of parallelism, or to be able to specify this separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does; I am open to changing it to a fixed parallelism level - say 16? I think being able to specify this separately may create unnecessary confusion - unless we determine it would be beneficial to have different levels of parallelism for warmups for different workloads, in which case we can always add this in.

The way it is now gives consistency in terms of bucket traffic: the bucket always sees the same level of parallelism; but ultimately for the long term a fixed parallelism makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think 16 (or numCPUs) is appropriate. We could make it configurable if/when we refactor all the CLI opts into some kind of config file eventually...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - I changed it to num cpus


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
}
}
}
}()
}