From 34cba04268d7b583ad5f37d9e5690c7b516d9b01 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 4 Jun 2024 16:53:20 +0800 Subject: [PATCH 01/14] Separate receipts tune db mode --- .../Nethermind.Blockchain/Synchronization/ISyncConfig.cs | 3 +++ .../Nethermind.Blockchain/Synchronization/SyncConfig.cs | 1 + .../DbTuner/SyncDbTunerTests.cs | 4 +++- .../Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs | 4 +++- src/Nethermind/Nethermind.Synchronization/Synchronizer.cs | 4 +++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs index 551a9856a33..a262938f35d 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs @@ -123,6 +123,9 @@ public interface ISyncConfig : IConfig [ConfigItem(Description = "Configure the blocks database for write optimizations during sync.", DefaultValue = "EnableBlobFiles")] ITunableDb.TuneType BlocksDbTuneDbMode { get; set; } + [ConfigItem(Description = "Configure the receipts database for write optimizations during sync.", DefaultValue = "WriteBias")] + ITunableDb.TuneType ReceiptsDbTuneDbMode { get; set; } + [ConfigItem(Description = "The max number of threads used for syncing. `0` to use the number of logical processors.", DefaultValue = "0")] public int MaxProcessingThreads { get; set; } diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs index d2645336586..1e3eb8b7852 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs @@ -59,6 +59,7 @@ public string? PivotHash public bool NonValidatorNode { get; set; } = false; public ITunableDb.TuneType TuneDbMode { get; set; } = ITunableDb.TuneType.HeavyWrite; public ITunableDb.TuneType BlocksDbTuneDbMode { get; set; } = ITunableDb.TuneType.EnableBlobFiles; + public ITunableDb.TuneType ReceiptsDbTuneDbMode { get; set; } = ITunableDb.TuneType.WriteBias; public int MaxProcessingThreads { get; set; } public bool ExitOnSynced { get; set; } = false; public int ExitOnSyncedWaitTimeSec { get; set; } = 60; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs index 8c7954d8b92..dd47388b9c6 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs @@ -16,6 +16,7 @@ public class SyncDbTunerTests { private ITunableDb.TuneType _tuneType = ITunableDb.TuneType.HeavyWrite; private readonly ITunableDb.TuneType _blocksTuneType = ITunableDb.TuneType.AggressiveHeavyWrite; + private readonly ITunableDb.TuneType _receiptsTuneType = ITunableDb.TuneType.EnableBlobFiles; private SyncConfig _syncConfig = null!; private ISyncFeed _snapSyncFeed = null!; private ISyncFeed _bodiesSyncFeed = null!; @@ -33,6 +34,7 @@ public void Setup() { TuneDbMode = _tuneType, BlocksDbTuneDbMode = _blocksTuneType, + ReceiptsDbTuneDbMode = _receiptsTuneType, }; _snapSyncFeed = Substitute.For>(); _bodiesSyncFeed = Substitute.For>(); @@ -83,7 +85,7 @@ public void WhenBodiesIsOn_TriggerBlocksDbTune() [Test] public void WhenReceiptsIsOn_TriggerReceiptsDbTune() { - TestFeedAndDbTune(_receiptSyncFeed, _receiptDb); + TestFeedAndDbTune(_receiptSyncFeed, _receiptDb, _receiptsTuneType); } private void TestFeedAndDbTune(ISyncFeed feed, ITunableDb db, ITunableDb.TuneType? tuneType = null) diff --git a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs index e9f5c7c10d5..90ab1b5e51d 100644 --- a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs @@ -18,6 +18,7 @@ public class SyncDbTuner private readonly ITunableDb.TuneType _tuneType; private readonly ITunableDb.TuneType _blocksDbTuneType; + private readonly ITunableDb.TuneType _receiptsDbTuneType; public SyncDbTuner( ISyncConfig syncConfig, @@ -55,6 +56,7 @@ public SyncDbTuner( _tuneType = syncConfig.TuneDbMode; _blocksDbTuneType = syncConfig.BlocksDbTuneDbMode; + _receiptsDbTuneType = syncConfig.ReceiptsDbTuneDbMode; } private void SnapStateChanged(object? sender, SyncFeedStateEventArgs e) @@ -87,7 +89,7 @@ private void ReceiptsStateChanged(object? sender, SyncFeedStateEventArgs e) { if (e.NewState == SyncFeedState.Active) { - _receiptDb?.Tune(_tuneType); + _receiptDb?.Tune(_receiptsDbTuneType); } else if (e.NewState == SyncFeedState.Finished) { diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index 614ae1e50ea..812ad9e23df 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -170,7 +170,9 @@ public virtual void Start() StartStateSyncComponents(); } - if (_syncConfig.TuneDbMode != ITunableDb.TuneType.Default || _syncConfig.BlocksDbTuneDbMode != ITunableDb.TuneType.Default) + if (_syncConfig.TuneDbMode != ITunableDb.TuneType.Default + || _syncConfig.BlocksDbTuneDbMode != ITunableDb.TuneType.Default + || _syncConfig.ReceiptsDbTuneDbMode != ITunableDb.TuneType.Default) { SetupDbOptimizer(); } From 965517002d911657e8e807d9026b364e248a53ce Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 4 Jun 2024 17:16:57 +0800 Subject: [PATCH 02/14] Fix column not using main table config --- .../Config/PerTableDbConfig.cs | 65 ++++++++++++------- .../Config/PerTableDbConfigTests.cs | 11 ++++ 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index b50ffb7b4e8..12b268d989c 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -2,7 +2,6 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; -using System.Collections.Generic; using System.IO; using System.Reflection; using Nethermind.Core.Extensions; @@ -12,6 +11,7 @@ namespace Nethermind.Db.Rocks.Config; public class PerTableDbConfig { private readonly string _tableName; + private readonly string? _columnName; private readonly IDbConfig _dbConfig; private readonly DbSettings _settings; @@ -20,10 +20,7 @@ public PerTableDbConfig(IDbConfig dbConfig, DbSettings dbSettings, string? colum _dbConfig = dbConfig; _settings = dbSettings; _tableName = _settings.DbName; - if (columnName is not null) - { - _tableName += columnName; - } + _columnName = columnName; } public bool CacheIndexAndFilterBlocks => _settings.CacheIndexAndFilterBlocks ?? ReadConfig(nameof(CacheIndexAndFilterBlocks)); @@ -77,43 +74,65 @@ public PerTableDbConfig(IDbConfig dbConfig, DbSettings dbSettings, string? colum private T? ReadConfig(string propertyName) { - return ReadConfig(_dbConfig, propertyName, GetPrefix()); + return ReadConfig(_dbConfig, propertyName, GetPrefixes()); } - private string GetPrefix() + public string[] GetPrefixes() { - return _tableName.StartsWith("State") ? "StateDb" : string.Concat(_tableName, "Db"); + if (_tableName.StartsWith("State")) + { + return ["StateDb"]; + } + + if (_columnName != null) + { + return [ + string.Concat(_tableName, _columnName, "Db"), + string.Concat(_tableName, "Db"), + ]; + } + + return [string.Concat(_tableName, "Db")]; } - private static T? ReadConfig(IDbConfig dbConfig, string propertyName, string prefix) + private static T? ReadConfig(IDbConfig dbConfig, string propertyName, string[] prefixes) { - string prefixed = string.Concat(prefix, propertyName); - try { Type type = dbConfig.GetType(); - PropertyInfo? propertyInfo = type.GetProperty(prefixed, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); + PropertyInfo? propertyInfo; - if (propertyInfo is not null && propertyInfo.PropertyType.CanBeAssignedNull()) + foreach (var prefix in prefixes) { - // If its nullable check if its null first - T? val = (T?)propertyInfo?.GetValue(dbConfig); - if (val is not null) + string prefixed = string.Concat(prefix, propertyName); + + propertyInfo = type.GetProperty(prefixed, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); + if (propertyInfo is not null) { - return val; + if (propertyInfo.PropertyType.CanBeAssignedNull()) + { + // If its nullable check if its null first + T? val = (T?)propertyInfo.GetValue(dbConfig); + if (val is not null) + { + return val; + } + } + else + { + // If not nullable just use it directly + return (T?)propertyInfo.GetValue(dbConfig); + } } - - // Use generic one even if its available - propertyInfo = type.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); } - // if no custom db property default to generic one - propertyInfo ??= type.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); + // Use generic one even if its available + propertyInfo = type.GetProperty(propertyName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); return (T?)propertyInfo?.GetValue(dbConfig); } catch (Exception e) { - throw new InvalidDataException($"Unable to read {prefixed} property from DB config", e); + throw new InvalidDataException($"Unable to read property from DB config. Prefixes: ${prefixes}", e); } } } diff --git a/src/Nethermind/Nethermind.Db.Test/Config/PerTableDbConfigTests.cs b/src/Nethermind/Nethermind.Db.Test/Config/PerTableDbConfigTests.cs index 22f78e51939..d9d65b1d024 100644 --- a/src/Nethermind/Nethermind.Db.Test/Config/PerTableDbConfigTests.cs +++ b/src/Nethermind/Nethermind.Db.Test/Config/PerTableDbConfigTests.cs @@ -38,6 +38,17 @@ public void CanReadAllConfigForAllTable() } } + [Test] + public void When_ColumnDb_UsePerTableConfig() + { + DbConfig dbConfig = new DbConfig(); + dbConfig.MaxOpenFiles = 2; + dbConfig.ReceiptsDbMaxOpenFiles = 3; + + PerTableDbConfig config = new PerTableDbConfig(dbConfig, new DbSettings(DbNames.Receipts, ""), "Blocks"); + config.MaxOpenFiles.Should().Be(3); + } + [Test] public void When_PerTableConfigIsAvailable_UsePerTableConfig() { From 01216c6d6c057f9f9af39f255b27550851f55a66 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 4 Jun 2024 17:19:12 +0800 Subject: [PATCH 03/14] Unnecessary public modifier --- src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index 12b268d989c..884797cc712 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -77,7 +77,7 @@ public PerTableDbConfig(IDbConfig dbConfig, DbSettings dbSettings, string? colum return ReadConfig(_dbConfig, propertyName, GetPrefixes()); } - public string[] GetPrefixes() + private string[] GetPrefixes() { if (_tableName.StartsWith("State")) { From 50566e2f8c9de9160057632e7dedb7eed2819df4 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 4 Jun 2024 19:58:39 +0800 Subject: [PATCH 04/14] Reduce target file size to 64 --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index 0b133070801..ede729e0f8a 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -65,7 +65,7 @@ public class DbConfig : IDbConfig public bool? ReceiptsDbUseDirectReads { get; set; } public bool? ReceiptsDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? ReceiptsDbCompactionReadAhead { get; set; } - public ulong ReceiptsDbTargetFileSizeBase { get; set; } = (ulong)256.MiB(); + public ulong ReceiptsDbTargetFileSizeBase { get; set; } = (ulong)64.MiB(); public string? ReceiptsDbAdditionalRocksDbOptions { get; set; } public ulong BlocksDbWriteBufferSize { get; set; } = (ulong)64.MiB(); From b2062d14d42585aef1c9c03ba8a7dab5c4742d62 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Tue, 4 Jun 2024 20:50:29 +0800 Subject: [PATCH 05/14] Separate blocks and transactions --- .../Config/PerTableDbConfig.cs | 12 ++++++---- .../DbTuner/SyncDbTunerTests.cs | 22 ++++++++++++++----- .../DbTuner/SyncDbOptimizer.cs | 15 ++++++++----- .../Synchronizer.cs | 3 ++- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index 884797cc712..69a35387958 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -112,10 +112,14 @@ private string[] GetPrefixes() if (propertyInfo.PropertyType.CanBeAssignedNull()) { // If its nullable check if its null first - T? val = (T?)propertyInfo.GetValue(dbConfig); - if (val is not null) + object? valObj = propertyInfo.GetValue(dbConfig); + if (valObj is not null) { - return val; + T? val = (T?)valObj; + if (val is not null) + { + return val; + } } } else @@ -132,7 +136,7 @@ private string[] GetPrefixes() } catch (Exception e) { - throw new InvalidDataException($"Unable to read property from DB config. Prefixes: ${prefixes}", e); + throw new InvalidDataException($"Unable to read property {propertyName} from DB config. Prefixes: {string.Join(",", prefixes)}", e); } } } diff --git a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs index dd47388b9c6..3377338427a 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs @@ -24,7 +24,8 @@ public class SyncDbTunerTests private ITunableDb _stateDb = null!; private ITunableDb _codeDb = null!; private ITunableDb _blockDb = null!; - private ITunableDb _receiptDb = null!; + private ITunableDb _receiptBlocksDb = null!; + private ITunableDb _receiptTransactionsDb = null!; [SetUp] public void Setup() @@ -42,7 +43,8 @@ public void Setup() _stateDb = Substitute.For(); _codeDb = Substitute.For(); _blockDb = Substitute.For(); - _receiptDb = Substitute.For(); + _receiptBlocksDb = Substitute.For(); + _receiptTransactionsDb = Substitute.For(); SyncDbTuner _ = new SyncDbTuner( _syncConfig, @@ -52,7 +54,8 @@ public void Setup() _stateDb, _codeDb, _blockDb, - _receiptDb); + _receiptBlocksDb, + _receiptTransactionsDb); } [TearDown] @@ -60,7 +63,8 @@ public void TearDown() { _blockDb?.Dispose(); _codeDb?.Dispose(); - _receiptDb?.Dispose(); + _receiptBlocksDb?.Dispose(); + _receiptTransactionsDb?.Dispose(); _stateDb?.Dispose(); } @@ -83,9 +87,15 @@ public void WhenBodiesIsOn_TriggerBlocksDbTune() } [Test] - public void WhenReceiptsIsOn_TriggerReceiptsDbTune() + public void WhenReceiptsIsOn_TriggerReceiptBlocksDbTune() { - TestFeedAndDbTune(_receiptSyncFeed, _receiptDb, _receiptsTuneType); + TestFeedAndDbTune(_receiptSyncFeed, _receiptBlocksDb, _receiptsTuneType); + } + + [Test] + public void WhenReceiptsIsOn_TriggerReceiptsTransactionsDbTune() + { + TestFeedAndDbTune(_receiptSyncFeed, _receiptTransactionsDb, _tuneType); } private void TestFeedAndDbTune(ISyncFeed feed, ITunableDb db, ITunableDb.TuneType? tuneType = null) diff --git a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs index 90ab1b5e51d..cd4f2adb461 100644 --- a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs @@ -14,7 +14,8 @@ public class SyncDbTuner private readonly ITunableDb? _stateDb; private readonly ITunableDb? _codeDb; private readonly ITunableDb? _blockDb; - private readonly ITunableDb? _receiptDb; + private readonly ITunableDb? _receiptBlocksDb; + private readonly ITunableDb? _receiptTransactionsDb; private readonly ITunableDb.TuneType _tuneType; private readonly ITunableDb.TuneType _blocksDbTuneType; @@ -28,7 +29,8 @@ public SyncDbTuner( ITunableDb? stateDb, ITunableDb? codeDb, ITunableDb? blockDb, - ITunableDb? receiptDb + ITunableDb? receiptBlocksDb, + ITunableDb? receiptTransactionsDb ) { // Only these three make sense as they are write heavy @@ -52,7 +54,8 @@ public SyncDbTuner( _stateDb = stateDb; _codeDb = codeDb; _blockDb = blockDb; - _receiptDb = receiptDb; + _receiptBlocksDb = receiptBlocksDb; + _receiptTransactionsDb = receiptTransactionsDb; _tuneType = syncConfig.TuneDbMode; _blocksDbTuneType = syncConfig.BlocksDbTuneDbMode; @@ -89,11 +92,13 @@ private void ReceiptsStateChanged(object? sender, SyncFeedStateEventArgs e) { if (e.NewState == SyncFeedState.Active) { - _receiptDb?.Tune(_receiptsDbTuneType); + _receiptBlocksDb?.Tune(_receiptsDbTuneType); + _receiptTransactionsDb?.Tune(_tuneType); } else if (e.NewState == SyncFeedState.Finished) { - _receiptDb?.Tune(ITunableDb.TuneType.Default); + _receiptBlocksDb?.Tune(ITunableDb.TuneType.Default); + _receiptTransactionsDb?.Tune(ITunableDb.TuneType.Default); } } } diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index 812ad9e23df..e4b45846412 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -222,7 +222,8 @@ private void SetupDbOptimizer() _dbProvider.StateDb as ITunableDb, _dbProvider.CodeDb as ITunableDb, _dbProvider.BlocksDb as ITunableDb, - _dbProvider.ReceiptsDb as ITunableDb); + _dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Blocks) as ITunableDb, + _dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Transactions) as ITunableDb); } private void StartFullSyncComponents() From 31efa2b2af132ac9e034a6f5fcc84c08130f147e Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 09:29:41 +0800 Subject: [PATCH 06/14] Revert "Separate blocks and transactions" This reverts commit b2062d14d42585aef1c9c03ba8a7dab5c4742d62. --- .../Config/PerTableDbConfig.cs | 12 ++++------ .../DbTuner/SyncDbTunerTests.cs | 22 +++++-------------- .../DbTuner/SyncDbOptimizer.cs | 15 +++++-------- .../Synchronizer.cs | 3 +-- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index 69a35387958..884797cc712 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -112,14 +112,10 @@ private string[] GetPrefixes() if (propertyInfo.PropertyType.CanBeAssignedNull()) { // If its nullable check if its null first - object? valObj = propertyInfo.GetValue(dbConfig); - if (valObj is not null) + T? val = (T?)propertyInfo.GetValue(dbConfig); + if (val is not null) { - T? val = (T?)valObj; - if (val is not null) - { - return val; - } + return val; } } else @@ -136,7 +132,7 @@ private string[] GetPrefixes() } catch (Exception e) { - throw new InvalidDataException($"Unable to read property {propertyName} from DB config. Prefixes: {string.Join(",", prefixes)}", e); + throw new InvalidDataException($"Unable to read property from DB config. Prefixes: ${prefixes}", e); } } } diff --git a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs index 3377338427a..dd47388b9c6 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs @@ -24,8 +24,7 @@ public class SyncDbTunerTests private ITunableDb _stateDb = null!; private ITunableDb _codeDb = null!; private ITunableDb _blockDb = null!; - private ITunableDb _receiptBlocksDb = null!; - private ITunableDb _receiptTransactionsDb = null!; + private ITunableDb _receiptDb = null!; [SetUp] public void Setup() @@ -43,8 +42,7 @@ public void Setup() _stateDb = Substitute.For(); _codeDb = Substitute.For(); _blockDb = Substitute.For(); - _receiptBlocksDb = Substitute.For(); - _receiptTransactionsDb = Substitute.For(); + _receiptDb = Substitute.For(); SyncDbTuner _ = new SyncDbTuner( _syncConfig, @@ -54,8 +52,7 @@ public void Setup() _stateDb, _codeDb, _blockDb, - _receiptBlocksDb, - _receiptTransactionsDb); + _receiptDb); } [TearDown] @@ -63,8 +60,7 @@ public void TearDown() { _blockDb?.Dispose(); _codeDb?.Dispose(); - _receiptBlocksDb?.Dispose(); - _receiptTransactionsDb?.Dispose(); + _receiptDb?.Dispose(); _stateDb?.Dispose(); } @@ -87,15 +83,9 @@ public void WhenBodiesIsOn_TriggerBlocksDbTune() } [Test] - public void WhenReceiptsIsOn_TriggerReceiptBlocksDbTune() + public void WhenReceiptsIsOn_TriggerReceiptsDbTune() { - TestFeedAndDbTune(_receiptSyncFeed, _receiptBlocksDb, _receiptsTuneType); - } - - [Test] - public void WhenReceiptsIsOn_TriggerReceiptsTransactionsDbTune() - { - TestFeedAndDbTune(_receiptSyncFeed, _receiptTransactionsDb, _tuneType); + TestFeedAndDbTune(_receiptSyncFeed, _receiptDb, _receiptsTuneType); } private void TestFeedAndDbTune(ISyncFeed feed, ITunableDb db, ITunableDb.TuneType? tuneType = null) diff --git a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs index cd4f2adb461..90ab1b5e51d 100644 --- a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs @@ -14,8 +14,7 @@ public class SyncDbTuner private readonly ITunableDb? _stateDb; private readonly ITunableDb? _codeDb; private readonly ITunableDb? _blockDb; - private readonly ITunableDb? _receiptBlocksDb; - private readonly ITunableDb? _receiptTransactionsDb; + private readonly ITunableDb? _receiptDb; private readonly ITunableDb.TuneType _tuneType; private readonly ITunableDb.TuneType _blocksDbTuneType; @@ -29,8 +28,7 @@ public SyncDbTuner( ITunableDb? stateDb, ITunableDb? codeDb, ITunableDb? blockDb, - ITunableDb? receiptBlocksDb, - ITunableDb? receiptTransactionsDb + ITunableDb? receiptDb ) { // Only these three make sense as they are write heavy @@ -54,8 +52,7 @@ public SyncDbTuner( _stateDb = stateDb; _codeDb = codeDb; _blockDb = blockDb; - _receiptBlocksDb = receiptBlocksDb; - _receiptTransactionsDb = receiptTransactionsDb; + _receiptDb = receiptDb; _tuneType = syncConfig.TuneDbMode; _blocksDbTuneType = syncConfig.BlocksDbTuneDbMode; @@ -92,13 +89,11 @@ private void ReceiptsStateChanged(object? sender, SyncFeedStateEventArgs e) { if (e.NewState == SyncFeedState.Active) { - _receiptBlocksDb?.Tune(_receiptsDbTuneType); - _receiptTransactionsDb?.Tune(_tuneType); + _receiptDb?.Tune(_receiptsDbTuneType); } else if (e.NewState == SyncFeedState.Finished) { - _receiptBlocksDb?.Tune(ITunableDb.TuneType.Default); - _receiptTransactionsDb?.Tune(ITunableDb.TuneType.Default); + _receiptDb?.Tune(ITunableDb.TuneType.Default); } } } diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index e4b45846412..812ad9e23df 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -222,8 +222,7 @@ private void SetupDbOptimizer() _dbProvider.StateDb as ITunableDb, _dbProvider.CodeDb as ITunableDb, _dbProvider.BlocksDb as ITunableDb, - _dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Blocks) as ITunableDb, - _dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Transactions) as ITunableDb); + _dbProvider.ReceiptsDb as ITunableDb); } private void StartFullSyncComponents() From 5d6e8ec850cc972a694ecc631313a26486e58b9a Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 09:30:02 +0800 Subject: [PATCH 07/14] Revert "Separate receipts tune db mode" This reverts commit 34cba04268d7b583ad5f37d9e5690c7b516d9b01. --- .../Nethermind.Blockchain/Synchronization/ISyncConfig.cs | 3 --- .../Nethermind.Blockchain/Synchronization/SyncConfig.cs | 1 - .../DbTuner/SyncDbTunerTests.cs | 4 +--- .../Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs | 4 +--- src/Nethermind/Nethermind.Synchronization/Synchronizer.cs | 4 +--- 5 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs index a262938f35d..551a9856a33 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/ISyncConfig.cs @@ -123,9 +123,6 @@ public interface ISyncConfig : IConfig [ConfigItem(Description = "Configure the blocks database for write optimizations during sync.", DefaultValue = "EnableBlobFiles")] ITunableDb.TuneType BlocksDbTuneDbMode { get; set; } - [ConfigItem(Description = "Configure the receipts database for write optimizations during sync.", DefaultValue = "WriteBias")] - ITunableDb.TuneType ReceiptsDbTuneDbMode { get; set; } - [ConfigItem(Description = "The max number of threads used for syncing. `0` to use the number of logical processors.", DefaultValue = "0")] public int MaxProcessingThreads { get; set; } diff --git a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs index 1e3eb8b7852..d2645336586 100644 --- a/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs +++ b/src/Nethermind/Nethermind.Blockchain/Synchronization/SyncConfig.cs @@ -59,7 +59,6 @@ public string? PivotHash public bool NonValidatorNode { get; set; } = false; public ITunableDb.TuneType TuneDbMode { get; set; } = ITunableDb.TuneType.HeavyWrite; public ITunableDb.TuneType BlocksDbTuneDbMode { get; set; } = ITunableDb.TuneType.EnableBlobFiles; - public ITunableDb.TuneType ReceiptsDbTuneDbMode { get; set; } = ITunableDb.TuneType.WriteBias; public int MaxProcessingThreads { get; set; } public bool ExitOnSynced { get; set; } = false; public int ExitOnSyncedWaitTimeSec { get; set; } = 60; diff --git a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs index dd47388b9c6..8c7954d8b92 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/DbTuner/SyncDbTunerTests.cs @@ -16,7 +16,6 @@ public class SyncDbTunerTests { private ITunableDb.TuneType _tuneType = ITunableDb.TuneType.HeavyWrite; private readonly ITunableDb.TuneType _blocksTuneType = ITunableDb.TuneType.AggressiveHeavyWrite; - private readonly ITunableDb.TuneType _receiptsTuneType = ITunableDb.TuneType.EnableBlobFiles; private SyncConfig _syncConfig = null!; private ISyncFeed _snapSyncFeed = null!; private ISyncFeed _bodiesSyncFeed = null!; @@ -34,7 +33,6 @@ public void Setup() { TuneDbMode = _tuneType, BlocksDbTuneDbMode = _blocksTuneType, - ReceiptsDbTuneDbMode = _receiptsTuneType, }; _snapSyncFeed = Substitute.For>(); _bodiesSyncFeed = Substitute.For>(); @@ -85,7 +83,7 @@ public void WhenBodiesIsOn_TriggerBlocksDbTune() [Test] public void WhenReceiptsIsOn_TriggerReceiptsDbTune() { - TestFeedAndDbTune(_receiptSyncFeed, _receiptDb, _receiptsTuneType); + TestFeedAndDbTune(_receiptSyncFeed, _receiptDb); } private void TestFeedAndDbTune(ISyncFeed feed, ITunableDb db, ITunableDb.TuneType? tuneType = null) diff --git a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs index 90ab1b5e51d..e9f5c7c10d5 100644 --- a/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/DbTuner/SyncDbOptimizer.cs @@ -18,7 +18,6 @@ public class SyncDbTuner private readonly ITunableDb.TuneType _tuneType; private readonly ITunableDb.TuneType _blocksDbTuneType; - private readonly ITunableDb.TuneType _receiptsDbTuneType; public SyncDbTuner( ISyncConfig syncConfig, @@ -56,7 +55,6 @@ public SyncDbTuner( _tuneType = syncConfig.TuneDbMode; _blocksDbTuneType = syncConfig.BlocksDbTuneDbMode; - _receiptsDbTuneType = syncConfig.ReceiptsDbTuneDbMode; } private void SnapStateChanged(object? sender, SyncFeedStateEventArgs e) @@ -89,7 +87,7 @@ private void ReceiptsStateChanged(object? sender, SyncFeedStateEventArgs e) { if (e.NewState == SyncFeedState.Active) { - _receiptDb?.Tune(_receiptsDbTuneType); + _receiptDb?.Tune(_tuneType); } else if (e.NewState == SyncFeedState.Finished) { diff --git a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs index 812ad9e23df..614ae1e50ea 100644 --- a/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs +++ b/src/Nethermind/Nethermind.Synchronization/Synchronizer.cs @@ -170,9 +170,7 @@ public virtual void Start() StartStateSyncComponents(); } - if (_syncConfig.TuneDbMode != ITunableDb.TuneType.Default - || _syncConfig.BlocksDbTuneDbMode != ITunableDb.TuneType.Default - || _syncConfig.ReceiptsDbTuneDbMode != ITunableDb.TuneType.Default) + if (_syncConfig.TuneDbMode != ITunableDb.TuneType.Default || _syncConfig.BlocksDbTuneDbMode != ITunableDb.TuneType.Default) { SetupDbOptimizer(); } From 50f7fd059604e45478e1754cd1dbfed4d0f461cf Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 09:30:49 +0800 Subject: [PATCH 08/14] Fix exception --- .../Nethermind.Db.Rocks/Config/PerTableDbConfig.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index 884797cc712..90c98080b9c 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -112,10 +112,14 @@ private string[] GetPrefixes() if (propertyInfo.PropertyType.CanBeAssignedNull()) { // If its nullable check if its null first - T? val = (T?)propertyInfo.GetValue(dbConfig); - if (val is not null) + object? valObj = propertyInfo.GetValue(dbConfig); + if (valObj is not null) { - return val; + T? val = (T?)valObj; + if (val is not null) + { + return val; + } } } else From b0e0979f6d587c568d41650063ad385b1174bf9e Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 09:31:26 +0800 Subject: [PATCH 09/14] Set max compaction bytes to prevent very large compaction --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index ede729e0f8a..bf3d67a0f74 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -36,7 +36,7 @@ public class DbConfig : IDbConfig public bool AllowMmapReads { get; set; } = false; public bool? VerifyChecksum { get; set; } = true; public double MaxBytesForLevelMultiplier { get; set; } = 10; - public ulong? MaxCompactionBytes { get; set; } = null; + public ulong? MaxCompactionBytes { get; set; } = (ulong)4.GiB(); public int MinWriteBufferNumberToMerge { get; set; } = 1; public ulong? RowCacheSize { get; set; } = null; public bool OptimizeFiltersForHits { get; set; } = true; From a9c1dff3337560a46774baa01355ae0810879825 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 10:25:44 +0800 Subject: [PATCH 10/14] Introduce compressibility hint --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 3 +++ src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs | 3 +++ src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs | 1 + src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs | 3 ++- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index bf3d67a0f74..ff2c1346878 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -52,6 +52,7 @@ public class DbConfig : IDbConfig public ulong BytesPerSync { get; set; } = 0; public double? DataBlockIndexUtilRatio { get; set; } public bool EnableFileWarmer { get; set; } = false; + public double CompressibilityHint { get; set; } = 1.0; public ulong BlobTransactionsDbBlockCacheSize { get; set; } = (ulong)32.MiB(); @@ -66,6 +67,7 @@ public class DbConfig : IDbConfig public bool? ReceiptsDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? ReceiptsDbCompactionReadAhead { get; set; } public ulong ReceiptsDbTargetFileSizeBase { get; set; } = (ulong)64.MiB(); + public double ReceiptsDbCompressibilityHint { get; set; } = 0.6; public string? ReceiptsDbAdditionalRocksDbOptions { get; set; } public ulong BlocksDbWriteBufferSize { get; set; } = (ulong)64.MiB(); @@ -202,6 +204,7 @@ public class DbConfig : IDbConfig public int? StateDbUseRibbonFilterStartingFromLevel { get; set; } = 2; public double? StateDbDataBlockIndexUtilRatio { get; set; } = 0.5; public bool StateDbEnableFileWarmer { get; set; } = false; + public double StateDbCompressibilityHint { get; set; } = 0.75; public string? StateDbAdditionalRocksDbOptions { get; set; } public uint RecycleLogFileNum { get; set; } = 0; diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs index e16202cedd7..b19730fdf50 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs @@ -53,6 +53,7 @@ public interface IDbConfig : IConfig ulong BytesPerSync { get; set; } double? DataBlockIndexUtilRatio { get; set; } bool EnableFileWarmer { get; set; } + double CompressibilityHint { get; set; } ulong BlobTransactionsDbBlockCacheSize { get; set; } @@ -67,6 +68,7 @@ public interface IDbConfig : IConfig bool? ReceiptsDbUseDirectIoForFlushAndCompactions { get; set; } ulong? ReceiptsDbCompactionReadAhead { get; set; } ulong ReceiptsDbTargetFileSizeBase { get; set; } + double ReceiptsDbCompressibilityHint { get; set; } string? ReceiptsDbAdditionalRocksDbOptions { get; set; } ulong BlocksDbWriteBufferSize { get; set; } @@ -203,6 +205,7 @@ public interface IDbConfig : IConfig int? StateDbUseRibbonFilterStartingFromLevel { get; set; } double? StateDbDataBlockIndexUtilRatio { get; set; } bool StateDbEnableFileWarmer { get; set; } + double StateDbCompressibilityHint { get; set; } string? StateDbAdditionalRocksDbOptions { get; set; } /// diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs index 90c98080b9c..5ca7bb5a6de 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs @@ -71,6 +71,7 @@ public PerTableDbConfig(IDbConfig dbConfig, DbSettings dbSettings, string? colum public ulong BytesPerSync => ReadConfig(nameof(BytesPerSync)); public double? DataBlockIndexUtilRatio => ReadConfig(nameof(DataBlockIndexUtilRatio)); public bool EnableFileWarmer => ReadConfig(nameof(EnableFileWarmer)); + public double CompressibilityHint => ReadConfig(nameof(CompressibilityHint)); private T? ReadConfig(string propertyName) { diff --git a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs index 85133e0704e..6841a33fc92 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs @@ -1609,7 +1609,8 @@ private IDictionary GetHeavyWriteOptions(ulong l0SizeTarget) // but no io, only cpu. // bufferSize*maxBufferNumber = 128MB, which is the max memory used, which tend to be the case as its now // stalled by compaction instead of flush. - ulong bufferSize = (ulong)16.MiB(); + // The buffer is not compressed unlike l0File, so to account for it, its size need to be slightly larger. + ulong bufferSize = (ulong)(16.MiB() / _perTableDbConfig.CompressibilityHint); ulong l0FileSize = bufferSize * (ulong)_perTableDbConfig.MinWriteBufferNumberToMerge; ulong maxBufferNumber = 8; From 5bf56671890d5b73a2af7574541c83ab9498c18b Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 10:42:45 +0800 Subject: [PATCH 11/14] Fix wrong calculation --- src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs index 6841a33fc92..7a566f41fa7 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs @@ -1610,8 +1610,9 @@ private IDictionary GetHeavyWriteOptions(ulong l0SizeTarget) // bufferSize*maxBufferNumber = 128MB, which is the max memory used, which tend to be the case as its now // stalled by compaction instead of flush. // The buffer is not compressed unlike l0File, so to account for it, its size need to be slightly larger. - ulong bufferSize = (ulong)(16.MiB() / _perTableDbConfig.CompressibilityHint); - ulong l0FileSize = bufferSize * (ulong)_perTableDbConfig.MinWriteBufferNumberToMerge; + ulong targetFileSize = (ulong)16.MiB(); + ulong bufferSize = (ulong)(targetFileSize / _perTableDbConfig.CompressibilityHint); + ulong l0FileSize = targetFileSize * (ulong)_perTableDbConfig.MinWriteBufferNumberToMerge; ulong maxBufferNumber = 8; // Guide recommend to have l0 and l1 to be the same size. They have to be compacted together so if l1 is larger, From f768a42c7b5f735400d6e083113d189b418a69fa Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 13:21:26 +0800 Subject: [PATCH 12/14] Reduce aggressivenett of heavy write tune and set kOldestLargestSeqFirst --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 8 ++++---- src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index ff2c1346878..429f74ece24 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -68,7 +68,7 @@ public class DbConfig : IDbConfig public ulong? ReceiptsDbCompactionReadAhead { get; set; } public ulong ReceiptsDbTargetFileSizeBase { get; set; } = (ulong)64.MiB(); public double ReceiptsDbCompressibilityHint { get; set; } = 0.6; - public string? ReceiptsDbAdditionalRocksDbOptions { get; set; } + public string? ReceiptsDbAdditionalRocksDbOptions { get; set; } = "compaction_pri=kOldestLargestSeqFirst"; public ulong BlocksDbWriteBufferSize { get; set; } = (ulong)64.MiB(); public uint BlocksDbWriteBufferNumber { get; set; } = 2; @@ -80,7 +80,7 @@ public class DbConfig : IDbConfig public bool? BlocksDbUseDirectReads { get; set; } public bool? BlocksDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? BlocksDbCompactionReadAhead { get; set; } - public string? BlocksDbAdditionalRocksDbOptions { get; set; } + public string? BlocksDbAdditionalRocksDbOptions { get; set; } = "compaction_pri=kOldestLargestSeqFirst"; public ulong HeadersDbWriteBufferSize { get; set; } = (ulong)8.MiB(); public uint HeadersDbWriteBufferNumber { get; set; } = 2; @@ -92,7 +92,7 @@ public class DbConfig : IDbConfig public bool? HeadersDbUseDirectReads { get; set; } public bool? HeadersDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? HeadersDbCompactionReadAhead { get; set; } - public string? HeadersDbAdditionalRocksDbOptions { get; set; } + public string? HeadersDbAdditionalRocksDbOptions { get; set; } = "compaction_pri=kOldestLargestSeqFirst"; public ulong? HeadersDbMaxBytesForLevelBase { get; set; } = (ulong)128.MiB(); public ulong BlockNumbersDbWriteBufferSize { get; set; } = (ulong)8.MiB(); @@ -121,7 +121,7 @@ public class DbConfig : IDbConfig public bool? BlockInfosDbUseDirectReads { get; set; } public bool? BlockInfosDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? BlockInfosDbCompactionReadAhead { get; set; } - public string? BlockInfosDbAdditionalRocksDbOptions { get; set; } + public string? BlockInfosDbAdditionalRocksDbOptions { get; set; } = "compaction_pri=kOldestLargestSeqFirst"; public ulong PendingTxsDbWriteBufferSize { get; set; } = (ulong)4.MiB(); public uint PendingTxsDbWriteBufferNumber { get; set; } = 4; diff --git a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs index 7a566f41fa7..8b5ac589718 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs @@ -1500,7 +1500,7 @@ public virtual void Tune(ITunableDb.TuneType type) case ITunableDb.TuneType.HeavyWrite: // Compaction spikes are clear at this point. Will definitely affect attestation performance. // Its unclear if it improve or slow down sync time. Seems to be the sweet spot. - ApplyOptions(GetHeavyWriteOptions((ulong)4.GiB())); + ApplyOptions(GetHeavyWriteOptions((ulong)2.GiB())); break; case ITunableDb.TuneType.AggressiveHeavyWrite: // For when, you are desperate, but don't wanna disable compaction completely, because you don't want From 63b219506e6936353c8842cd7d0905a5fedcc1d3 Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 13:24:17 +0800 Subject: [PATCH 13/14] Adjust receipts db compressibility hint --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index 429f74ece24..eec2425ad06 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -67,7 +67,7 @@ public class DbConfig : IDbConfig public bool? ReceiptsDbUseDirectIoForFlushAndCompactions { get; set; } public ulong? ReceiptsDbCompactionReadAhead { get; set; } public ulong ReceiptsDbTargetFileSizeBase { get; set; } = (ulong)64.MiB(); - public double ReceiptsDbCompressibilityHint { get; set; } = 0.6; + public double ReceiptsDbCompressibilityHint { get; set; } = 0.35; public string? ReceiptsDbAdditionalRocksDbOptions { get; set; } = "compaction_pri=kOldestLargestSeqFirst"; public ulong BlocksDbWriteBufferSize { get; set; } = (ulong)64.MiB(); From 4806fb20d5afbe37b7511bf019551a7e3b730dda Mon Sep 17 00:00:00 2001 From: Amirul Ashraf Date: Wed, 5 Jun 2024 15:29:52 +0800 Subject: [PATCH 14/14] Adjust state db compressibility --- src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs index eec2425ad06..b18a43b70b5 100644 --- a/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs +++ b/src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs @@ -204,7 +204,7 @@ public class DbConfig : IDbConfig public int? StateDbUseRibbonFilterStartingFromLevel { get; set; } = 2; public double? StateDbDataBlockIndexUtilRatio { get; set; } = 0.5; public bool StateDbEnableFileWarmer { get; set; } = false; - public double StateDbCompressibilityHint { get; set; } = 0.75; + public double StateDbCompressibilityHint { get; set; } = 0.45; public string? StateDbAdditionalRocksDbOptions { get; set; } public uint RecycleLogFileNum { get; set; } = 0;