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

Set metrics consistently before request completion #7599

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -397,6 +397,7 @@ private void FireProcessingQueueEmpty()

_stopwatch.Restart();
Block[]? processedBlocks = ProcessBranch(processingBranch, options, tracer, out error);
_stopwatch.Stop();
if (processedBlocks is null)
{
return null;
Expand All @@ -414,33 +415,32 @@ private void FireProcessingQueueEmpty()
if (_logger.IsDebug) _logger.Debug($"Skipped processing of {suggestedBlock.ToString(Block.Format.FullHashAndNumber)}, last processed is null: {true}, processedBlocks.Length: {processedBlocks.Length}");
}

bool readonlyChain = options.ContainsFlag(ProcessingOptions.ReadOnlyChain);
if (!readonlyChain)
{
long blockProcessingTimeInMicrosecs = _stopwatch.ElapsedMicroseconds();
Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMicrosecs / 1000;
Metrics.RecoveryQueueSize = _recoveryQueue.Count;
Metrics.ProcessingQueueSize = _blockQueue.Count;
_stats.UpdateStats(lastProcessed, blockProcessingTimeInMicrosecs);
}

bool updateHead = !options.ContainsFlag(ProcessingOptions.DoNotUpdateHead);
if (updateHead)
{
if (_logger.IsTrace) _logger.Trace($"Updating main chain: {lastProcessed}, blocks count: {processedBlocks.Length}");
_blockTree.UpdateMainChain(processingBranch.Blocks, true);
}

bool readonlyChain = options.ContainsFlag(ProcessingOptions.ReadOnlyChain);
long blockProcessingTimeInMs = _stopwatch.ElapsedMilliseconds;
if (!readonlyChain)
{
Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMs;
}

if ((options & ProcessingOptions.MarkAsProcessed) == ProcessingOptions.MarkAsProcessed)
{
if (_logger.IsTrace) _logger.Trace($"Marked blocks as processed {lastProcessed}, blocks count: {processedBlocks.Length}");
_blockTree.MarkChainAsProcessed(processingBranch.Blocks);

Metrics.LastBlockProcessingTimeInMs = blockProcessingTimeInMs;
}

if (!readonlyChain)
{
Metrics.RecoveryQueueSize = _recoveryQueue.Count;
Metrics.ProcessingQueueSize = _blockQueue.Count;
_stats.UpdateStats(lastProcessed, _blockTree, _stopwatch.ElapsedMicroseconds());
Metrics.BestKnownBlockNumber = _blockTree.BestKnownNumber;
}

return lastProcessed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public ProcessingStats(ILogger logger)
#endif
}

public void UpdateStats(Block? block, IBlockTree blockTreeCtx, long blockProcessingTimeInMicros)
public void UpdateStats(Block? block, long blockProcessingTimeInMicros)
{
if (block is null)
{
Expand All @@ -82,7 +82,6 @@ public void UpdateStats(Block? block, IBlockTree blockTreeCtx, long blockProcess
Metrics.GasLimit = block.GasLimit;

Metrics.BlockchainHeight = block.Header.Number;
Metrics.BestKnownBlockNumber = blockTreeCtx.BestKnownNumber;

_blockProcessingMicroseconds = _processingStopwatch.ElapsedMicroseconds();
_runningMicroseconds = _runStopwatch.ElapsedMicroseconds();
Expand Down
Loading