Percona-Lab / mongodb_consistent_backup

A tool for performing consistent backups of MongoDB Clusters or Replica Sets
https://www.percona.com
Apache License 2.0
276 stars 81 forks source link

S3 upload throttle: Add --upload.s3.target_mb_per_second parameter #294

Closed dschneller closed 5 years ago

dschneller commented 5 years ago

Boto2 unfortunately does not provide a bandwidth limiter for S3 uploads. Instead, it will upload a completed backup as quickly as possible, potentially consuming all available network bandwidth and therefore impacting other applications.

This patch adds a very basic throttling mechanism for S3 uploads by optionally hooking into the upload progress and determining the current bandwidth. If it exceeds the designated maximum, the upload thread will pause for a suitable amount of time (capped at 3 seconds) before resuming.

While this is far from ideal, it is an easy to understand and (from my experience) good enough method to protect other network users from starvation.

Notice: The calculation happens per upload thread.