Ensure GC runs after each compactor call
GC is triggered rarely, which may cause unnecessarily high memory spikes when running several compaction cycles in a row. Explicitly run GC so we don't have idle bytes marked as used from the previous cycle.
This commit is contained in:
parent
789e8224ff
commit
70909ca8ad
10
db.go
10
db.go
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -285,6 +286,7 @@ func (db *DB) compact() (changes bool, err error) {
|
|||
return changes, errors.Wrap(err, "persist head block")
|
||||
}
|
||||
changes = true
|
||||
runtime.GC()
|
||||
}
|
||||
|
||||
// Check for compactions of multiple blocks.
|
||||
|
@ -293,6 +295,9 @@ func (db *DB) compact() (changes bool, err error) {
|
|||
if err != nil {
|
||||
return changes, errors.Wrap(err, "plan compaction")
|
||||
}
|
||||
if len(plans) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
select {
|
||||
case <-db.stopc:
|
||||
|
@ -309,10 +314,7 @@ func (db *DB) compact() (changes bool, err error) {
|
|||
return changes, errors.Wrapf(err, "compact %s", p)
|
||||
}
|
||||
changes = true
|
||||
}
|
||||
// If we didn't compact anything, there's nothing left to do.
|
||||
if len(plans) == 0 {
|
||||
break
|
||||
runtime.GC()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue