Skip to content

Commit f86b7c0

Browse files
Enable ConcurrentStreamParts option and add detailed timing to S3/MinIO benchmarks
1 parent 725e716 commit f86b7c0

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

pbm/storage/mio/minio.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (m *Minio) Save(name string, data io.Reader, options ...storage.Option) err
183183
putOpts := minio.PutObjectOptions{
184184
PartSize: uint64(partSize),
185185
NumThreads: uint(max(runtime.NumCPU()/2, 1)),
186+
ConcurrentStreamParts: true,
186187
}
187188
_, err := m.cl.PutObject(
188189
context.Background(),

pbm/storage/mio/minio_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ go test ./pbm/storage/mio -bench=BenchmarkMinioPutObject -run=^$ -v \
275275
-part-size=100
276276
*/
277277
func BenchmarkMinioPutObject(b *testing.B) {
278+
var uploadTimes []time.Duration
278279
numThreds := uint(max(runtime.GOMAXPROCS(0), 1))
279280
fsize := *fileSize * 1024 * 1024
280281
pSize := *partSize * 1024 * 1024
@@ -306,14 +307,15 @@ func BenchmarkMinioPutObject(b *testing.B) {
306307
r := io.LimitReader(infR, fsize)
307308

308309
fname := time.Now().Format("2006-01-02T15:04:05")
309-
b.Logf("uploading file: %s ....", fname)
310310

311311
putOpts := minio.PutObjectOptions{
312312
PartSize: uint64(pSize),
313313
NumThreads: numThreds,
314+
ConcurrentStreamParts: true,
314315
}
315316

316317
b.StartTimer()
318+
startTime := time.Now()
317319
_, err = mc.PutObject(
318320
context.Background(),
319321
bucket,
@@ -322,10 +324,22 @@ func BenchmarkMinioPutObject(b *testing.B) {
322324
-1,
323325
putOpts,
324326
)
327+
uploadDuration := time.Since(startTime)
328+
uploadTimes = append(uploadTimes, uploadDuration)
329+
b.Logf("uploading file: %s, completed in: %v", fname, uploadDuration)
325330
if err != nil {
326331
b.Fatalf("put object: %v", err)
327332
}
328333
}
334+
335+
if len(uploadTimes) > 0 {
336+
var totalDuration time.Duration
337+
for _, duration := range uploadTimes {
338+
totalDuration += duration
339+
}
340+
averageTime := totalDuration / time.Duration(len(uploadTimes))
341+
b.Logf("average upload time: %v", averageTime)
342+
}
329343
}
330344

331345
// BenchmarkMinioStorageSave measures the performance of uploading file on the

pbm/storage/s3/s3_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ go test ./pbm/storage/s3 -bench=BenchmarkS3Upload -run=^$ -v \
264264
-part-size=100
265265
*/
266266
func BenchmarkS3Upload(b *testing.B) {
267+
var uploadTimes []time.Duration
267268
numThreds := max(runtime.GOMAXPROCS(0), 1)
268269
fsize := *fileSize * 1024 * 1024
269270
pSize := *partSize * 1024 * 1024
@@ -289,6 +290,7 @@ func BenchmarkS3Upload(b *testing.B) {
289290
b.Logf("aws s3 client: file size=%s; part size=%s; NumThreads=%d",
290291
storage.PrettySize(fsize), storage.PrettySize(pSize), numThreds)
291292

293+
292294
b.ResetTimer()
293295
b.SetBytes(fsize)
294296

@@ -298,7 +300,6 @@ func BenchmarkS3Upload(b *testing.B) {
298300
r := io.LimitReader(infR, fsize)
299301

300302
fname := time.Now().Format("2006-01-02T15:04:05")
301-
b.Logf("uploading file: %s ....", fname)
302303

303304
putInput := &s3.PutObjectInput{
304305
Bucket: aws.String(bucket),
@@ -308,15 +309,28 @@ func BenchmarkS3Upload(b *testing.B) {
308309
}
309310

310311
b.StartTimer()
312+
startTime := time.Now()
311313
_, err := manager.NewUploader(s3Client, func(u *manager.Uploader) {
312314
u.PartSize = pSize
313315
u.LeavePartsOnError = true
314316
u.Concurrency = numThreds
315317
}).Upload(context.Background(), putInput)
318+
uploadDuration := time.Since(startTime)
319+
uploadTimes = append(uploadTimes, uploadDuration)
320+
b.Logf("uploading file: %s, completed in: %v", fname, uploadDuration)
316321
if err != nil {
317322
b.Fatalf("put object: %v", err)
318323
}
319324
}
325+
326+
if len(uploadTimes) > 0 {
327+
var totalDuration time.Duration
328+
for _, duration := range uploadTimes {
329+
totalDuration += duration
330+
}
331+
averageTime := totalDuration / time.Duration(len(uploadTimes))
332+
b.Logf("average upload time: %v", averageTime)
333+
}
320334
}
321335

322336
// BenchmarkS3StorageSave measures the performance of uploading file on the

0 commit comments

Comments
 (0)