Skip to content

Commit 790c61b

Browse files
authored
feat(metrics): capture gas metrics from ApplyBlocks, tweak time buckets (#13030)
1 parent de8e486 commit 790c61b

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
- fix(eth): always return nil for eth transactions not found ([filecoin-project/lotus#12999](https://github.com/filecoin-project/lotus/pull/12999))
1313
- feat: add experimental v2 APIs that are "F3 aware." (TODO: expand this section significantly to cover where someone learns about the new APIs, how they enable them, and what expectations they should have around them—i.e., they may change)
14+
- feat: add gas to application metric reporting `vm/applyblocks_early_gas`, `vm/applyblocks_messages_gas`, `vm/applyblocks_cron_gas` ([filecoin-project/lotus#13030](https://github.com/filecoin-project/lotus/pull/13030))
1415

1516
# Node and Miner v1.32.2 / 2025-04-04
1617

chain/consensus/compute_state.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,13 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
306306

307307
log.Infow("ApplyBlocks stats", "early", vmEarly, "earlyCronGas", earlyCronGas, "vmMsg", vmMsg, "msgGas", msgGas, "vmCron", vmCron, "cronGas", cronGas, "vmFlush", vmFlush, "epoch", epoch, "tsk", ts.Key())
308308

309-
stats.Record(ctx, metrics.VMSends.M(int64(atomic.LoadUint64(&vm.StatSends))),
310-
metrics.VMApplied.M(int64(atomic.LoadUint64(&vm.StatApplied))))
309+
stats.Record(ctx,
310+
metrics.VMSends.M(int64(atomic.LoadUint64(&vm.StatSends))),
311+
metrics.VMApplied.M(int64(atomic.LoadUint64(&vm.StatApplied))),
312+
metrics.VMApplyEarlyGas.M(earlyCronGas),
313+
metrics.VMApplyMessagesGas.M(msgGas),
314+
metrics.VMApplyCronGas.M(cronGas),
315+
)
311316

312317
return st, rectroot, nil
313318
}

metrics/metrics.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ import (
1414
"github.com/filecoin-project/lotus/build/buildconstants"
1515
)
1616

17-
// Distribution
18-
var defaultMillisecondsDistribution = view.Distribution(0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 3000, 4000, 5000, 7500, 10000, 20000, 50000, 100_000, 250_000, 500_000, 1000_000)
17+
// Distributions
18+
var defaultMillisecondsDistribution = view.Distribution(
19+
0.01, 0.05, 0.1, 0.3, 0.6, 0.8, 1, 2, 3, 4, 5, 6, 8, // Very short intervals for fast operations
20+
10, 20, 30, 40, 50, 60, 70, 80, 90, 100, // 10 ms intervals up to 100 ms
21+
150, 200, 250, 300, 350, 400, 450, 500, // 50 ms intervals from 100 to 500 ms
22+
600, 700, 800, 900, 1000, // 100 ms intervals from 500 to 1000 ms
23+
1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, // 100 ms intervals from 1000 to 2000 ms
24+
3000, 4000, 5000, 6000, 8000, 10000, 13000, 16000, 20000, 25000, 30000, 40000, 50000, 65000, 80000, 100000,
25+
130_000, 160_000, 200_000, 250_000, 300_000, 400_000, 500_000, 650_000, 800_000, 1000_000, // Larger, less frequent buckets
26+
)
27+
1928
var workMillisecondsDistribution = view.Distribution(
2029
250, 500, 1000, 2000, 5000, 10_000, 30_000, 60_000, 2*60_000, 5*60_000, 10*60_000, 15*60_000, 30*60_000, // short sealing tasks
2130
40*60_000, 45*60_000, 50*60_000, 55*60_000, 60*60_000, 65*60_000, 70*60_000, 75*60_000, 80*60_000, 85*60_000, 100*60_000, 120*60_000, // PC2 / C2 range
@@ -114,6 +123,9 @@ var (
114123
VMApplyEarly = stats.Float64("vm/applyblocks_early", "Time spent in early apply-blocks (null cron, upgrades)", stats.UnitMilliseconds)
115124
VMApplyCron = stats.Float64("vm/applyblocks_cron", "Time spent in cron", stats.UnitMilliseconds)
116125
VMApplyFlush = stats.Float64("vm/applyblocks_flush", "Time spent flushing vm state", stats.UnitMilliseconds)
126+
VMApplyMessagesGas = stats.Int64("vm/applyblocks_messages_gas", "Total gas of block messages", stats.UnitDimensionless)
127+
VMApplyEarlyGas = stats.Int64("vm/applyblocks_early_gas", "Total gas of early apply-blocks (null cron, upgrades)", stats.UnitDimensionless)
128+
VMApplyCronGas = stats.Int64("vm/applyblocks_cron_gas", "Total gas of cron", stats.UnitDimensionless)
117129
VMSends = stats.Int64("vm/sends", "Counter for sends processed by the VM", stats.UnitDimensionless)
118130
VMApplied = stats.Int64("vm/applied", "Counter for messages (including internal messages) processed by the VM", stats.UnitDimensionless)
119131
VMExecutionWaiting = stats.Int64("vm/execution_waiting", "Counter for VM executions waiting to be assigned to a lane", stats.UnitDimensionless)
@@ -399,6 +411,21 @@ var (
399411
Aggregation: defaultMillisecondsDistribution,
400412
TagKeys: []tag.Key{Network},
401413
}
414+
VMApplyEarlyGasView = &view.View{
415+
Measure: VMApplyEarlyGas,
416+
Aggregation: view.LastValue(),
417+
TagKeys: []tag.Key{Network},
418+
}
419+
VMApplyMessagesGasView = &view.View{
420+
Measure: VMApplyMessagesGas,
421+
Aggregation: view.LastValue(),
422+
TagKeys: []tag.Key{Network},
423+
}
424+
VMApplyCronGasView = &view.View{
425+
Measure: VMApplyCronGas,
426+
Aggregation: view.LastValue(),
427+
TagKeys: []tag.Key{Network},
428+
}
402429
VMSendsView = &view.View{
403430
Measure: VMSends,
404431
Aggregation: view.LastValue(),
@@ -788,6 +815,9 @@ var ChainNodeViews = append([]*view.View{
788815
VMApplyEarlyView,
789816
VMApplyCronView,
790817
VMApplyFlushView,
818+
VMApplyEarlyGasView,
819+
VMApplyMessagesGasView,
820+
VMApplyCronGasView,
791821
VMSendsView,
792822
VMAppliedView,
793823
VMExecutionWaitingView,

0 commit comments

Comments
 (0)