|
8 | 8 | "time"
|
9 | 9 |
|
10 | 10 | badger "github.com/dgraph-io/badger"
|
| 11 | + options "github.com/dgraph-io/badger/options" |
11 | 12 | ds "github.com/ipfs/go-datastore"
|
12 | 13 | dsq "github.com/ipfs/go-datastore/query"
|
13 | 14 | logger "github.com/ipfs/go-log"
|
@@ -71,10 +72,30 @@ func init() {
|
71 | 72 | GcDiscardRatio: 0.2,
|
72 | 73 | GcInterval: 15 * time.Minute,
|
73 | 74 | GcSleep: 10 * time.Second,
|
74 |
| - Options: badger.DefaultOptions(""), |
| 75 | + Options: badger.LSMOnlyOptions(""), |
75 | 76 | }
|
| 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. |
76 | 80 | 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. |
77 | 85 | 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 |
78 | 99 | }
|
79 | 100 |
|
80 | 101 | var _ ds.Datastore = (*Datastore)(nil)
|
|
0 commit comments