@@ -2,6 +2,7 @@ package mio
22
33import (
44 "context"
5+ "flag"
56 "io"
67 "net/url"
78 "path"
@@ -14,6 +15,7 @@ import (
1415 "github.com/testcontainers/testcontainers-go"
1516 tcminio "github.com/testcontainers/testcontainers-go/modules/minio"
1617
18+ "github.com/percona/percona-backup-mongodb/pbm/log"
1719 "github.com/percona/percona-backup-mongodb/pbm/storage"
1820)
1921
@@ -256,12 +258,15 @@ func (r *InfiniteCustomReader) Read(p []byte) (int, error) {
256258 return readLen , nil
257259}
258260
259- func BenchmarkMinioUpload (b * testing.B ) {
260- fsize := int64 (500 * 1024 * 1024 )
261+ var (
262+ fileSize = flag .Int64 ("file-size" , 500 , "file size in MB that will be uploaded" )
263+ partSize = flag .Int64 ("part-size" , 10 , "part size in MB that will be used to upload file" )
264+ )
265+
266+ func BenchmarkMinioPutObject (b * testing.B ) {
261267 numThreds := uint (max (runtime .GOMAXPROCS (0 ), 1 ))
262- partSize := uint64 (defaultPartSize )
263- // partSize := uint64(50 * 1024 * 1024)
264- // partSize := uint64(100 * 1024 * 1024)
268+ fsize := * fileSize * 1024 * 1024
269+ pSize := * partSize * 1024 * 1024
265270
266271 ep := "s3.amazonaws.com"
267272 region := "eu-central-1"
@@ -278,8 +283,8 @@ func BenchmarkMinioUpload(b *testing.B) {
278283 if err != nil {
279284 b .Fatalf ("minio client creation for aws: %v" , err )
280285 }
281- b .Logf ("minio client: file size=%d bytes ; part size=%d bytes ; NumThreads=%d" ,
282- fsize , partSize , numThreds )
286+ b .Logf ("minio client: file size=%s ; part size=%s ; NumThreads=%d" ,
287+ storage . PrettySize ( fsize ), storage . PrettySize ( pSize ) , numThreds )
283288
284289 b .ResetTimer ()
285290 b .SetBytes (fsize )
@@ -293,7 +298,7 @@ func BenchmarkMinioUpload(b *testing.B) {
293298 b .Logf ("uploading file: %s ...." , fname )
294299
295300 putOpts := minio.PutObjectOptions {
296- PartSize : partSize ,
301+ PartSize : uint64 ( pSize ) ,
297302 NumThreads : numThreds ,
298303 }
299304
@@ -311,3 +316,47 @@ func BenchmarkMinioUpload(b *testing.B) {
311316 }
312317 }
313318}
319+
320+ func BenchmarkMinioStorageSave (b * testing.B ) {
321+ numThreds := uint (max (runtime .GOMAXPROCS (0 ), 1 ))
322+ fsize := * fileSize * 1024 * 1024
323+ pSize := * partSize * 1024 * 1024
324+
325+ cfg := & Config {
326+ Endpoint : "s3.amazonaws.com" ,
327+ Region : "eu-central-1" ,
328+ Bucket : "" ,
329+ Prefix : "" ,
330+ Credentials : Credentials {
331+ AccessKeyID : "" ,
332+ SecretAccessKey : "" ,
333+ },
334+ PartSize : pSize ,
335+ }
336+
337+ s , err := New (cfg , "" , log .DiscardEvent )
338+ if err != nil {
339+ b .Fatalf ("minio storage creation: %v" , err )
340+ }
341+ b .Logf ("minio client: file size=%s; part size=%s; NumThreads=%d" ,
342+ storage .PrettySize (fsize ), storage .PrettySize (pSize ), numThreds )
343+
344+ b .ResetTimer ()
345+ b .SetBytes (fsize )
346+
347+ for b .Loop () {
348+ b .StopTimer ()
349+
350+ infR := NewInfiniteCustomReader ()
351+ r := io .LimitReader (infR , fsize )
352+
353+ fname := time .Now ().Format ("2006-01-02T15:04:05" )
354+ b .Logf ("saving file: %s ...." , fname )
355+
356+ b .StartTimer ()
357+ err := s .Save (fname , r )
358+ if err != nil {
359+ b .Fatalf ("save %s: %v" , fname , err )
360+ }
361+ }
362+ }
0 commit comments