aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/s3lat/main.go
blob: 32b03cfa72e7132814221949285cdddd3493d280 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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"
    "github.com/google/uuid"
)

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"), ""),
		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
	}

    // 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())
		elapsed := time.Since(start)
		if err != nil {
			log.Fatal("failed listbucket: ", err)
		return
		}
		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(), 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)
			return
		}
		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, buck, 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())
	}

    // GetObject
	for i := 0; i < 100; i++ {
		istr := strconv.Itoa(i)
		start := time.Now()
		object, err := mc.GetObject(context.Background(), buck, "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())
	}

    // RemoveObject
	for i := 0; i < 100; i++ {
		istr := strconv.Itoa(i)
		start := time.Now()
		err = mc.RemoveObject(context.Background(), buck, "element"+istr, minio.RemoveObjectOptions{})
		elapsed := time.Since(start)
		if err != nil {
			log.Fatal(err)
			return
		}
		fmt.Printf("removeobject,%v\n", elapsed.Nanoseconds())
	}

    // RemoveBucket
    err = mc.RemoveBucket(context.Background(), buck)
    if err != nil {
        log.Fatal(err)
        return
    }
}