Skip to content

Commit

Permalink
Diagnostics: refactor bulk execution thread safety (#11143)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvovk authored Jul 13, 2024
1 parent b8c9187 commit 6bb5d8b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
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
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

0 comments on commit 6bb5d8b

Please sign in to comment.