Skip to content

Commit

Permalink
Reduce rate of sending blocks when batch bloks are being processed (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaszRozmej authored Mar 28, 2022
1 parent 0ccea4d commit d184113
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Nethermind.Blockchain;
Expand All @@ -33,6 +34,7 @@
using Nethermind.TxPool;
using Websocket.Client;
using Block = Nethermind.Core.Block;
using Timer = System.Timers.Timer;
using Transaction = Nethermind.EthStats.Messages.Models.Transaction;

namespace Nethermind.EthStats.Integrations
Expand Down Expand Up @@ -62,7 +64,7 @@ public class EthStatsIntegration : IEthStatsIntegration
private bool _connected;
private long _lastBlockProcessedTimestamp;
private Timer? _timer;
private const int ThrottlingThreshold = 25;
private const int ThrottlingThreshold = 250;
private const int SendStatsInterval = 1000;

public EthStatsIntegration(
Expand Down Expand Up @@ -146,13 +148,11 @@ private void Run(Timer timer)

private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
{
if (!_connected)
if (_connected)
{
return;
if (_logger.IsDebug) _logger.Debug("ETH Stats sending 'stats' message...");
SendStatsAsync();
}

if (_logger.IsDebug) _logger.Debug("ETH Stats sending 'stats' message...");
SendStatsAsync();
}

private void BlockTreeOnNewHeadBlock(object? sender, BlockEventArgs e)
Expand All @@ -164,7 +164,7 @@ private void BlockTreeOnNewHeadBlock(object? sender, BlockEventArgs e)
return;
}

long timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds();
long timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
if (timestamp - _lastBlockProcessedTimestamp < ThrottlingThreshold)
{
return;
Expand Down

0 comments on commit d184113

Please sign in to comment.