Add benchmarks to show impact of ExemplarFilter (#4245)

This commit is contained in:
Cijo Thomas 2023-02-28 13:30:21 -08:00 committed by GitHub
parent afd677f679
commit 19a281e541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 12 deletions

View File

@ -43,7 +43,7 @@ internal abstract class ExemplarReservoir
/// </summary>
/// <param name="actualTags">The actual tags that are part of the metric. Exemplars are
/// only expected to contain any filtered tags, so this will allow the reservoir
/// prepare the filtered tags from all the tags it is given by doing the
/// to prepare the filtered tags from all the tags it is given by doing the
/// equivalent of filtered tags = all tags - actual tags.
/// </param>
/// <param name="reset">Flag to indicate if the reservoir should be reset after this call.</param>

View File

@ -23,19 +23,21 @@ using OpenTelemetry.Tests;
/*
// * Summary *
BenchmarkDotNet=v0.13.3, OS=Windows 11 (10.0.22621.1265)
11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores
BenchmarkDotNet=v0.13.3, OS=Windows 10 (10.0.19045.2604)
Intel Core i7-4790 CPU 3.60GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
.NET SDK=7.0.103
[Host] : .NET 7.0.3 (7.0.323.6910), X64 RyuJIT AVX2
DefaultJob : .NET 7.0.3 (7.0.323.6910), X64 RyuJIT AVX2
| Method | EnableExemplar | Mean | Error | StdDev | Allocated |
|-------------------------- |--------------- |---------:|--------:|--------:|----------:|
| HistogramNoTagReduction | False | 256.5 ns | 4.84 ns | 4.53 ns | - |
| HistogramWithTagReduction | False | 246.6 ns | 4.90 ns | 4.81 ns | - |
| HistogramNoTagReduction | True | 286.4 ns | 5.30 ns | 7.25 ns | - |
| HistogramWithTagReduction | True | 293.6 ns | 5.77 ns | 7.09 ns | - |
| Method | ExemplarFilter | Mean | Error | StdDev |
|-------------------------- |--------------- |---------:|--------:|--------:|
| HistogramNoTagReduction | AlwaysOff | 380.7 ns | 5.92 ns | 5.53 ns |
| HistogramWithTagReduction | AlwaysOff | 356.5 ns | 3.33 ns | 2.95 ns |
| HistogramNoTagReduction | AlwaysOn | 412.3 ns | 2.11 ns | 1.64 ns |
| HistogramWithTagReduction | AlwaysOn | 461.0 ns | 4.65 ns | 4.35 ns |
| HistogramNoTagReduction | HighValueOnly | 378.3 ns | 2.22 ns | 2.08 ns |
| HistogramWithTagReduction | HighValueOnly | 383.1 ns | 7.48 ns | 7.35 ns |
*/
@ -52,8 +54,16 @@ namespace Benchmarks.Metrics
private MeterProvider provider;
private Meter meter;
[Params(true, false)]
public bool EnableExemplar { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1602:Enumeration items should be documented", Justification = "Test only.")]
public enum ExemplarFilterTouse
{
AlwaysOff,
AlwaysOn,
HighValueOnly,
}
[Params(ExemplarFilterTouse.AlwaysOn, ExemplarFilterTouse.AlwaysOff, ExemplarFilterTouse.HighValueOnly)]
public ExemplarFilterTouse ExemplarFilter { get; set; }
[GlobalSetup]
public void Setup()
@ -63,9 +73,19 @@ namespace Benchmarks.Metrics
this.histogramWithTagReduction = this.meter.CreateHistogram<long>("HistogramWithTagReduction");
var exportedItems = new List<Metric>();
ExemplarFilter exemplarFilter = new AlwaysOffExemplarFilter();
if (this.ExemplarFilter == ExemplarFilterTouse.AlwaysOn)
{
exemplarFilter = new AlwaysOnExemplarFilter();
}
else if (this.ExemplarFilter == ExemplarFilterTouse.HighValueOnly)
{
exemplarFilter = new HighValueExemplarFilter();
}
this.provider = Sdk.CreateMeterProviderBuilder()
.AddMeter(this.meter.Name)
.SetExemplarFilter(this.EnableExemplar ? new AlwaysOnExemplarFilter() : new AlwaysOffExemplarFilter())
.SetExemplarFilter(exemplarFilter)
.AddView("HistogramWithTagReduction", new MetricStreamConfiguration() { TagKeys = new string[] { "DimName1", "DimName2", "DimName3" } })
.AddInMemoryExporter(exportedItems, metricReaderOptions =>
{
@ -112,5 +132,18 @@ namespace Benchmarks.Metrics
this.histogramWithTagReduction.Record(random.Next(1000), tags);
}
public class HighValueExemplarFilter : ExemplarFilter
{
public override bool ShouldSample(long value, ReadOnlySpan<KeyValuePair<string, object>> tags)
{
return value > 800;
}
public override bool ShouldSample(double value, ReadOnlySpan<KeyValuePair<string, object>> tags)
{
return value > 800;
}
}
}
}