Skip to content

Commit

Permalink
get: Add --range-size to have a random but a defined range pattern
Browse files Browse the repository at this point in the history
--range-size will create a random offset but with a fixed range
  • Loading branch information
Anis Eleuch committed Jul 11, 2024
1 parent 9e01ed3 commit 30d35d1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 16 additions & 1 deletion cli/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
15 changes: 11 additions & 4 deletions pkg/bench/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type Get struct {
CreateObjects int
Versions int
RandomRanges bool
RangeSize int64
ListExisting bool
ListFlat bool
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 30d35d1

Please sign in to comment.