You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
2.9 KiB

package main
import (
"context"
"log"
"os"
"fmt"
"time"
"io"
"io/ioutil"
"strings"
"net/http"
"crypto/tls"
"strconv"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
// 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")
_, isSSL := os.LookupEnv("SSL");
opts := minio.Options {
Creds: credentials.NewStaticV4(os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"), ""),
Secure: isSSL,
}
if region, ok := os.LookupEnv("REGION"); ok {
opts.Region = region
}
if _, ok := os.LookupEnv("SSL_INSECURE"); ok {
opts.Transport = &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}
}
mc, err := minio.New(os.Getenv("ENDPOINT"), &opts)
if err != nil {
log.Fatal("failed connect", err)
return
}
for i := 0; i < 100; i++ {
start := time.Now()
_, err := mc.ListBuckets(context.Background())
elapsed := time.Since(start)
if err != nil {
log.Fatal("failed listbucket: ", err)
return
}
fmt.Printf("listbuckets,%v\n", elapsed.Nanoseconds())
}
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"})
elapsed := time.Since(start)
if err != nil {
log.Fatal("failed putObject: ",err)
return
}
fmt.Printf("putobject,%v\n", elapsed.Nanoseconds())
}
for i := 0; i < 100; i++ {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
start := time.Now()
objectCh := mc.ListObjects(ctx, "bench1", minio.ListObjectsOptions{
Recursive: true,
})
for object := range objectCh {
if object.Err != nil {
log.Fatal(object.Err)
return
}
}
elapsed := time.Since(start)
fmt.Printf("listobjects,%v\n", elapsed.Nanoseconds())
}
for i := 0; i < 100; i++ {
istr := strconv.Itoa(i)
start := time.Now()
object, err := mc.GetObject(context.Background(), "bench1", "element"+istr, minio.GetObjectOptions{})
if err != nil {
log.Fatal(err)
return
}
if _, err = io.Copy(ioutil.Discard, object) ; err != nil {
log.Fatal("failed getobject: ", err)
return
}
elapsed := time.Since(start)
fmt.Printf("getobject,%v\n", elapsed.Nanoseconds())
}
for i := 0; i < 100; i++ {
istr := strconv.Itoa(i)
start := time.Now()
err = mc.RemoveObject(context.Background(), "bench1", "element"+istr, minio.RemoveObjectOptions{})
elapsed := time.Since(start)
if err != nil {
log.Fatal(err)
return
}
fmt.Printf("removeobject,%v\n", elapsed.Nanoseconds())
}
}