Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use smaller per part size to use lower memory #3935

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pkg/objstore/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ var DefaultConfig = Config{
MaxIdleConnsPerHost: 100,
MaxConnsPerHost: 0,
},
// Minimum file size after which an HTTP multipart request should be used to upload objects to storage.
// Set to 128 MiB as in the minio client.
PartSize: 1024 * 1024 * 128,
// TODO(bwplotka): This means 32MB will be always allocated for every Upload.
// See: https://github.com/thanos-io/thanos/issues/3917
PartSize: 1024 * 1024 * 8, // 8MB.
}

// Config stores the configuration for s3 bucket.
Expand All @@ -84,7 +84,7 @@ type Config struct {
HTTPConfig HTTPConfig `yaml:"http_config"`
TraceConfig TraceConfig `yaml:"trace"`
ListObjectsVersion string `yaml:"list_objects_version"`
// PartSize used for multipart upload. Only used if uploaded object size is known and larger than configured PartSize.
// PartSize used for multipart upload. Only used if uploaded object size is known and 4x larger than configured PartSize.
PartSize uint64 `yaml:"part_size"`
SSEConfig SSEConfig `yaml:"sse_config"`
}
Expand Down Expand Up @@ -449,9 +449,8 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {
size = -1
}

// partSize cannot be larger than object size.
partSize := b.partSize
if size < int64(partSize) {
if size < 4*int64(partSize) {
partSize = 0
}
if _, err := b.client.PutObject(
Expand All @@ -461,6 +460,7 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {
r,
size,
minio.PutObjectOptions{
NumThreads: 4, // Minio default.
PartSize: partSize,
ServerSideEncryption: sse,
UserMetadata: b.putUserMetadata,
Expand Down
55 changes: 55 additions & 0 deletions pkg/objstore/s3/s3_e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package s3_test

import (
"bytes"
"context"
"strings"
"testing"

"github.com/cortexproject/cortex/integration/e2e"
e2edb "github.com/cortexproject/cortex/integration/e2e/db"
"github.com/go-kit/kit/log"
"github.com/thanos-io/thanos/pkg/objstore/s3"
"github.com/thanos-io/thanos/test/e2e/e2ethanos"

"github.com/thanos-io/thanos/pkg/testutil"
)

// Regression benchmark for https://github.com/thanos-io/thanos/issues/3917.
func BenchmarkUpload(b *testing.B) {
b.ReportAllocs()
ctx := context.Background()

s, err := e2e.NewScenario("e2e_bench_mino_client")
testutil.Ok(b, err)
b.Cleanup(e2ethanos.CleanScenario(b, s))

const bucket = "test"
m := e2edb.NewMinio(8080, bucket)
testutil.Ok(b, s.StartAndWaitReady(m))

bkt, err := s3.NewBucketWithConfig(log.NewNopLogger(), s3.Config{
Bucket: bucket,
AccessKey: e2edb.MinioAccessKey,
SecretKey: e2edb.MinioSecretKey,
Endpoint: m.HTTPEndpoint(),
Insecure: true,
}, "test-feed")
testutil.Ok(b, err)

buf := bytes.Buffer{}
buf.Grow(1028 * 1028 * 100) // 100MB.
word := "abcdefghij"
for i := 0; i < buf.Cap()/len(word); i++ {
_, _ = buf.WriteString(word)
}
str := buf.String()

b.ResetTimer()
for i := 0; i < b.N; i++ {
testutil.Ok(b, bkt.Upload(ctx, "test", strings.NewReader(str)))
}
}
2 changes: 1 addition & 1 deletion test/e2e/e2ethanos/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/thanos-io/thanos/pkg/testutil"
)

func CleanScenario(t *testing.T, s *e2e.Scenario) func() {
func CleanScenario(t testing.TB, s *e2e.Scenario) func() {
return func() {
// Make sure Clean can properly delete everything.
testutil.Ok(t, exec.Command("chmod", "-R", "777", s.SharedDir()).Run())
Expand Down