From 30d35d1c74bec8d0b0ecb5b70d7a92b763a0053c Mon Sep 17 00:00:00 2001 From: Anis Eleuch Date: Wed, 6 Mar 2024 10:37:04 +0100 Subject: [PATCH] get: Add --range-size to have a random but a defined range pattern --range-size will create a random offset but with a fixed range --- cli/get.go | 17 ++++++++++++++++- pkg/bench/get.go | 15 +++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cli/get.go b/cli/get.go index 0e5f6fc..318edde 100644 --- a/cli/get.go +++ b/cli/get.go @@ -53,6 +53,10 @@ var getFlags = []cli.Flag{ Name: "range", Usage: "Do ranged get operations. Will request with random offset and length.", }, + cli.StringFlag{ + Name: "range-size", + Usage: "Use a fixed range size while doing random range offsets, --range is implied", + }, cli.IntFlag{ Name: "versions", Value: 1, @@ -81,11 +85,22 @@ FLAGS: // mainGet is the entry point for get command. func mainGet(ctx *cli.Context) error { checkGetSyntax(ctx) + + var rangeSize int64 + if rs := ctx.String("range-size"); rs != "" { + s, err := toSize(rs) + if err != nil { + return err + } + rangeSize = int64(s) + } + sse := newSSE(ctx) b := bench.Get{ Common: getCommon(ctx, newGenSource(ctx, "obj.size")), Versions: ctx.Int("versions"), - RandomRanges: ctx.Bool("range"), + RandomRanges: ctx.Bool("range") || ctx.IsSet("range-size"), + RangeSize: rangeSize, CreateObjects: ctx.Int("objects"), GetOpts: minio.GetObjectOptions{ServerSideEncryption: sse}, ListExisting: ctx.Bool("list-existing"), diff --git a/pkg/bench/get.go b/pkg/bench/get.go index e8c6ad3..3a1345d 100644 --- a/pkg/bench/get.go +++ b/pkg/bench/get.go @@ -43,6 +43,7 @@ type Get struct { CreateObjects int Versions int RandomRanges bool + RangeSize int64 ListExisting bool ListFlat bool } @@ -288,10 +289,16 @@ func (g *Get) Start(ctx context.Context, wait chan struct{}) (Operations, error) } if g.RandomRanges && op.Size > 2 { - // Randomize length similar to --obj.randsize - size := generator.GetExpRandSize(rng, 0, op.Size-2) - start := rng.Int63n(op.Size - size) - end := start + size + var start, end int64 + if g.RangeSize <= 0 { + // Randomize length similar to --obj.randsize + size := generator.GetExpRandSize(rng, 0, op.Size-2) + start = rng.Int63n(op.Size - size) + end = start + size + } else { + start = rng.Int63n(op.Size - g.RangeSize) + end = start + g.RangeSize - 1 + } op.Size = end - start + 1 opts.SetRange(start, end) }