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

get: Add --range-size to have a random but a defined range pattern #302

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading