From 08e404ac62ccef3faf2f3d03ad2d524a718661a8 Mon Sep 17 00:00:00 2001 From: "@RubenKelevra" Date: Sat, 30 May 2020 00:06:44 +0200 Subject: [PATCH] change default settings for the database, to allow for effective garbage collection fixes #54 settings are by courtesy of @jsign, see [his post here](https://github.com/dgraph-io/badger/issues/1297#issuecomment-612941482) --- datastore.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/datastore.go b/datastore.go index 151af22..5a983f2 100644 --- a/datastore.go +++ b/datastore.go @@ -79,15 +79,25 @@ var DefaultOptions Options func init() { DefaultOptions = Options{ - GcDiscardRatio: 0.2, + GcDiscardRatio: 0.01, GcInterval: 15 * time.Minute, GcSleep: 10 * time.Second, 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 + // This is to optimize the database on closure + DefaultOptions.Options.CompactL0OnClose = true + + // Remove elements which the has been deleted from the database + DefaultOptions.Options.NumVersionsToKeep = 0 + + // Reduce the number of zero tables (which are hold in memory) + DefaultOptions.Options.NumLevelZeroTables = 1 + + // Reduce the number of zero tables which are stalled + DefaultOptions.Options.NumLevelZeroTablesStall = 2 + + // Reduce the max vlog size usage after compaction ( + DefaultOptions.Options.ValueLogFileSize = 10485760 // 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