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

feat: metric for block exec, commit and tx recheck #132

Merged
merged 1 commit into from
Oct 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions mempool/clist_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@ func (mem *CListMempool) Update(
if mem.Size() > 0 {
if mem.config.Recheck {
mem.logger.Info("Recheck txs", "numtxs", mem.Size(), "height", height)

recheckStartTime := time.Now().UnixNano()
mem.recheckTxs()
recheckEndTime := time.Now().UnixNano()

recheckTimeMs := float64(recheckEndTime-recheckStartTime) / 1000000
mem.metrics.RecheckingTime.Set(recheckTimeMs)

// At this point, mem.txs are being rechecked.
// mem.recheckCursor re-scans mem.txs and possibly removes some txs.
// Before mem.Reap(), we should wait for mem.recheckCursor to be nil.
Expand Down
17 changes: 13 additions & 4 deletions mempool/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type Metrics struct {
FailedTxs metrics.Counter
// Number of times transactions are rechecked in the mempool.
RecheckTimes metrics.Counter
// Time of Rechecking
RecheckingTime metrics.Gauge
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand Down Expand Up @@ -60,15 +62,22 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Name: "recheck_times",
Help: "Number of times transactions are rechecked in the mempool.",
}, labels).With(labelsAndValues...),
RecheckingTime: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "rechecking_time",
Help: "Time of Rechecking in ms.",
}, labels).With(labelsAndValues...),
}
}

// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
Size: discard.NewGauge(),
TxSizeBytes: discard.NewHistogram(),
FailedTxs: discard.NewCounter(),
RecheckTimes: discard.NewCounter(),
Size: discard.NewGauge(),
TxSizeBytes: discard.NewHistogram(),
FailedTxs: discard.NewCounter(),
RecheckTimes: discard.NewCounter(),
RecheckingTime: discard.NewGauge(),
}
}
16 changes: 13 additions & 3 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ func (blockExec *BlockExecutor) ApplyBlock(
return state, 0, ErrInvalidBlock(err)
}

startTime := time.Now().UnixNano()
execStartTime := time.Now().UnixNano()
abciResponses, err := execBlockOnProxyApp(blockExec.logger, blockExec.proxyApp, block, blockExec.db)
endTime := time.Now().UnixNano()
blockExec.metrics.BlockProcessingTime.Observe(float64(endTime-startTime) / 1000000)
execEndTime := time.Now().UnixNano()

execTimeMs := float64(execEndTime-execStartTime) / 1000000
blockExec.metrics.BlockProcessingTime.Observe(execTimeMs)
blockExec.metrics.BlockExecutionTime.Set(execTimeMs)

if err != nil {
return state, 0, ErrProxyAppConn(err)
}
Expand Down Expand Up @@ -167,7 +171,13 @@ func (blockExec *BlockExecutor) ApplyBlock(
}

// Lock mempool, commit app state, update mempoool.
commitStartTime := time.Now().UnixNano()
appHash, retainHeight, err := blockExec.Commit(state, block, abciResponses.DeliverTxs)
commitEndTime := time.Now().UnixNano()

commitTimeMs := float64(commitEndTime-commitStartTime) / 1000000
blockExec.metrics.BlockCommitTime.Set(commitTimeMs)

if err != nil {
return state, 0, fmt.Errorf("commit failed for application: %v", err)
}
Expand Down
18 changes: 18 additions & 0 deletions state/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
type Metrics struct {
// Time between BeginBlock and EndBlock.
BlockProcessingTime metrics.Histogram
// Time between BeginBlock and EndBlock.
BlockExecutionTime metrics.Gauge
// Time of Commit
BlockCommitTime metrics.Gauge
}

// PrometheusMetrics returns Metrics build using Prometheus client library.
Expand All @@ -35,12 +39,26 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
Help: "Time between BeginBlock and EndBlock in ms.",
Buckets: stdprometheus.LinearBuckets(1, 10, 10),
}, labels).With(labelsAndValues...),
BlockExecutionTime: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "block_execution_time",
Help: "Time between BeginBlock and EndBlock in ms.",
}, labels).With(labelsAndValues...),
BlockCommitTime: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: MetricsSubsystem,
Name: "block_commit_time",
Help: "Time of Commit in ms.",
}, labels).With(labelsAndValues...),
}
}

// NopMetrics returns no-op Metrics.
func NopMetrics() *Metrics {
return &Metrics{
BlockProcessingTime: discard.NewHistogram(),
BlockExecutionTime: discard.NewGauge(),
BlockCommitTime: discard.NewGauge(),
}
}