-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathBatchProcessorBenchmarks.cs
More file actions
85 lines (72 loc) · 2.32 KB
/
BatchProcessorBenchmarks.cs
File metadata and controls
85 lines (72 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using BenchmarkDotNet.Attributes;
using Sentry.Extensibility;
using Sentry.Internal;
namespace Sentry.Benchmarks;
/// <summary>
/// <see cref="BatchProcessor{TItem}"/> (formerly "Sentry.Internal.StructuredLogBatchProcessor") was originally developed as Batch Processor for Logs only.
/// When adding support for Trace-connected Metrics, which are quite similar to Logs, it has been made generic to support both.
/// For comparability of results, we still benchmark with <see cref="SentryLog"/>, rather than <see cref="SentryMetric"/>.
/// </summary>
public class BatchProcessorBenchmarks
{
private Hub _hub;
private BatchProcessor<SentryLog> _batchProcessor;
private SentryLog _log;
[Params(10, 100)]
public int BatchCount { get; set; }
[Params(100, 200, 1_000)]
public int OperationsPerInvoke { get; set; }
[GlobalSetup]
public void Setup()
{
SentryOptions options = new()
{
Dsn = DsnSamples.ValidDsn,
EnableLogs = true,
};
var batchInterval = Timeout.InfiniteTimeSpan;
var clientReportRecorder = new NullClientReportRecorder();
_hub = new Hub(options, DisabledHub.Instance);
_batchProcessor = new SentryLogBatchProcessor(_hub, BatchCount, batchInterval, clientReportRecorder, null);
_log = new SentryLog(DateTimeOffset.Now, SentryId.Empty, SentryLogLevel.Trace, "message");
}
[Benchmark]
public void EnqueueAndFlush()
{
for (var i = 0; i < OperationsPerInvoke; i++)
{
_batchProcessor.Enqueue(_log);
}
_batchProcessor.Flush();
}
[Benchmark]
public void EnqueueAndFlush_Parallel()
{
_ = Parallel.For(0, OperationsPerInvoke, (int i) =>
{
_batchProcessor.Enqueue(_log);
});
_batchProcessor.Flush();
}
[GlobalCleanup]
public void Cleanup()
{
_batchProcessor.Dispose();
_hub.Dispose();
}
}
file sealed class NullClientReportRecorder : IClientReportRecorder
{
public void RecordDiscardedEvent(DiscardReason reason, DataCategory category, int quantity = 1)
{
// no-op
}
public ClientReport GenerateClientReport()
{
throw new UnreachableException();
}
public void Load(ClientReport report)
{
throw new UnreachableException();
}
}