Skip to content

Use ValueMap for Gauge - Throughput increased around 8x #2017

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

Merged

Conversation

utpilla
Copy link
Contributor

@utpilla utpilla commented Aug 13, 2024

Follow-up to #2012
Similar to #1833 and #1989 from @cijothomas
Related to #1740

Changes

  • Update Gauge to use ValueMap
Machine information OS: Ubuntu 22.04.3 LTS (5.15.146.1-microsoft-standard-WSL2) Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs, RAM: 64.0 GB

Benchmarks

There is a ~63% increase in benchmark performance. This is coming from ValueMap's optimized lookup on the hot path.

Gauge_Add_With_Three_Random_Attributes Average time
main branch 483.78 ns
PR 178.37 ns

Stress Test

That's an improvement of nearly 8x for throughput. This is coming from ValueMap's reduced thread contention and optimized lookup on the hot path.

16 threads updating random trackers Throughput
main branch 1.5 M/sec
PR 11.5 M/sec

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)

@utpilla utpilla requested a review from a team August 13, 2024 07:30
Copy link

codecov bot commented Aug 13, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 75.2%. Comparing base (399846e) to head (ba28778).

Files Patch % Lines
...entelemetry-sdk/src/metrics/internal/last_value.rs 96.6% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #2017   +/-   ##
=====================================
  Coverage   75.2%   75.2%           
=====================================
  Files        122     122           
  Lines      20874   20873    -1     
=====================================
+ Hits       15698   15703    +5     
+ Misses      5176    5170    -6     

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

pub(crate) struct LastValue<T> {
values: Mutex<HashMap<AttributeSet, DataPointValue<T>>>,
pub(crate) struct LastValue<T: Number<T>> {
value_map: ValueMap<T, Assign>,
Copy link
Member

Choose a reason for hiding this comment

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

as important as the perf gains is the code reusability now! Hopefully, we can make it to Histograms too and have a single place dealing with the 1st half of the Metric aggregation problem, which is finding the datapoint to make updates to, and that is independent of actual aggregation!

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.

Awesome!
Nit: Consider a changelog entry. (Or okay to make a common entry once all changes are in, so users get a good summary)

@cijothomas cijothomas merged commit b24608e into open-telemetry:main Aug 13, 2024
25 checks passed
@cijothomas
Copy link
Member

Merging quickly as this is internal implementation fixes and follows existing approach from other instruments. We have good (not great) test coverage too now.

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.

2 participants