Skip to content

Commit

Permalink
Merge pull request #2357 from 0chain/new_metrics
Browse files Browse the repository at this point in the history
New metrics state and events computation times
  • Loading branch information
dabasov committed May 5, 2023
2 parents a772384 + a3b7751 commit 32b075e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion code/go/0chain.net/chaincore/chain/protocol_block.go
Expand Up @@ -378,13 +378,14 @@ func (c *Chain) finalizeBlock(ctx context.Context, fb *block.Block, bsh BlockSta
logging.Logger.Error("emit update block event error", zap.Error(err))
}
fb.Events = append(fb.Events, ev)

ts := time.Now()
if err := c.GetEventDb().ProcessEvents(ctx, fb.Events, fb.Round, fb.Hash, len(fb.Txns)); err != nil {
logging.Logger.Error("finalize block - add events failed",
zap.Error(err),
zap.Int64("round", fb.Round),
zap.String("hash", fb.Hash))
}
EventsComputationTimer.Update(time.Since(ts).Microseconds())
fb.Events = nil
})
}
Expand Down
9 changes: 8 additions & 1 deletion code/go/0chain.net/chaincore/chain/state.go
Expand Up @@ -31,9 +31,13 @@ import (

// SmartContractExecutionTimer - a metric that tracks the time it takes to execute a smart contract txn
var SmartContractExecutionTimer metrics.Timer
var StateComputationTimer metrics.Histogram
var EventsComputationTimer metrics.Histogram

func init() {
SmartContractExecutionTimer = metrics.GetOrRegisterTimer("sc_execute_timer", nil)
StateComputationTimer = metrics.NewHistogram(metrics.NewUniformSample(1024))
EventsComputationTimer = metrics.NewHistogram(metrics.NewUniformSample(1024))
}

var ErrWrongNonce = common.NewError("wrong_nonce", "nonce of sender is not valid")
Expand Down Expand Up @@ -76,7 +80,10 @@ func (c *Chain) ComputeOrSyncState(ctx context.Context, b *block.Block) error {
}

func (c *Chain) computeState(ctx context.Context, b *block.Block, waitC ...chan struct{}) error {
return b.ComputeState(ctx, c, waitC...)
timer := time.Now()
err := b.ComputeState(ctx, c, waitC...)
StateComputationTimer.Update(time.Since(timer).Microseconds())
return err
}

// SaveChanges - persist the state changes
Expand Down
8 changes: 8 additions & 0 deletions code/go/0chain.net/sharder/handler.go
Expand Up @@ -225,6 +225,14 @@ func ChainStatsWriter(w http.ResponseWriter, r *http.Request) {
diagnostics.WriteTimerStatistics(w, c, chain.StatePruneDeleteTimer, 1000000.0)
fmt.Fprintf(w, "</td></tr>")

fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<h3>State Computation Statistics</h3>")
diagnostics.WriteHistogramStatistics(w, c, chain.StateComputationTimer)
fmt.Fprintf(w, "</td><td valign='top'>")
fmt.Fprintf(w, "<h3>Events Computation Statistics</h3>")
diagnostics.WriteHistogramStatistics(w, c, chain.EventsComputationTimer)
fmt.Fprintf(w, "</td></tr>")

if c.GetPruneStats() != nil {
fmt.Fprintf(w, "<tr><td>")
fmt.Fprintf(w, "<h3>Prune Stats</h3>")
Expand Down

0 comments on commit 32b075e

Please sign in to comment.