Skip to content

Commit

Permalink
Remove db throttling (#6438)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Dec 29, 2023
1 parent c4767a4 commit 087b06a
Showing 1 changed file with 4 additions and 23 deletions.
27 changes: 4 additions & 23 deletions src/Nethermind/Nethermind.Db.Rocks/DbOnTheRocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Net.Sockets;
using System.Reflection;
using System.Threading;
using ConcurrentCollections;
Expand All @@ -15,7 +14,6 @@
using Nethermind.Core.Crypto;
using Nethermind.Core.Exceptions;
using Nethermind.Core.Extensions;
using Nethermind.Core.Threading;
using Nethermind.Db.Rocks.Config;
using Nethermind.Db.Rocks.Statistics;
using Nethermind.Logging;
Expand All @@ -26,9 +24,6 @@ namespace Nethermind.Db.Rocks;

public class DbOnTheRocks : IDb, ITunableDb
{
private McsPriorityLock _readThrottle = new();
private McsPriorityLock _writeThrottle = new();

private ILogger _logger;

private string? _fullPath;
Expand Down Expand Up @@ -505,7 +500,6 @@ private static WriteOptions CreateWriteOptions(PerTableDbConfig dbConfig)
}
}

using var handle = _readThrottle.Acquire();
return _db.Get(key, cf);
}
catch (RocksDbSharpException e)
Expand All @@ -528,7 +522,6 @@ internal void SetWithColumnFamily(ReadOnlySpan<byte> key, ColumnFamilyHandle? cf

try
{
using var handle = _writeThrottle.Acquire();
if (value.IsNull())
{
_db.Remove(key, cf, WriteFlagsToWriteOptions(flags));
Expand Down Expand Up @@ -572,7 +565,6 @@ internal void SetWithColumnFamily(ReadOnlySpan<byte> key, ColumnFamilyHandle? cf
{
try
{
using var handle = _readThrottle.Acquire();
return _db.MultiGet(keys);
}
catch (RocksDbSharpException e)
Expand All @@ -596,11 +588,8 @@ internal Span<byte> GetSpanWithColumnFamily(ReadOnlySpan<byte> key, ColumnFamily

try
{
Span<byte> span;
using (var handle = _readThrottle.Acquire())
{
span = _db.GetSpan(key, cf);
}
Span<byte> span = _db.GetSpan(key, cf);

if (!span.IsNullOrEmpty())
{
Interlocked.Increment(ref _allocatedSpan);
Expand Down Expand Up @@ -636,7 +625,6 @@ public void Remove(ReadOnlySpan<byte> key)

try
{
using var handle = _writeThrottle.Acquire();
_db.Remove(key, null, WriteOptions);
}
catch (RocksDbSharpException e)
Expand Down Expand Up @@ -824,7 +812,6 @@ public bool KeyExists(ReadOnlySpan<byte> key)

try
{
using var handle = _readThrottle.Acquire();
// seems it has no performance impact
return _db.Get(key) is not null;
// return _db.Get(key, 32, _keyExistsBuffer, 0, 0, null, null) != -1;
Expand Down Expand Up @@ -903,10 +890,7 @@ public void Dispose()

try
{
using (var handle = _dbOnTheRocks._writeThrottle.Acquire())
{
_dbOnTheRocks._db.Write(_rocksBatch, _dbOnTheRocks.WriteFlagsToWriteOptions(_writeFlags));
}
_dbOnTheRocks._db.Write(_rocksBatch, _dbOnTheRocks.WriteFlagsToWriteOptions(_writeFlags));

_dbOnTheRocks._currentBatches.TryRemove(this);
ReturnWriteBatch(_rocksBatch);
Expand Down Expand Up @@ -960,10 +944,7 @@ private void FlushOnTooManyWrites()

try
{
using (var handle = _dbOnTheRocks._writeThrottle.Acquire())
{
_dbOnTheRocks._db.Write(currentBatch, _dbOnTheRocks.WriteFlagsToWriteOptions(_writeFlags));
}
_dbOnTheRocks._db.Write(currentBatch, _dbOnTheRocks.WriteFlagsToWriteOptions(_writeFlags));
ReturnWriteBatch(currentBatch);
}
catch (RocksDbSharpException e)
Expand Down

0 comments on commit 087b06a

Please sign in to comment.