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

Reduce cost of no attribute counters #1519

Merged

Conversation

KallDrexx
Copy link
Contributor

@KallDrexx KallDrexx commented Feb 8, 2024

Fixes #
Design discussion issue (if applicable) #

Changes

This PR utilizes atomics to make counters fast when an empty set of attributes are passed in. This atomic bypasses the hashmap lookups and mutex locking.

Benchmarks

main

Counter/AddNoAttrs      time:   [59.516 ns 59.947 ns 60.457 ns]
Found 6 outliers among 100 measurements (6.00%)
  2 (2.00%) high mild
  4 (4.00%) high severe

Counter/AddNoAttrsDelta time:   [62.342 ns 63.361 ns 64.458 ns]
Found 2 outliers among 100 measurements (2.00%)
  1 (1.00%) high mild
  1 (1.00%) high severe

Counter/AddOneAttr      time:   [144.01 ns 146.76 ns 150.11 ns]
Found 13 outliers among 100 measurements (13.00%)
  5 (5.00%) high mild
  8 (8.00%) high severe

Counter/AddOneAttrDelta time:   [144.58 ns 145.39 ns 146.28 ns]
Found 6 outliers among 100 measurements (6.00%)
  1 (1.00%) high mild
  5 (5.00%) high severe

PR

Counter/AddNoAttrs      time:   [30.140 ns 30.390 ns 30.652 ns]
                        change: [-49.181% -48.265% -47.331%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 12 outliers among 100 measurements (12.00%)
  4 (4.00%) high mild
  8 (8.00%) high severe
Counter/AddNoAttrsDelta time:   [29.836 ns 30.040 ns 30.327 ns]
                        change: [-53.397% -52.564% -51.790%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  4 (4.00%) high mild
  3 (3.00%) high severe
Counter/AddOneAttr      time:   [145.48 ns 145.84 ns 146.24 ns]
                        change: [-0.3877% +0.8455% +2.1208%] (p = 0.20 > 0.05)
                        No change in performance detected.
Found 8 outliers among 100 measurements (8.00%)
  1 (1.00%) high mild
  7 (7.00%) high severe
Counter/AddOneAttrDelta time:   [147.37 ns 148.07 ns 148.85 ns]
                        change: [+0.5418% +2.2081% +3.9805%] (p = 0.01 < 0.05)
                        Change within noise threshold.
Found 11 outliers among 100 measurements (11.00%)
  4 (4.00%) high mild
  7 (7.00%) high severe

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@KallDrexx KallDrexx requested a review from a team February 8, 2024 20:24
Copy link

codecov bot commented Feb 8, 2024

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (b35bf38) 62.4% compared to head (f40ab52) 63.2%.

Files Patch % Lines
opentelemetry-sdk/src/metrics/internal/sum.rs 77.1% 19 Missing ⚠️
opentelemetry-sdk/src/metrics/mod.rs 99.1% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1519     +/-   ##
=======================================
+ Coverage   62.4%   63.2%   +0.8%     
=======================================
  Files        144     144             
  Lines      19891   20299    +408     
=======================================
+ Hits       12426   12847    +421     
+ Misses      7465    7452     -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cijothomas
Copy link
Member

Consider a changelog entry, as users upgrading will learn about the perf improvement of zero-attributes, and can leverage it to achieve bound-instrument (not technically, but a reasonable workaround).

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some nits, but overall looks very good.

@KallDrexx
Copy link
Contributor Author

Unit tests and changelog updated

@cijothomas cijothomas merged commit 650904f into open-telemetry:main Feb 15, 2024
14 checks passed
@KallDrexx KallDrexx deleted the reduce_cost_of_no_attribute_counters branch February 16, 2024 15:29
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