Skip to content

Commit

Permalink
add options for badgerdb
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintWish committed Jan 7, 2025
1 parent 7238bce commit ab39a2a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions internal/database/badger/badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/msrevive/nexus2/internal/database"

"github.com/dgraph-io/badger/v4"
"github.com/dgraph-io/badger/v4/options"
)

// The smaller the key prefix the better?
Expand All @@ -21,16 +22,23 @@ func New() *badgerDB {
}

func (d *badgerDB) Connect(cfg database.Config, opts database.Options) error {
dOpts := badger.DefaultOptions(cfg.Badger.Directory)
// opts.ValueLogFileSize = 256 * 1024 * 1024 // 256 MB
// opts.LevelFanout = 10
// opts.LevelFringeSize = 100
// opts.BloomFalsePositive = 0.01
// opts.Compression = badger.Snappy
// opts.SyncWrites = false
opts.Logger = opts.Logger

db, err := badger.Open(dOpts)
bOpts := badger.DefaultOptions(cfg.Badger.Directory)
bOpts.WithCompression(options.None)
bOpts.WithBlockSize(0)
bOpts.WithBlockCacheSize(0)
bOpts.WithMemTableSize(4 << 20)

// opts.MemTableSize = 1 << 20
// opts.BaseTableSize = 1 << 20
// //opts.NumCompactors = 2
// opts.NumLevelZeroTables = 1
// opts.NumLevelZeroTablesStall = 2
// opts.BlockCacheSize = 10 << 20
// //opts.NumMemtables = 1
// opts.ValueThreshold = 1 << 10
//bOpts.Logger = opts.Logger

db, err := badger.Open(bOpts)
if err != nil {
return err
}
Expand Down

0 comments on commit ab39a2a

Please sign in to comment.