Commit 818d0d78 authored by Steven Allen's avatar Steven Allen

feat: switch to file io and reduce max table size

It's actually _faster_ (4x) when reading, on my system. But that may just be
because I use BTRFS + SSDs? I'm really not sure.
parent ba5d5326
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"time" "time"
badger "github.com/dgraph-io/badger" badger "github.com/dgraph-io/badger"
options "github.com/dgraph-io/badger/options"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
dsq "github.com/ipfs/go-datastore/query" dsq "github.com/ipfs/go-datastore/query"
logger "github.com/ipfs/go-log" logger "github.com/ipfs/go-log"
...@@ -71,10 +72,30 @@ func init() { ...@@ -71,10 +72,30 @@ func init() {
GcDiscardRatio: 0.2, GcDiscardRatio: 0.2,
GcInterval: 15 * time.Minute, GcInterval: 15 * time.Minute,
GcSleep: 10 * time.Second, GcSleep: 10 * time.Second,
Options: badger.DefaultOptions(""), Options: badger.LSMOnlyOptions(""),
} }
// This is to optimize the database on close so it can be opened
// read-only and efficiently queried. We don't do that and hanging on
// stop isn't nice.
DefaultOptions.Options.CompactL0OnClose = false DefaultOptions.Options.CompactL0OnClose = false
// The alternative is "crash on start and tell the user to fix it". This
// will truncate corrupt and unsynced data, which we don't guarantee to
// persist anyways.
DefaultOptions.Options.Truncate = true DefaultOptions.Options.Truncate = true
// Uses less memory, is no slower when writing, and is faster when
// reading (in some tests).
DefaultOptions.Options.ValueLogLoadingMode = options.FileIO
// Explicitly set this to mmap. This doesn't use much memory anyways.
DefaultOptions.Options.TableLoadingMode = options.MemoryMap
// Reduce this from 64MiB to 16MiB. That means badger will hold on to
// 20MiB by default instead of 80MiB.
//
// This does not appear to have a significant performance hit.
DefaultOptions.Options.MaxTableSize = 16 << 20
} }
var _ ds.Datastore = (*Datastore)(nil) var _ ds.Datastore = (*Datastore)(nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment