fs/accounting: add remote control of bwlimit

This commit is contained in:
Nick Craig-Wood 2018-03-16 21:45:09 +00:00
parent 2db0c4dd95
commit 4295428a0f
3 changed files with 60 additions and 0 deletions

View file

@ -306,6 +306,11 @@ running, you can toggle the limiter like this:
kill -SIGUSR2 $(pidof rclone)
If you configure rclone with a [remote control](/rc) then you can use
change the bwlimit dynamically:
rclone rc core/bwlimit rate=1M
### --buffer-size=SIZE ###
Use this sized buffer to speed up file transfers. Each `--transfer`

View file

@ -69,10 +69,20 @@ control commands.
## Supported commands
### core/bwlimit: Set the bandwidth limit.
This sets the bandwidth limit to that passed in.
Eg
rclone core/bwlimit rate=1M
rclone core/bwlimit rate=off
### cache/expire: Purge a remote from cache
Purge a remote from the cache backend. Supports either a directory or a file.
Params:
- remote = path to remote (required)
- withData = true/false to delete cached data (chunks) as well (optional)

View file

@ -5,6 +5,8 @@ import (
"time"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fs/rc"
"github.com/pkg/errors"
"golang.org/x/net/context" // switch to "context" when we stop supporting go1.6
"golang.org/x/time/rate"
)
@ -112,3 +114,46 @@ func limitBandwidth(n int) {
tokenBucketMu.Unlock()
}
// Remote control for the token bucket
func init() {
rc.Add(rc.Call{
Path: "core/bwlimit",
Fn: func(in rc.Params) (out rc.Params, err error) {
ibwlimit, ok := in["rate"]
if !ok {
return out, errors.Errorf("parameter rate not found")
}
bwlimit, ok := ibwlimit.(string)
if !ok {
return out, errors.Errorf("value must be string rate=%v", ibwlimit)
}
var bws fs.BwTimetable
err = bws.Set(bwlimit)
if err != nil {
return out, errors.Wrap(err, "bad bwlimit")
}
if len(bws) != 1 {
return out, errors.New("need exactly 1 bandwidth setting")
}
bw := bws[0]
tokenBucketMu.Lock()
tokenBucket = newTokenBucket(bw.Bandwidth)
tokenBucketMu.Unlock()
fs.Logf(nil, "Bandwidth limit set to %v", bw.Bandwidth)
return rc.Params{"rate": bw.Bandwidth.String()}, nil
},
Title: "Set the bandwidth limit.",
Help: `
This sets the bandwidth limit to that passed in.
Eg
rclone core/bwlimit rate=1M
rclone core/bwlimit rate=off
The format of the parameter is exactly the same as passed to --bwlimit
except only one bandwidth may be specified.
`,
})
}