From f0db8ba560c882d3fe297b5433acc128dc2d9343 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Wed, 14 Sep 2022 18:22:46 +0200 Subject: Scenario based benchmarks will be ready soon --- benchmarks/s3concurrent/.gitignore | 1 + benchmarks/s3concurrent/main.go | 167 +++++++++++++++++++------------------ 2 files changed, 85 insertions(+), 83 deletions(-) create mode 100644 benchmarks/s3concurrent/.gitignore (limited to 'benchmarks/s3concurrent') diff --git a/benchmarks/s3concurrent/.gitignore b/benchmarks/s3concurrent/.gitignore new file mode 100644 index 0000000..22189b7 --- /dev/null +++ b/benchmarks/s3concurrent/.gitignore @@ -0,0 +1 @@ +s3concurrent diff --git a/benchmarks/s3concurrent/main.go b/benchmarks/s3concurrent/main.go index a67fc5b..9f7f3af 100644 --- a/benchmarks/s3concurrent/main.go +++ b/benchmarks/s3concurrent/main.go @@ -1,17 +1,17 @@ package main import ( - "context" - "crypto/tls" - "io" - "log" - "math/rand" - "net/http" - "os" - + "context" + "crypto/tls" + "io" + "log" + "math/rand" + "net/http" + "os" + + "github.com/google/uuid" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" - "github.com/google/uuid" ) func buildMc() (*minio.Client, error) { @@ -30,92 +30,93 @@ func buildMc() (*minio.Client, error) { } mc, err := minio.New(os.Getenv("ENDPOINT"), &opts) - return mc, err + return mc, err } -type PRNG struct { - rem int64 +type PRNG struct { + rem int64 } -func (r *PRNG) Read(p []byte) (n int, err error) { - //log.Printf("rem=%d, buf=%d\n", r.rem, len(p)) - if int64(len(p)) > r.rem { - p = p[:r.rem] - } - - if int64(len(p)) > r.rem { - log.Fatal("LOGIC ERROR") - } - - n, err = rand.Read(p) - if err != nil { - return - } - r.rem -= int64(n) - if r.rem <= 0 { - err = io.EOF - //log.Printf("PRNG file has been fully read. rem=%d,n=%d,err=%s\n", r.rem, n, err) - } - return + +func (r *PRNG) Read(p []byte) (n int, err error) { + //log.Printf("rem=%d, buf=%d\n", r.rem, len(p)) + if int64(len(p)) > r.rem { + p = p[:r.rem] + } + + if int64(len(p)) > r.rem { + log.Fatal("LOGIC ERROR") + } + + n, err = rand.Read(p) + if err != nil { + return + } + r.rem -= int64(n) + if r.rem <= 0 { + err = io.EOF + //log.Printf("PRNG file has been fully read. rem=%d,n=%d,err=%s\n", r.rem, n, err) + } + return } func putObj(buck string, size int64) error { - mc, err := buildMc() - if err != nil { - return err - } - - prng := new(PRNG) - prng.rem = size - - key := uuid.New().String() - - _, err = mc.PutObject( - context.Background(), - buck, - key, - prng, - size, - minio.PutObjectOptions{ContentType:"application/octet-stream"}, - ) - - return err + mc, err := buildMc() + if err != nil { + return err + } + + prng := new(PRNG) + prng.rem = size + + key := uuid.New().String() + + _, err = mc.PutObject( + context.Background(), + buck, + key, + prng, + size, + minio.PutObjectOptions{ContentType: "application/octet-stream"}, + ) + + return err } func main() { - minio.MaxRetry = 1 - mc, err := buildMc() + minio.MaxRetry = 1 + mc, err := buildMc() if err != nil { log.Fatal("failed connect", err) return } - // Create Bucket - buck := uuid.New().String() - err = mc.MakeBucket(context.Background(), buck, minio.MakeBucketOptions{ }) - if err != nil { - log.Fatal(err) - return - } - log.Printf("created bucket %s\n", buck) - - // Send to bucket - for i := 1; i <= 16; i++ { - log.Printf("start concurrent loop with %d coroutines\n", i) - syn := make(chan error) - for j := 1; j <= i; j++ { - go func() { - syn <- putObj(buck, 1024 * 1024) - }() - } - - for j := 1; j <= i; j++ { - cerr := <-syn - if cerr != nil { - log.Printf("%d/%d failed with %s\n", j, i, cerr) - } - } - log.Printf("done, %d coroutines returned\n", i) - } - - log.Println("done") + // Create Bucket + buck := uuid.New().String() + err = mc.MakeBucket(context.Background(), buck, minio.MakeBucketOptions{}) + if err != nil { + log.Fatal(err) + return + } + log.Printf("created bucket %s\n", buck) + + // Send to bucket + for i := 1; i <= 16; i++ { + log.Printf("start concurrent loop with %d coroutines\n", i) + syn := make(chan error) + for j := 1; j <= i; j++ { + go func() { + syn <- putObj(buck, 1024*1024) + }() + } + + for j := 1; j <= i; j++ { + cerr := <-syn + if cerr != nil { + log.Printf("%d/%d failed with %s\n", j, i, cerr) + } + } + log.Printf("done, %d coroutines returned\n", i) + } + + log.Println("done") } -- cgit v1.2.3