accounting: refactor bwlimit code to allow for multiple slots

This commit is contained in:
Nick Craig-Wood
2021-01-30 17:39:30 +00:00
parent 31de631b22
commit 3b6df71838
7 changed files with 127 additions and 90 deletions
+3 -4
View File
@@ -10,7 +10,6 @@ import (
"unicode/utf8"
"github.com/rclone/rclone/fs/rc"
"golang.org/x/time/rate"
"github.com/pkg/errors"
"github.com/rclone/rclone/fs"
@@ -50,7 +49,7 @@ type Account struct {
exit chan struct{} // channel that will be closed when transfer is finished
withBuf bool // is using a buffered in
tokenBucket *rate.Limiter // per file bandwidth limiter (may be nil)
tokenBucket buckets // per file bandwidth limiter (may be nil)
values accountValues
}
@@ -289,7 +288,7 @@ func (acc *Account) DryRun(n int64) {
// Account for n bytes from the current file bandwidth limit (if any)
func (acc *Account) limitPerFileBandwidth(n int) {
acc.values.mu.Lock()
tokenBucket := acc.tokenBucket
tokenBucket := acc.tokenBucket[TokenBucketSlotAccounting]
acc.values.mu.Unlock()
if tokenBucket != nil {
@@ -310,7 +309,7 @@ func (acc *Account) accountRead(n int) {
acc.stats.Bytes(int64(n))
limitBandwidth(n)
TokenBucket.LimitBandwidth(TokenBucketSlotAccounting, n)
acc.limitPerFileBandwidth(n)
}