Skip to content

Commit

Permalink
chore(storage): add configurable per op timeout, print on timeout [be…
Browse files Browse the repository at this point in the history
…nchmarking] (#8191)
  • Loading branch information
BrennaEpp authored Jul 7, 2023
1 parent e1f52db commit ed73916
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions storage/internal/benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ This runs 1000 iterations on 512kib to 2Gib files in the background, sending out
| -connection_pool_size | GRPC connection pool size | any positive integer | 4 |
| -force_garbage_collection | whether to force garbage collection <br> before every write or read benchmark | `true` or `false` (present/not present) | `false` |
| -timeout | timeout (maximum time running benchmarks) <br> the program may run for longer while it finishes running processes | any [time.Duration](https://pkg.go.dev/time#Duration) | `1h` |
| -timeout_per_op | timeout on a single upload or download | any [time.Duration](https://pkg.go.dev/time#Duration) | `5m` |
| -workload | `1` will run a w1r3 (write 1 read 3) benchmark <br> `6` will run a benchmark uploading and downloading (once each) <br> a single directory with `-directory_num_objects` number of files (no subdirectories) | `1` or `6` | `1` |
| -directory_num_objects | total number of objects in a directory (directory will only contain files, <br> no subdirectories); only applies to workload 6 | any positive integer | `1000` |

Expand Down
2 changes: 2 additions & 0 deletions storage/internal/benchmarks/directory_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func (r *directoryBenchmark) uploadDirectory(ctx context.Context, numWorkers int
object: objectName,
useDefaultChunkSize: opts.minChunkSize == useDefault || opts.maxChunkSize == useDefault,
objectPath: filePath,
timeout: r.opts.timeoutPerOp,
})
return err
})
Expand Down Expand Up @@ -278,6 +279,7 @@ func (r *directoryBenchmark) downloadDirectory(ctx context.Context, numWorkers i
downloadToDirectory: r.downloadDirectoryPath,
rangeStart: rangeStart,
rangeLength: rangeLength,
timeout: r.opts.timeoutPerOp,
})
return err
})
Expand Down
3 changes: 2 additions & 1 deletion storage/internal/benchmarks/download_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type downloadOpts struct {
rangeStart int64
rangeLength int64
downloadToDirectory string
timeout time.Duration
}

func downloadBenchmark(ctx context.Context, dopts downloadOpts) (elapsedTime time.Duration, rerr error) {
Expand All @@ -45,7 +46,7 @@ func downloadBenchmark(ctx context.Context, dopts downloadOpts) (elapsedTime tim
defer func() { elapsedTime = time.Since(start) }()

// Set additional timeout
ctx, cancel := context.WithTimeout(ctx, time.Minute*2)
ctx, cancel := context.WithTimeout(ctx, dopts.timeout)
defer cancel()

o := dopts.client.Bucket(dopts.bucket).Object(dopts.object)
Expand Down
10 changes: 9 additions & 1 deletion storage/internal/benchmarks/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ type benchmarkOptions struct {
forceGC bool
connPoolSize int

timeout time.Duration
timeout time.Duration
timeoutPerOp time.Duration

continueOnFail bool

Expand Down Expand Up @@ -166,6 +167,7 @@ func parseFlags() {
flag.BoolVar(&opts.forceGC, "force_garbage_collection", false, "force garbage collection at the beginning of each upload")

flag.DurationVar(&opts.timeout, "timeout", time.Hour, "timeout")
flag.DurationVar(&opts.timeoutPerOp, "timeout_per_op", time.Minute*5, "timeout per upload/download")
flag.StringVar(&outputFile, "o", "", "file to output results to - if empty, will output to stdout")

flag.BoolVar(&opts.continueOnFail, "continue_on_fail", false, "continue even if a run fails")
Expand Down Expand Up @@ -209,6 +211,12 @@ func main() {
ctx, cancel := context.WithDeadline(context.Background(), start.Add(opts.timeout))
defer cancel()

// Print a message once deadline is exceeded
go func() {
<-ctx.Done()
log.Printf("total configured timeout exceeded")
}()

// Create bucket if necessary
if len(opts.bucket) < 1 {
opts.bucket = randomName(bucketPrefix)
Expand Down
3 changes: 2 additions & 1 deletion storage/internal/benchmarks/upload_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type uploadOpts struct {
object string
useDefaultChunkSize bool
objectPath string
timeout time.Duration
}

func uploadBenchmark(ctx context.Context, uopts uploadOpts) (elapsedTime time.Duration, rerr error) {
Expand All @@ -50,7 +51,7 @@ func uploadBenchmark(ctx context.Context, uopts uploadOpts) (elapsedTime time.Du
defer func() { elapsedTime = time.Since(start) }()

// Set additional timeout
ctx, cancel := context.WithTimeout(ctx, time.Minute*2)
ctx, cancel := context.WithTimeout(ctx, uopts.timeout)
defer cancel()

// Open file
Expand Down
2 changes: 2 additions & 0 deletions storage/internal/benchmarks/w1r3.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (r *w1r3) run(ctx context.Context) error {
object: r.objectName,
useDefaultChunkSize: opts.minChunkSize == useDefault || opts.maxChunkSize == useDefault,
objectPath: r.objectPath,
timeout: r.opts.timeoutPerOp,
})
})

Expand Down Expand Up @@ -186,6 +187,7 @@ func (r *w1r3) run(ctx context.Context) error {
rangeStart: rangeStart,
rangeLength: rangeLength,
downloadToDirectory: r.directoryPath,
timeout: r.opts.timeoutPerOp,
})
})
if err != nil {
Expand Down

0 comments on commit ed73916

Please sign in to comment.