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

Diagnostics: refactor bulk execution thread safety #11143

Merged
merged 5 commits into from
Jul 13, 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
46 changes: 42 additions & 4 deletions erigon-lib/diagnostics/block_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,45 @@ package diagnostics

import (
"context"
"encoding/json"
"io"
"sync"

"github.com/ledgerwatch/erigon-lib/log/v3"
)

type BlockEexcStatsData struct {
data BlockExecutionStatistics
mu sync.Mutex
}

type BlockExecutionStatistics struct {
From uint64 `json:"from"`
To uint64 `json:"to"`
BlockNumber uint64 `json:"blockNumber"`
BlkPerSec float64 `json:"blkPerSec"`
TxPerSec float64 `json:"txPerSec"`
MgasPerSec float64 `json:"mgasPerSec"`
GasState float64 `json:"gasState"`
Batch uint64 `json:"batch"`
Alloc uint64 `json:"alloc"`
Sys uint64 `json:"sys"`
TimeElapsed float64 `json:"timeElapsed"`
}

func (b *BlockEexcStatsData) SetData(d BlockExecutionStatistics) {
b.mu.Lock()
defer b.mu.Unlock()
b.data = d
}

func (b *BlockEexcStatsData) Data() (d BlockExecutionStatistics) {
b.mu.Lock()
d = b.data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this trick works until class doesn't have map/slice fields

b.mu.Unlock()
return
}

func (d *DiagnosticClient) setupBlockExecutionDiagnostics(rootCtx context.Context) {
d.runBlockExecutionListener(rootCtx)
}
Expand All @@ -37,14 +72,17 @@ func (d *DiagnosticClient) runBlockExecutionListener(rootCtx context.Context) {
case <-rootCtx.Done():
return
case info := <-ch:
d.mu.Lock()
d.syncStats.BlockExecution = info
d.mu.Unlock()

d.BlockExecution.SetData(info)
if d.syncStats.SyncFinished {
return
}
}
}
}()
}

func (d *DiagnosticClient) BlockExecutionInfoJson(w io.Writer) {
if err := json.NewEncoder(w).Encode(d.BlockExecution.Data()); err != nil {
log.Debug("[diagnostics] BlockExecutionInfoJson", "err", err)
}
}
1 change: 1 addition & 0 deletions erigon-lib/diagnostics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type DiagnosticClient struct {

syncStages []SyncStage
syncStats SyncStatistics
BlockExecution BlockEexcStatsData
snapshotFileList SnapshoFilesList
mu sync.Mutex
headerMutex sync.Mutex
Expand Down
14 changes: 0 additions & 14 deletions erigon-lib/diagnostics/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ type SyncStatistics struct {
SnapshotDownload SnapshotDownloadStatistics `json:"snapshotDownload"`
SnapshotIndexing SnapshotIndexingStatistics `json:"snapshotIndexing"`
SnapshotFillDB SnapshotFillDBStatistics `json:"snapshotFillDB"`
BlockExecution BlockExecutionStatistics `json:"blockExecution"`
SyncFinished bool `json:"syncFinished"`
}

Expand Down Expand Up @@ -167,19 +166,6 @@ type SnapshotFillDBStageUpdate struct {
Stage SnapshotFillDBStage `json:"stage"`
TimeElapsed float64 `json:"timeElapsed"`
}
type BlockExecutionStatistics struct {
From uint64 `json:"from"`
To uint64 `json:"to"`
BlockNumber uint64 `json:"blockNumber"`
BlkPerSec float64 `json:"blkPerSec"`
TxPerSec float64 `json:"txPerSec"`
MgasPerSec float64 `json:"mgasPerSec"`
GasState float64 `json:"gasState"`
Batch uint64 `json:"batch"`
Alloc uint64 `json:"alloc"`
Sys uint64 `json:"sys"`
TimeElapsed float64 `json:"timeElapsed"`
}

type SnapshoFilesList struct {
Files []string `json:"files"`
Expand Down
Loading