mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 07:11:08 +00:00
Merge pull request #1345 from calmh/smaller-batches
Reduce memory usage by writing smaller batches
This commit is contained in:
commit
2edaf22590
@ -102,6 +102,9 @@ type dbWriter interface {
|
|||||||
Delete([]byte)
|
Delete([]byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Flush batches to disk when they contain this many records.
|
||||||
|
const batchFlushSize = 64
|
||||||
|
|
||||||
// deviceKey returns a byte slice encoding the following information:
|
// deviceKey returns a byte slice encoding the following information:
|
||||||
// keyTypeDevice (1 byte)
|
// keyTypeDevice (1 byte)
|
||||||
// folder (64 bytes)
|
// folder (64 bytes)
|
||||||
@ -275,6 +278,21 @@ func ldbGenericReplace(db *leveldb.DB, folder, device []byte, fs []protocol.File
|
|||||||
}
|
}
|
||||||
moreDb = dbi.Next()
|
moreDb = dbi.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write out and reuse the batch every few records, to avoid the batch
|
||||||
|
// growing too large and thus allocating unnecessarily much memory.
|
||||||
|
if batch.Len() > batchFlushSize {
|
||||||
|
if debugDB {
|
||||||
|
l.Debugf("db.Write %p", batch)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Write(batch, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.Reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if debugDB {
|
if debugDB {
|
||||||
@ -393,6 +411,21 @@ func ldbUpdate(db *leveldb.DB, folder, device []byte, fs []protocol.FileInfo) in
|
|||||||
ldbUpdateGlobal(snap, batch, folder, device, name, f.Version)
|
ldbUpdateGlobal(snap, batch, folder, device, name, f.Version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write out and reuse the batch every few records, to avoid the batch
|
||||||
|
// growing too large and thus allocating unnecessarily much memory.
|
||||||
|
if batch.Len() > batchFlushSize {
|
||||||
|
if debugDB {
|
||||||
|
l.Debugf("db.Write %p", batch)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.Write(batch, nil)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.Reset()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if debugDB {
|
if debugDB {
|
||||||
|
Loading…
Reference in New Issue
Block a user