Skip to content

Commit b608e4f

Browse files
authored
Merge pull request #83 from ipfs/feat/fileio
feat: switch to file io and shrink tables
2 parents 8f15d7d + 818d0d7 commit b608e4f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

datastore.go

+22-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
badger "github.com/dgraph-io/badger"
11+
options "github.com/dgraph-io/badger/options"
1112
ds "github.com/ipfs/go-datastore"
1213
dsq "github.com/ipfs/go-datastore/query"
1314
logger "github.com/ipfs/go-log"
@@ -71,10 +72,30 @@ func init() {
7172
GcDiscardRatio: 0.2,
7273
GcInterval: 15 * time.Minute,
7374
GcSleep: 10 * time.Second,
74-
Options: badger.DefaultOptions(""),
75+
Options: badger.LSMOnlyOptions(""),
7576
}
77+
// This is to optimize the database on close so it can be opened
78+
// read-only and efficiently queried. We don't do that and hanging on
79+
// stop isn't nice.
7680
DefaultOptions.Options.CompactL0OnClose = false
81+
82+
// The alternative is "crash on start and tell the user to fix it". This
83+
// will truncate corrupt and unsynced data, which we don't guarantee to
84+
// persist anyways.
7785
DefaultOptions.Options.Truncate = true
86+
87+
// Uses less memory, is no slower when writing, and is faster when
88+
// reading (in some tests).
89+
DefaultOptions.Options.ValueLogLoadingMode = options.FileIO
90+
91+
// Explicitly set this to mmap. This doesn't use much memory anyways.
92+
DefaultOptions.Options.TableLoadingMode = options.MemoryMap
93+
94+
// Reduce this from 64MiB to 16MiB. That means badger will hold on to
95+
// 20MiB by default instead of 80MiB.
96+
//
97+
// This does not appear to have a significant performance hit.
98+
DefaultOptions.Options.MaxTableSize = 16 << 20
7899
}
79100

80101
var _ ds.Datastore = (*Datastore)(nil)

0 commit comments

Comments
 (0)