aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2021-09-10 17:28:08 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2021-09-10 17:28:08 +0200
commit93631b4e3d5195d446504db1c4a2bc7468b3ef28 (patch)
tree3f4a3d8c91d5d998dbbdce64fbb71cfc5c076b10
parent4982bdd83988d8521b1163cf5070bedf968ddb15 (diff)
downloadbagage-93631b4e3d5195d446504db1c4a2bc7468b3ef28.tar.gz
bagage-93631b4e3d5195d446504db1c4a2bc7468b3ef28.zip
Change part size to fix memory leak
-rw-r--r--.gitignore1
-rw-r--r--s3_file.go11
2 files changed, 11 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 9b6940b..76cf493 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
bagage
+.env
diff --git a/s3_file.go b/s3_file.go
index a72397e..bbcfc8a 100644
--- a/s3_file.go
+++ b/s3_file.go
@@ -98,7 +98,16 @@ func (f *S3File) Write(p []byte) (n int, err error) {
contentType := mime.TypeByExtension(path.Ext(f.path.key))
go func() {
- _, err := f.fs.mc.PutObject(context.Background(), f.path.bucket, f.path.key, r, -1, minio.PutObjectOptions{ContentType: contentType})
+ /* @FIXME
+ PutObject has a strange behaviour when used with unknown size, it supposes the final size will be 5TiB.
+ Then it computes that, following the final size of the file, each part of the multipart upload should be 512MiB, which leads to big allocations.
+ The culprit is OptimalPartInfo: https://github.com/minio/minio-go/blob/62beca8cd87e9960d88793320220ad2c159bb5e5/api-put-object-common.go#L70
+ We set this value to the minimum allowed one, 5MiB.
+ The minimum value is set here: https://github.com/minio/minio-go/blob/62beca8cd87e9960d88793320220ad2c159bb5e5/constants.go#L24
+ Because Multipart uploads seems to be limited to 10 000 parts, it might be possible that we are limited to 50 GiB files, which is still good enough.
+ Ref: https://github.com/minio/minio-go/blob/62beca8cd87e9960d88793320220ad2c159bb5e5/api-put-object-common.go#L110-L112
+ */
+ _, err := f.fs.mc.PutObject(context.Background(), f.path.bucket, f.path.key, r, -1, minio.PutObjectOptions{ContentType: contentType, PartSize: 5*1024*1024})
f.donew <- err
}()
}