Skip to content

Commit

Permalink
Perf/Reduce number of files in DB. (#6165)
Browse files Browse the repository at this point in the history
* Expose target file size base and multiplier

* Adjust blob file count

* Whitespace
  • Loading branch information
asdacap authored Oct 7, 2023
1 parent a33737e commit d524775
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/DbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class DbConfig : IDbConfig
public ulong? CompactionReadAhead { get; set; }
public IDictionary<string, string>? AdditionalRocksDbOptions { get; set; }
public ulong? MaxBytesForLevelBase { get; set; } = (ulong)256.MiB();
public ulong TargetFileSizeBase { get; set; } = (ulong)64.MiB();
public int TargetFileSizeMultiplier { get; set; } = 1;

public ulong ReceiptsDbWriteBufferSize { get; set; } = (ulong)8.MiB();
public uint ReceiptsDbWriteBufferNumber { get; set; } = 4;
Expand All @@ -38,6 +40,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 IDictionary<string, string>? ReceiptsDbAdditionalRocksDbOptions { get; set; }

public ulong BlocksDbWriteBufferSize { get; set; } = (ulong)8.MiB();
Expand Down Expand Up @@ -157,6 +160,7 @@ public class DbConfig : IDbConfig
public bool? StateDbUseDirectIoForFlushAndCompactions { get; set; } = false;
public ulong? StateDbCompactionReadAhead { get; set; }
public bool? StateDbDisableCompression { get; set; } = false;
public int StateDbTargetFileSizeMultiplier { get; set; } = 2;
public IDictionary<string, string>? StateDbAdditionalRocksDbOptions { get; set; }

public uint RecycleLogFileNum { get; set; } = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/IDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface IDbConfig : IConfig
ulong? CompactionReadAhead { get; set; }
IDictionary<string, string>? AdditionalRocksDbOptions { get; set; }
ulong? MaxBytesForLevelBase { get; set; }
ulong TargetFileSizeBase { get; set; }
int TargetFileSizeMultiplier { get; set; }

ulong ReceiptsDbWriteBufferSize { get; set; }
uint ReceiptsDbWriteBufferNumber { get; set; }
Expand All @@ -39,6 +41,7 @@ public interface IDbConfig : IConfig
bool? ReceiptsDbUseDirectReads { get; set; }
bool? ReceiptsDbUseDirectIoForFlushAndCompactions { get; set; }
ulong? ReceiptsDbCompactionReadAhead { get; set; }
ulong ReceiptsDbTargetFileSizeBase { get; set; }
IDictionary<string, string>? ReceiptsDbAdditionalRocksDbOptions { get; set; }

ulong BlocksDbWriteBufferSize { get; set; }
Expand Down Expand Up @@ -157,6 +160,7 @@ public interface IDbConfig : IConfig
bool? StateDbUseDirectIoForFlushAndCompactions { get; set; }
ulong? StateDbCompactionReadAhead { get; set; }
bool? StateDbDisableCompression { get; set; }
int StateDbTargetFileSizeMultiplier { get; set; }
IDictionary<string, string>? StateDbAdditionalRocksDbOptions { get; set; }

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public PerTableDbConfig(IDbConfig dbConfig, RocksDbSettings rocksDbSettings, str
public bool? DisableCompression => ReadConfig<bool?>(nameof(DisableCompression));
public ulong? CompactionReadAhead => ReadConfig<ulong?>(nameof(CompactionReadAhead));
public ulong MaxBytesForLevelBase => ReadConfig<ulong>(nameof(MaxBytesForLevelBase));
public ulong TargetFileSizeBase => ReadConfig<ulong>(nameof(TargetFileSizeBase));
public int TargetFileSizeMultiplier => ReadConfig<int>(nameof(TargetFileSizeMultiplier));

private T? ReadConfig<T>(string propertyName)
{
Expand Down
17 changes: 15 additions & 2 deletions src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,13 @@ protected virtual void BuildOptions<T>(PerTableDbConfig dbConfig, Options<T> opt
options.SetMaxOpenFiles(dbConfig.MaxOpenFiles.Value);
}

// Target size of each SST file.
options.SetTargetFileSizeBase(dbConfig.TargetFileSizeBase);

// Multiply the target size of SST file by this much every level down. Does not have much downside on
// hash based DB, but might disable some move optimization on db with blocknumber key.
options.SetTargetFileSizeMultiplier(dbConfig.TargetFileSizeMultiplier);

if (dbConfig.MaxBytesPerSec.HasValue)
{
_rateLimiter =
Expand Down Expand Up @@ -1159,7 +1166,7 @@ private IDictionary<string, string> GetStandardOptions()
{ "level0_stop_writes_trigger", 36.ToString() },

{ "max_bytes_for_level_base", _perTableDbConfig.MaxBytesForLevelBase.ToString() },
{ "target_file_size_base", 64.MiB().ToString() },
{ "target_file_size_base", _perTableDbConfig.TargetFileSizeBase.ToString() },
{ "disable_auto_compactions", "false" },

{ "enable_blob_files", "false" },
Expand Down Expand Up @@ -1249,7 +1256,13 @@ private IDictionary<string, string> GetBlobFilesOptions()
{
{ "enable_blob_files", "true" },
{ "blob_compression_type", "kSnappyCompression" },
{ "write_buffer_size", 64.MiB().ToString() },

// Make file size big, so we have less of them.
{ "write_buffer_size", 256.MiB().ToString() },
// Current memtable + 2 concurrent writes. Can't have too many of these as it take up RAM.
{ "max_write_buffer_number", 3.ToString() },

// These two are SST files instead of the blobs, which are now much smaller.
{ "max_bytes_for_level_base", 4.MiB().ToString() },
{ "target_file_size_base", 1.MiB().ToString() },
};
Expand Down

0 comments on commit d524775

Please sign in to comment.