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

perf: improve metric performance #287

Closed
wants to merge 3 commits into from
Closed

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Jun 16, 2022

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

@dapplion
Copy link
Contributor

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?

@codecov-commenter
Copy link

Codecov Report

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

❗ 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%) ⬆️
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.

@twoeths
Copy link
Contributor Author

twoeths commented Jun 28, 2023

closing as this PR was merged #433

@twoeths twoeths closed this Jun 28, 2023
@twoeths twoeths deleted the tuyen/reduce-metrics branch June 28, 2023 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants