fuse: Add bandwidth accounting and buffering

This fixes rclone mount ignoring bwlimit and increases buffering which
should speed up transfers greatly.

Fixes #796
Fixes #690
This commit is contained in:
Nick Craig-Wood
2016-12-04 16:57:47 +00:00
parent 2cbdb95ce5
commit be4fd51289
4 changed files with 34 additions and 16 deletions
+25 -4
View File
@@ -276,12 +276,28 @@ type Account struct {
wholeFileDisabled bool // disables the whole file when doing parts
}
// NewAccount makes a Account reader for an object
func NewAccount(in io.ReadCloser, obj Object) *Account {
// NewAccountSizeName makes a Account reader for an io.ReadCloser of
// the given size and name
//
// If the file is above a certain size it adds an Async reader
func NewAccountSizeName(in io.ReadCloser, size int64, name string) *Account {
// On big files add a buffer
if size > 10<<20 {
const memUsed = 16 * 1024 * 1024
const bufSize = 128 * 1024
const buffers = memUsed / bufSize
newIn, err := newAsyncReader(in, buffers, bufSize)
if err != nil {
ErrorLog(name, "Failed to make buffer: %v", err)
} else {
in = newIn
}
}
acc := &Account{
in: in,
size: obj.Size(),
name: obj.Remote(),
size: size,
name: name,
exit: make(chan struct{}),
avg: ewma.NewMovingAverage(),
lpTime: time.Now(),
@@ -291,6 +307,11 @@ func NewAccount(in io.ReadCloser, obj Object) *Account {
return acc
}
// NewAccount makes a Account reader for an object
func NewAccount(in io.ReadCloser, obj Object) *Account {
return NewAccountSizeName(in, obj.Size(), obj.Remote())
}
// disableWholeFileAccounting turns off the whole file accounting
func (acc *Account) disableWholeFileAccounting() {
acc.mu.Lock()