Skip to content

Commit

Permalink
Lock-free updates for HistogramSumCount (#2961)
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Mar 4, 2022
1 parent cee9006 commit af0c9b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/OpenTelemetry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
([#2949](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2949/)
[#2897](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2897))

* Perf improvement for Histogram, by implementing lock-free updates.
([#2951](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2951))
* Perf improvement for Histogram and HistogramSumCount by implementing lock-free
updates.
([2951](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2951))
([2961](https://github.com/open-telemetry/opentelemetry-dotnet/pull/2961))

## 1.2.0-rc2

Expand Down
18 changes: 15 additions & 3 deletions src/OpenTelemetry/Metrics/MetricPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,22 @@ internal void Update(double number)

case AggregationType.HistogramSumCount:
{
lock (this.histogramBuckets.LockObject)
var sw = default(SpinWait);
while (true)
{
this.runningValue.AsLong++;
this.histogramBuckets.RunningSum += number;
if (Interlocked.Exchange(ref this.histogramBuckets.IsCriticalSectionOccupied, 1) == 0)
{
unchecked
{
this.runningValue.AsLong++;
this.histogramBuckets.RunningSum += number;
}

this.histogramBuckets.IsCriticalSectionOccupied = 0;
break;
}

sw.SpinOnce();
}

break;
Expand Down

0 comments on commit af0c9b4

Please sign in to comment.