Repository navigation
feat(db): opt-in BadgerDB memory tuning (BADGER_PROFILE=low-memory) - #137
Open
rafaelvieiras wants to merge 2 commits into
Open
rafaelvieiras wants to merge 2 commits into
rafaelvieiras wants to merge 2 commits into
Conversation
Haven opens five BadgerDB instances with BadgerDB's server-sized defaults (64 MB memtables, 256 MB block cache, 4 compactors), which is far more than a small relay needs. Add BADGER_PROFILE=low-memory plus per-option overrides via BadgerOptionsModifier. Defaults are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Haven opens five independent BadgerDB instances (private, chat, outbox, inbox, blossom) and uses
badger.DefaultOptionsfor each of them. Those defaults are sized for a database server (64 MB memtables x 5, 256 MB block cache, 4 compactors, 1 GB value log files), so on small hardware an idle relay reserves far more memory than its databases need.BadgerBackendalready exposesBadgerOptionsModifier, but Haven never used it and there is no way to tune this.This PR adds an opt-in way to tune it:
BADGER_PROFILE=low-memory: 8 MB x 2 memtables, 16 MB block cache, 8 MB index cache, 2 compactors, 64 MB value log files.0keeps the profile/BadgerDB default):BADGER_MEMTABLE_SIZE_MB,BADGER_NUM_MEMTABLES,BADGER_BLOCK_CACHE_MB,BADGER_INDEX_CACHE_MB,BADGER_NUM_COMPACTORS,BADGER_VALUE_LOG_FILE_SIZE_MB,BADGER_NUM_LEVEL_ZERO_TABLES.BADGER_*variable no modifier is installed..env.exampleentries.Measurements
Same binary, same copy of a real database (~21 MB on disk), same environment (WoT depth 3, real import relays), two containers side by side for 12 minutes,
DB_ENGINE=badger:BADGER_PROFILE=low-memoryBoth logged identical WoT results (16152 pubkeys, 3627 kept) and no errors. The default instance also started pushing pages to swap over the run; the low-memory one did not.
Tests
go test ./...passes and golangci-lint is clean for the new files.Side note: the package tests need the
OWNER_NPUB/relay variables exported in my environment, becausea_testenv_test.gogets initialised afterconfig.go(test files are appended after the regular ones). Unrelated to this change; mentioning it in case it is useful.