js-libp2p-gossipsub icon indicating copy to clipboard operation
js-libp2p-gossipsub copied to clipboard

perf: improve metric performance

Open twoeths opened this issue 3 years ago • 2 comments
trafficstars

Motivation

  • gauge.inc() takes 2.45% cpu time which is > 2 / 3 runHeartbeat() cpu time

Description

  • gauge.inc() will hash the label objects and push to Map every time we call it
  • so we we write some cached gauge metric class to only do that when scrape
    • gauge has no label: use NoLabelCachedGauge, this gives 7x improvement
    • gauge has 1 label: use OneLabelCachedGauge, this gives 1.2x improvement
    • gauge has 2 labels: use TwoLabelCachedGauge, this gives 2.5x improvement
  • also remove unnecessary gauge metric

twoeths avatar Jun 16 '22 12:06 twoeths

also remove unnecessary gauge metric

@tuyennhv Could you do this item in a separate PR?

About the optimization, is it best to do it here or on Lodestar?

dapplion avatar Jun 16 '22 14:06 dapplion

Codecov Report

Merging #287 (43db65b) into master (475c861) will decrease coverage by 1.50%. The diff coverage is 21.06%.

:exclamation: Current head 43db65b differs from pull request most recent head dc3c677. Consider uploading reports for the commit dc3c677 to get more accurate results

@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
- Coverage   80.46%   78.96%   -1.51%     
==========================================
  Files          42       42              
  Lines        9102     9384     +282     
  Branches      826      825       -1     
==========================================
+ Hits         7324     7410      +86     
- Misses       1778     1974     +196     
Impacted Files Coverage Δ
src/metrics.ts 25.20% <21.02%> (+2.11%) :arrow_up:
src/index.ts 69.42% <25.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 475c861...dc3c677. Read the comment docs.

codecov-commenter avatar Jun 17 '22 04:06 codecov-commenter

closing as this PR was merged https://github.com/ChainSafe/js-libp2p-gossipsub/pull/433

twoeths avatar Jun 28 '23 02:06 twoeths