Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory use during Archive Sync #7407

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public void SetUp()
CreateStorage();
}

[TearDown]
public void TearDown()
{
_receiptsDb.Dispose();
}

private void CreateStorage()
{
_decoder = new ReceiptArrayStorageDecoder(_useCompactReceipts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ public virtual void Dispose()
{
CodeDb?.Dispose();
StateDb?.Dispose();
DbProvider.BlobTransactionsDb?.Dispose();
DbProvider.ReceiptsDb?.Dispose();
}

_trieStoreWatcher?.Dispose();
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Core.Test/TestMemColumnDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ public IColumnsWriteBatch<TKey> StartWriteBatch()
{
return new InMemoryColumnWriteBatch<TKey>(this);
}
public void Dispose() { }
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Db.Rpc/RpcColumnsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public IColumnsWriteBatch<T> StartWriteBatch()
{
return new InMemoryColumnWriteBatch<T>(this);
}
public void Dispose() { }
}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Db/IColumnsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Nethermind.Db
{
public interface IColumnsDb<TKey> : IDbMeta
public interface IColumnsDb<TKey> : IDbMeta, IDisposable
{
IDb GetColumnDb(TKey key);
IEnumerable<TKey> ColumnKeys { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Db/MemColumnsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public IColumnsWriteBatch<TKey> StartWriteBatch()
{
return new InMemoryColumnWriteBatch<TKey>(this);
}
public void Dispose() { }
}
}
8 changes: 6 additions & 2 deletions src/Nethermind/Nethermind.Trie/Pruning/TrieStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public readonly void Dispose()

// Track ALL of the recently re-committed persisted nodes. This is so that we don't accidentally remove
// recommitted persisted nodes (which will not get re-persisted).
private readonly ConcurrentDictionary<HashAndTinyPathAndHash, long> _persistedLastSeen = new(CollectionExtensions.LockPartitions, 4 * 4096);
private readonly ConcurrentDictionary<HashAndTinyPathAndHash, long>? _persistedLastSeen;
benaadams marked this conversation as resolved.
Show resolved Hide resolved

private bool _lastPersistedReachedReorgBoundary;
private Task _pruningTask = Task.CompletedTask;
Expand Down Expand Up @@ -323,6 +323,10 @@ public TrieStore(
_dirtyNodes = new DirtyNodesCache(this);
_publicStore = new TrieKeyValueStore(this);

if (pruningStrategy.PruningEnabled)
{
_persistedLastSeen = new(CollectionExtensions.LockPartitions, 4 * 4096);
}
if (pruningStrategy.TrackedPastKeyCount > 0 && nodeStorage.RequirePath)
{
_pastPathHash = new(pruningStrategy.TrackedPastKeyCount);
Expand Down Expand Up @@ -925,7 +929,7 @@ private void PruneCache(bool skipRecalculateMemory = false, KeyValuePair<DirtyNo
pruneAndRecalculateAction.Completion.Wait();
trackNodesAction?.Completion.Wait();

if (!skipRecalculateMemory) MemoryUsedByDirtyCache = newMemory + _persistedLastSeen.Count * 48;
if (!skipRecalculateMemory) MemoryUsedByDirtyCache = newMemory + (_persistedLastSeen?.Count ?? 0) * 48;
Metrics.CachedNodesCount = _dirtyNodes.Count;

stopwatch.Stop();
Expand Down