Add support to toggle bandwidth limits via SIGUSR2.

Sending rclone a SIGUSR2 signal will toggle the limiter between off and
the limit set with the --bwlimit command-line option.
This commit is contained in:
Marco Paganini
2016-10-30 17:46:59 +00:00
committed by Nick Craig-Wood
parent 062616e4dd
commit cc4f5ba7ba
4 changed files with 71 additions and 2 deletions
+20 -2
View File
@@ -17,8 +17,10 @@ import (
// Globals
var (
Stats = NewStats()
tokenBucket *tb.Bucket
Stats = NewStats()
tokenBucket *tb.Bucket
origTokenBucket = tokenBucket
prevTokenBucket = tokenBucket
)
// Start the token bucket if necessary
@@ -27,6 +29,12 @@ func startTokenBucket() {
tokenBucket = tb.NewBucket(int64(bwLimit), 100*time.Millisecond)
Log(nil, "Starting bandwidth limiter at %vBytes/s", &bwLimit)
}
origTokenBucket = tokenBucket
prevTokenBucket = tokenBucket
// Start the SIGUSR2 signal handler to toggle bandwidth.
// This function does nothing in windows systems.
startSignalHandler()
}
// stringSet holds a set of strings
@@ -333,6 +341,16 @@ func (acc *Account) read(in io.Reader, p []byte) (n int, err error) {
Stats.Bytes(int64(n))
// Log bandwidth limiter status change.
if tokenBucket != prevTokenBucket {
s := "disabled"
if tokenBucket != nil {
s = "enabled"
}
Log(nil, "Bandwidth limit %s by user", s)
prevTokenBucket = tokenBucket
}
// Limit the transfer speed if required
if tokenBucket != nil {
tokenBucket.Wait(int64(n))