Skip to content

Commit f1c05e2

Browse files
authored
turn off badger's prefetch and tuning for memory usage (#168)
1 parent cf64dca commit f1c05e2

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

database/document/document.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ var documentDB *genji.DB
1818
var closeCh chan struct{}
1919

2020
func Init(cfg *config.Config) {
21+
badger.DefaultIteratorOptions.PrefetchValues = false
22+
2123
dataPath := path.Join(cfg.Storage.Path, "docdb")
2224
l, _ := initLogger(cfg)
2325
opts := badger.DefaultOptions(dataPath).
2426
WithZSTDCompressionLevel(3).
2527
WithBlockSize(8 * 1024).
2628
WithValueThreshold(128 * 1024).
29+
WithValueLogFileSize(64 * 1024 * 1024).
30+
WithBlockCacheSize(16 * 1024 * 1024).
31+
WithMemTableSize(16 * 1024 * 1024).
2732
WithLogger(l)
2833

2934
engine, err := badgerengine.NewEngine(opts)

utils/misc.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import (
99

1010
// GoWithRecovery wraps goroutine startup call with force recovery.
1111
// it will dump current goroutine stack into log if catch any recover result.
12-
// exec: execute logic function.
13-
// recoverFn: handler will be called after recover and before dump stack, passing `nil` means noop.
12+
//
13+
// exec: execute logic function.
14+
// recoverFn: handler will be called after recover and before dump stack, passing `nil` means noop.
1415
func GoWithRecovery(exec func(), recoverFn func(r interface{})) {
1516
defer func() {
1617
r := recover()

utils/testutil/util.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ import (
2525
)
2626

2727
func NewGenjiDB(t *testing.T, storagePath string) *genji.DB {
28+
badger.DefaultIteratorOptions.PrefetchValues = false
29+
2830
opts := badger.DefaultOptions(storagePath).
2931
WithZSTDCompressionLevel(3).
3032
WithBlockSize(8 * 1024).
31-
WithValueThreshold(128 * 1024)
33+
WithValueThreshold(128 * 1024).
34+
WithValueLogFileSize(64 * 1024 * 1024).
35+
WithBlockCacheSize(16 * 1024 * 1024).
36+
WithMemTableSize(16 * 1024 * 1024)
3237

3338
engine, err := badgerengine.NewEngine(opts)
3439
require.NoError(t, err)
@@ -38,10 +43,15 @@ func NewGenjiDB(t *testing.T, storagePath string) *genji.DB {
3843
}
3944

4045
func NewBadgerDB(t *testing.T, storagePath string) *badger.DB {
46+
badger.DefaultIteratorOptions.PrefetchValues = false
47+
4148
opts := badger.DefaultOptions(storagePath).
4249
WithZSTDCompressionLevel(3).
4350
WithBlockSize(8 * 1024).
44-
WithValueThreshold(128 * 1024)
51+
WithValueThreshold(128 * 1024).
52+
WithValueLogFileSize(64 * 1024 * 1024).
53+
WithBlockCacheSize(16 * 1024 * 1024).
54+
WithMemTableSize(16 * 1024 * 1024)
4555

4656
engine, err := badgerengine.NewEngine(opts)
4757
require.NoError(t, err)

0 commit comments

Comments
 (0)