Lock-free updates for Histogram (#2951)
This commit is contained in:
parent
b6dcfe8e09
commit
e7b0257605
|
|
@ -2,9 +2,13 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
* Make `IResourceDetector` public to allow custom implementations of resource detectors.
|
||||
* Make `IResourceDetector` public to allow custom implementations of resource
|
||||
detectors.
|
||||
([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))
|
||||
|
||||
## 1.2.0-rc2
|
||||
|
||||
Released 2022-Feb-02
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ namespace OpenTelemetry.Metrics
|
|||
|
||||
internal double SnapshotSum;
|
||||
|
||||
internal int IsCriticalSectionOccupied = 0;
|
||||
|
||||
internal HistogramBuckets(double[] explicitBounds)
|
||||
{
|
||||
this.ExplicitBounds = explicitBounds;
|
||||
|
|
|
|||
|
|
@ -323,11 +323,23 @@ namespace OpenTelemetry.Metrics
|
|||
}
|
||||
}
|
||||
|
||||
lock (this.histogramBuckets.LockObject)
|
||||
var sw = default(SpinWait);
|
||||
while (true)
|
||||
{
|
||||
this.runningValue.AsLong++;
|
||||
this.histogramBuckets.RunningSum += number;
|
||||
this.histogramBuckets.RunningBucketCounts[i]++;
|
||||
if (Interlocked.Exchange(ref this.histogramBuckets.IsCriticalSectionOccupied, 1) == 0)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
this.runningValue.AsLong++;
|
||||
this.histogramBuckets.RunningSum += number;
|
||||
this.histogramBuckets.RunningBucketCounts[i]++;
|
||||
}
|
||||
|
||||
this.histogramBuckets.IsCriticalSectionOccupied = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
sw.SpinOnce();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue