Create/Delete Bucket

main
Quentin 6 months ago
parent 0aaae1782a
commit a0bc80bcb4
Signed by: quentin
GPG Key ID: E9602264D639FF68
  1. 11
      README.md
  2. 5
      go.mod
  3. 36
      main.go

@ -8,23 +8,14 @@ go get git.deuxfleurs.fr/quentin/s3lat@latest
## usage
with minio:
```
```bash
export ENDPOINT=[fc00:9a7a:9e::1]:9000
export AWS_ACCESS_KEY_ID=minioadmin
export AWS_SECRET_ACCESS_KEY=minioadmin
mc alias set minio-bench http://$ENDPOINT $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY
mc mb minio-bench/bench1
s3lat
```
## todo
create bucket from s3lat
## see also
- https://git.deuxfleurs.fr/quentin/benchmarks

@ -2,4 +2,7 @@ module git.deuxfleurs.fr/quentin/s3lat
go 1.16
require github.com/minio/minio-go/v7 v7.0.16
require (
github.com/google/uuid v1.1.1
github.com/minio/minio-go/v7 v7.0.16
)

@ -15,15 +15,13 @@ import (
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/google/uuid"
)
// alias grg='sudo python3 main.py run dc1:dc1s1 garage -c /tmp/../tmp/garage-testnet/dc1/dc1s1/garage.toml'
// grg key new --name bench
// for i in $(seq 1 10); do grg bucket create bench$i; grg bucket allow --read --write bench$i --key bench; done
func main() {
fmt.Printf("endpoint,nanoseconds\n")
// Initial setup
_, isSSL := os.LookupEnv("SSL");
opts := minio.Options {
Creds: credentials.NewStaticV4(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), ""),
@ -45,6 +43,15 @@ func main() {
return
}
// Create Bucket
buck := uuid.New().String()
err = mc.MakeBucket(context.Background(), buck, minio.MakeBucketOptions{ })
if err != nil {
log.Fatal(err)
return
}
// List Buckets
for i := 0; i < 100; i++ {
start := time.Now()
_, err := mc.ListBuckets(context.Background())
@ -56,11 +63,12 @@ func main() {
fmt.Printf("listbuckets,%v\n", elapsed.Nanoseconds())
}
// PutObject
for i := 0; i < 100; i++ {
istr := strconv.Itoa(i)
content := istr + " hello world " + istr
start := time.Now()
_, err := mc.PutObject(context.Background(), "bench1", "element"+istr, strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType:"application/octet-stream"})
_, err := mc.PutObject(context.Background(), buck, "element"+istr, strings.NewReader(content), int64(len(content)), minio.PutObjectOptions{ContentType:"application/octet-stream"})
elapsed := time.Since(start)
if err != nil {
log.Fatal("failed putObject: ",err)
@ -69,12 +77,13 @@ func main() {
fmt.Printf("putobject,%v\n", elapsed.Nanoseconds())
}
// ListObject
for i := 0; i < 100; i++ {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
start := time.Now()
objectCh := mc.ListObjects(ctx, "bench1", minio.ListObjectsOptions{
objectCh := mc.ListObjects(ctx, buck, minio.ListObjectsOptions{
Recursive: true,
})
for object := range objectCh {
@ -87,10 +96,11 @@ func main() {
fmt.Printf("listobjects,%v\n", elapsed.Nanoseconds())
}
// GetObject
for i := 0; i < 100; i++ {
istr := strconv.Itoa(i)
start := time.Now()
object, err := mc.GetObject(context.Background(), "bench1", "element"+istr, minio.GetObjectOptions{})
object, err := mc.GetObject(context.Background(), buck, "element"+istr, minio.GetObjectOptions{})
if err != nil {
log.Fatal(err)
return
@ -103,10 +113,11 @@ func main() {
fmt.Printf("getobject,%v\n", elapsed.Nanoseconds())
}
// RemoveObject
for i := 0; i < 100; i++ {
istr := strconv.Itoa(i)
start := time.Now()
err = mc.RemoveObject(context.Background(), "bench1", "element"+istr, minio.RemoveObjectOptions{})
err = mc.RemoveObject(context.Background(), buck, "element"+istr, minio.RemoveObjectOptions{})
elapsed := time.Since(start)
if err != nil {
log.Fatal(err)
@ -114,4 +125,11 @@ func main() {
}
fmt.Printf("removeobject,%v\n", elapsed.Nanoseconds())
}
// RemoveBucket
err = mc.RemoveBucket(context.Background(), buck)
if err != nil {
log.Fatal(err)
return
}
}

Loading…
Cancel
Save