Skip to content

Commit

Permalink
fix metrics estimatedTxsPerSec (#3396)
Browse files Browse the repository at this point in the history
  • Loading branch information
agnusmor committed Feb 29, 2024
1 parent a3e1643 commit e2b5091
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sequencer/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ func (m *metrics) close(createdAt time.Time, txsCount int64) {
if m.txsCount > 0 {
// timePerTxuS is the average time spent per tx. This includes the l2Block time since the processing time of this section is proportional to the number of txs
timePerTxuS := (m.transactionsTimes.total() + m.l2BlockTimes.total()).Microseconds() / m.txsCount
m.estimatedTxsPerSec = float64(m.totalTime().Microseconds()-m.newL2BlockTimes.total().Microseconds()) / float64(timePerTxuS)
// estimatedTxs is the number of transactions that we estimate could have been processed in the block
estimatedTxs := float64(totalTime.Microseconds()-m.newL2BlockTimes.total().Microseconds()) / float64(timePerTxuS)
// estimatedTxxPerSec is the estimated transactions per second
m.estimatedTxsPerSec = float64(totalTime.Microseconds()) / estimatedTxs
}
}

Expand Down Expand Up @@ -151,7 +154,11 @@ func (i *intervalMetrics) addL2BlockMetrics(l2Block metrics) {
}

func (i *intervalMetrics) computeEstimatedTxsPerSec() {
i.estimatedTxsPerSec = i.estimatedTxsPerSecAcc / float64(i.estimatedTxsPerSecCount)
if i.estimatedTxsPerSecCount > 0 {
i.estimatedTxsPerSec = i.estimatedTxsPerSecAcc / float64(i.estimatedTxsPerSecCount)
} else {
i.estimatedTxsPerSecCount = 0
}
}

func (i *intervalMetrics) startsAt() time.Time {
Expand Down

0 comments on commit e2b5091

Please sign in to comment.