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

[delete] bench object from listing the bucket #290

Merged
merged 2 commits into from
Feb 26, 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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,18 @@ It is possible by forcing md5 checksums on data by using the `--md5` option.

## DELETE

Benchmarking delete operations will upload `--objects` objects of size `--obj.size` and attempt to
delete as many it can within `--duration`.
Benchmarking delete operations will attempt to delete as many objects it can within `--duration`.

By default, `--objects` objects of size `--obj.size` are uploaded beforing doin the actual bench.

The delete operations are done in `--batch` objects per request in `--concurrent` concurrently running requests.

If there are no more objects left the benchmark will end.

Using `--list-existing` will list at most `--objects` from the bucket and delete them instead of
deleting random objects (set it to 0 to use all objects from the lsiting).
Listing is restricted to `--prefix` if it is set and recursive listing can be disabled by setting `--list-flat`.

The analysis will include the upload stats as `PUT` operations and the `DELETE` operations.

```
Expand Down
11 changes: 11 additions & 0 deletions cli/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ var deleteFlags = []cli.Flag{
Value: 100,
Usage: "Number of DELETE operations per batch.",
},
cli.BoolFlag{
Name: "list-existing",
Usage: "Instead of preparing the bench by PUTing some objects, only use objects already in the bucket",
},
cli.BoolFlag{
Name: "list-flat",
Usage: "When using --list-existing, do not use recursive listing",
},
}

var deleteCmd = cli.Command{
Expand Down Expand Up @@ -68,6 +76,9 @@ func mainDelete(ctx *cli.Context) error {
Common: getCommon(ctx, newGenSource(ctx, "obj.size")),
CreateObjects: ctx.Int("objects"),
BatchSize: ctx.Int("batch"),
ListExisting: ctx.Bool("list-existing"),
ListFlat: ctx.Bool("list-flat"),
ListPrefix: ctx.String("prefix"),
}
return runBench(ctx, &b)
}
Expand Down
60 changes: 58 additions & 2 deletions pkg/bench/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,68 @@ type Delete struct {

CreateObjects int
BatchSize int
ListExisting bool
ListFlat bool
ListPrefix string
}

// Prepare will create an empty bucket or delete any content already there
// and upload a number of objects.
func (d *Delete) Prepare(ctx context.Context) error {
var groupErr error

// prepare the bench by listing object from the bucket
if d.ListExisting {
cl, done := d.Client()

// ensure the bucket exist
found, err := cl.BucketExists(ctx, d.Bucket)
if err != nil {
return err
}
if !found {
return fmt.Errorf("bucket %s does not exist and --list-existing has been set", d.Bucket)
}

// list all objects
ctx, cancel := context.WithCancel(ctx)
defer cancel()
objectCh := cl.ListObjects(ctx, d.Bucket, minio.ListObjectsOptions{
Prefix: d.ListPrefix,
Recursive: !d.ListFlat,
})

for object := range objectCh {
if object.Err != nil {
return object.Err
}
obj := generator.Object{
Name: object.Key,
Size: object.Size,
}

d.objects = append(d.objects, obj)

// limit to ListingMaxObjects
if d.CreateObjects > 0 && len(d.objects) >= d.CreateObjects {
break
}
}
if len(d.objects) == 0 {
return (fmt.Errorf("no objects found for bucket %s", d.Bucket))
}
done()
d.Collector = NewCollector()

// Shuffle objects.
// Benchmark will pick from slice in order.
a := d.objects
rand.Shuffle(len(a), func(i, j int) {
a[i], a[j] = a[j], a[i]
})
return groupErr
}

if err := d.createEmptyBucket(ctx); err != nil {
return err
}
Expand All @@ -57,7 +114,6 @@ func (d *Delete) Prepare(ctx context.Context) error {
}
close(obj)
var mu sync.Mutex
var groupErr error
for i := 0; i < d.Concurrency; i++ {
go func(i int) {
defer wg.Done()
Expand Down Expand Up @@ -227,7 +283,7 @@ func (d *Delete) Start(ctx context.Context, wait chan struct{}) (Operations, err

// Cleanup deletes everything uploaded to the bucket.
func (d *Delete) Cleanup(ctx context.Context) {
if len(d.objects) > 0 {
if len(d.objects) > 0 && !d.ListExisting {
d.deleteAllInBucket(ctx, d.objects.Prefixes()...)
}
}
Loading