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

Move detailed peer logging to debug, add diversity #5795

Merged
merged 11 commits into from
Jun 12, 2023
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
66 changes: 59 additions & 7 deletions src/Nethermind/Nethermind.Synchronization/Peers/SyncPeersReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ public SyncPeersReport(ISyncPeerPool peerPool, INodeStatsManager statsManager, I

public void WriteFullReport()
{
lock (_writeLock)
if (!_logger.IsDebug)
{
if (!_logger.IsInfo)
{
return;
}
return;
}

lock (_writeLock)
{
RememberState(out bool _);

_logger.Info(MakeReportForPeer(OrderedPeers, $"Sync peers - Initialized: {_currentInitializedPeerCount} | All: {_peerPool.PeerCount} | Max: {_peerPool.PeerMaxCount}"));
_logger.Debug(MakeSummaryReportForPeers(_peerPool.InitializedPeers, $"Sync peers - Connected: {_currentInitializedPeerCount} | All: {_peerPool.PeerCount} | Max: {_peerPool.PeerMaxCount}"));
_logger.Debug(MakeReportForPeer(OrderedPeers, ""));
}
}

Expand All @@ -69,7 +70,58 @@ public void WriteAllocatedReport()
return;
}

_logger.Info(MakeReportForPeer(OrderedPeers.Where(p => (p.AllocatedContexts & AllocationContexts.All) != AllocationContexts.None), $"Allocated sync peers {_currentInitializedPeerCount}({_peerPool.PeerCount})/{_peerPool.PeerMaxCount}"));
var header = $"Allocated sync peers {_currentInitializedPeerCount}({_peerPool.PeerCount})/{_peerPool.PeerMaxCount}";
if (_logger.IsDebug)
{
_logger.Debug(MakeReportForPeer(OrderedPeers.Where(p => (p.AllocatedContexts & AllocationContexts.All) != AllocationContexts.None), header));
}
else
{
_logger.Info(MakeSummaryReportForPeers(_peerPool.InitializedPeers, header));
}
}
}

internal string? MakeSummaryReportForPeers(IEnumerable<PeerInfo> peers, string header)
{
lock (_writeLock)
{
IEnumerable<IGrouping<string, PeerInfo>> peerGroups = peers.GroupBy(peerInfo => ParseClientInfo(peerInfo.SyncPeer.ClientId));
benaadams marked this conversation as resolved.
Show resolved Hide resolved
float sum = peerGroups.Sum(x => x.Count());

_stringBuilder.Append(header);
_stringBuilder.Append(" |");

bool isFirst = true;
foreach (var peerGroup in peerGroups.OrderByDescending(x => x.Count()))
{
if (isFirst)
{
isFirst = false;
}
else
{
_stringBuilder.Append(',');
}
_stringBuilder.Append($" {peerGroup.Key} ({peerGroup.Count() / sum,6:P2})");
}

string result = _stringBuilder.ToString();
_stringBuilder.Clear();
return result;
}
}

private string ParseClientInfo(string clientInfo)
{
int index = clientInfo.IndexOf('/');
if (index > 0)
{
return clientInfo[..index];
}
else
{
return "Unknown";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ private void SyncModeSelectorOnChanged(object? sender, SyncModeChangedEventArgs

private void TimerOnElapsed(object? sender, EventArgs e)
{
if (_reportId % SyncReportFrequency == 0)
{
WriteSyncReport();
}

if (_reportId % SyncFullPeersReportFrequency == 0)
{
_syncPeersReport.WriteFullReport();
Expand All @@ -88,6 +83,10 @@ private void TimerOnElapsed(object? sender, EventArgs e)
{
_syncPeersReport.WriteAllocatedReport();
}
else if (_reportId % SyncReportFrequency == 0)
{
WriteSyncReport();
}

_reportId++;

Expand Down Expand Up @@ -174,7 +173,7 @@ private void WriteSyncReport()
{
if (_reportId % PeerCountFrequency == 0)
{
_logger.Info($"Peers | with known best block: {_syncPeerPool.InitializedPeersCount} | all: {_syncPeerPool.PeerCount} |");
_logger.Info(_syncPeersReport.MakeSummaryReportForPeers(_syncPeerPool.InitializedPeers, $"Peers | with known best block: {_syncPeerPool.InitializedPeersCount} | all: {_syncPeerPool.PeerCount}"));
}
}

Expand Down