Skip to content

Commit

Permalink
Set ZSTD CompressionLevel to 1 (#4572)
Browse files Browse the repository at this point in the history
The default compression level in badger is 15 which is very slow.
This PR changes the ZSTD compression level from 15 to 1.
  • Loading branch information
Ibrahim Jarif authored Jan 14, 2020
1 parent ef2757c commit 1b83472
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dgraph/cmd/bulk/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (r *reducer) createBadger(i int) *badger.DB {
WithTableLoadingMode(bo.MemoryMap).WithValueThreshold(1 << 10 /* 1 KB */).
WithLogger(nil).WithMaxCacheSize(1 << 20).
WithEncryptionKey(enc.ReadEncryptionKeyFile(r.opt.BadgerKeyFile))

// TOOD(Ibrahim): Remove this once badger is updated.
opt.ZSTDCompressionLevel = 1

db, err := badger.OpenManaged(opt)
x.Check(err)

Expand Down
3 changes: 3 additions & 0 deletions dgraph/cmd/debug/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,9 @@ func run() {
WithTableLoadingMode(options.MemoryMap).
WithReadOnly(opt.readOnly)

// TODO(Ibrahim): Remove this once badger is updated.
bopts.ZSTDCompressionLevel = 1

x.AssertTruef(len(bopts.Dir) > 0, "No posting or wal dir specified.")
fmt.Printf("Opening DB: %s\n", bopts.Dir)

Expand Down
4 changes: 3 additions & 1 deletion dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ func setup(opts batchMutationOptions, dc *dgo.Dgraph) *loader {
var err error
db, err = badger.Open(badger.DefaultOptions(opt.clientDir).
WithTableLoadingMode(bopt.MemoryMap).
WithSyncWrites(false))
// TODO(Ibrahim): Remove compression level once badger is updated.
WithSyncWrites(false).WithZSTDCompressionLevel(1))
x.Checkf(err, "Error while creating badger KV posting store")

}

// compression with zero server actually makes things worse
Expand Down
4 changes: 4 additions & 0 deletions dgraph/cmd/zero/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func run() {
x.Checkf(os.MkdirAll(opts.w, 0700), "Error while creating WAL dir.")
kvOpt := badger.LSMOnlyOptions(opts.w).WithSyncWrites(false).WithTruncate(true).
WithValueLogFileSize(64 << 20).WithMaxCacheSize(10 << 20)

// TOOD(Ibrahim): Remove this once badger is updated.
kvOpt.ZSTDCompressionLevel = 1

kv, err := badger.Open(kvOpt)
x.Checkf(err, "Error while opening WAL store")
defer kv.Close()
Expand Down
4 changes: 4 additions & 0 deletions posting/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,10 @@ func (r *rebuilder) Run(ctx context.Context) error {
WithEventLogging(false).
WithLogRotatesToFlush(10).
WithMaxCacheSize(50) // TODO(Aman): Disable cache altogether

// TODO(Ibrahim): Remove this once badger is updated.
dbOpts.ZSTDCompressionLevel = 1

tmpDB, err := badger.OpenManaged(dbOpts)
if err != nil {
return errors.Wrap(err, "error opening temp badger for reindexing")
Expand Down
3 changes: 2 additions & 1 deletion testutil/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import (

func openDgraph(pdir string) (*badger.DB, error) {
opt := badger.DefaultOptions(pdir).WithTableLoadingMode(options.MemoryMap).
WithReadOnly(true)
// TOOD(Ibrahim): Remove compression level once badger is updated.
WithReadOnly(true).WithZSTDCompressionLevel(1)
return badger.OpenManaged(opt)
}

Expand Down
5 changes: 5 additions & 0 deletions worker/server_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (s *ServerState) runVlogGC(store *badger.DB) {
func setBadgerOptions(opt badger.Options) badger.Options {
opt = opt.WithSyncWrites(false).WithTruncate(true).WithLogger(&x.ToGlog{}).
WithEncryptionKey(enc.ReadEncryptionKeyFile(Config.BadgerKeyFile))
// TODO(ibrahim): Remove this once badger is updated in dgraph.
opt.ZSTDCompressionLevel = 1

glog.Infof("Setting Badger table load option: %s", Config.BadgerTables)
switch Config.BadgerTables {
Expand Down Expand Up @@ -158,6 +160,9 @@ func (s *ServerState) initStorage() {
glog.Infof("Opening write-ahead log BadgerDB with options: %+v\n", opt)
opt.EncryptionKey = key

// TODO(Ibrahim): Remove this once badger is updated.
opt.ZSTDCompressionLevel = 1

s.WALstore, err = badger.Open(opt)
x.Checkf(err, "Error while creating badger KV WAL store")
}
Expand Down

0 comments on commit 1b83472

Please sign in to comment.