|
| 1 | +// Copyright (c) The Thanos Authors. |
| 2 | +// Licensed under the Apache License 2.0. |
| 3 | + |
| 4 | +package s3_test |
| 5 | + |
| 6 | +import ( |
| 7 | + "bytes" |
| 8 | + "context" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | + |
| 12 | + "github.com/cortexproject/cortex/integration/e2e" |
| 13 | + e2edb "github.com/cortexproject/cortex/integration/e2e/db" |
| 14 | + "github.com/go-kit/kit/log" |
| 15 | + "github.com/thanos-io/thanos/pkg/objstore/s3" |
| 16 | + "github.com/thanos-io/thanos/test/e2e/e2ethanos" |
| 17 | + |
| 18 | + "github.com/thanos-io/thanos/pkg/testutil" |
| 19 | +) |
| 20 | + |
| 21 | +// Regression benchmark for https://github.com/thanos-io/thanos/issues/3917. |
| 22 | +func BenchmarkUpload(b *testing.B) { |
| 23 | + b.ReportAllocs() |
| 24 | + ctx := context.Background() |
| 25 | + |
| 26 | + s, err := e2e.NewScenario("e2e_bench_mino_client") |
| 27 | + testutil.Ok(b, err) |
| 28 | + b.Cleanup(e2ethanos.CleanScenario(b, s)) |
| 29 | + |
| 30 | + const bucket = "test" |
| 31 | + m := e2edb.NewMinio(8080, bucket) |
| 32 | + testutil.Ok(b, s.StartAndWaitReady(m)) |
| 33 | + |
| 34 | + bkt, err := s3.NewBucketWithConfig(log.NewNopLogger(), s3.Config{ |
| 35 | + Bucket: bucket, |
| 36 | + AccessKey: e2edb.MinioAccessKey, |
| 37 | + SecretKey: e2edb.MinioSecretKey, |
| 38 | + Endpoint: m.HTTPEndpoint(), |
| 39 | + Insecure: true, |
| 40 | + }, "test-feed") |
| 41 | + testutil.Ok(b, err) |
| 42 | + |
| 43 | + buf := bytes.Buffer{} |
| 44 | + buf.Grow(1028 * 1028 * 100) // 100MB. |
| 45 | + word := "abcdefghij" |
| 46 | + for i := 0; i < buf.Cap()/len(word); i++ { |
| 47 | + _, _ = buf.WriteString(word) |
| 48 | + } |
| 49 | + str := buf.String() |
| 50 | + |
| 51 | + b.ResetTimer() |
| 52 | + for i := 0; i < b.N; i++ { |
| 53 | + testutil.Ok(b, bkt.Upload(ctx, "test", strings.NewReader(str))) |
| 54 | + } |
| 55 | +} |
0 commit comments