Turn off compaction during business hours

runCompactor Compaction is consuming 100% CPU for 10 mins everyday at sporadic time with 100s of Go routines. I’d like to turn compaction off during businesss hours. Is there a way to customize compaction time to set it not to run during business hours between 8am and 5am?

goroutine profile: total 925
183 @ 0x43e54e 0x44e9c5 0xad166d 0x471aa1

0xad166c github.com/dgraph-io/badger/v4.(*levelsController).runCompactor+0x30c

Badger version:
v4.2.2

Go Version:
go1.21.8

OS:
Ubuntu

You could set opts.NumCompactors to zero which I think will disable auto compaction and then manually compact at times more convenient for you.

How do I run manual compaction in Go?

Check out the Flatten func of the DB type: badger/db.go at 9f07def77649d1f01c92ecb20c2f6c9c24fd2c4c · dgraph-io/badger · GitHub