-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectIngestFrameThroughputBenchmarks.cs
More file actions
83 lines (70 loc) · 2.51 KB
/
Copy pathDirectIngestFrameThroughputBenchmarks.cs
File metadata and controls
83 lines (70 loc) · 2.51 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
using BenchmarkDotNet.Attributes;
using System.Diagnostics;
using Store = SharedMemoryStore.MemoryStore;
namespace SharedMemoryStore.Benchmarks;
[MemoryDiagnoser]
public class DirectIngestFrameThroughputBenchmarks
{
private Store _store = null!;
private readonly byte[] _key = [1];
private readonly byte[] _descriptor = [1, 0, 0, 0];
private int _payloadLength;
[GlobalSetup]
public void Setup()
{
_payloadLength = BenchmarkEnvironment.FramePayloadBytes;
_store = BenchmarkStoreFactory.Create(slotCount: 2, maxValueBytes: _payloadLength, maxDescriptorBytes: _descriptor.Length);
}
[GlobalCleanup]
public void Cleanup() => _store.Dispose();
[Benchmark]
public StoreStatus DirectFrameIngestRemove()
{
var status = _store.TryReserve(_key, _payloadLength, _descriptor, out var reservation);
if (status != StoreStatus.Success)
{
return status;
}
reservation.GetSpan(_payloadLength).Fill(0x5A);
status = reservation.Advance(_payloadLength);
if (status != StoreStatus.Success)
{
_ = reservation.Abort();
return status;
}
status = reservation.Commit();
return status == StoreStatus.Success ? _store.TryRemove(_key) : status;
}
[Benchmark]
public DirectIngestThroughputValidationResult SustainedDirectIngestForSixtySeconds()
{
var stopwatch = Stopwatch.StartNew();
long frames = 0;
var status = StoreStatus.Success;
while (stopwatch.Elapsed < TimeSpan.FromSeconds(BenchmarkEnvironment.FrameThroughputDurationSeconds))
{
status = DirectFrameIngestRemove();
if (status != StoreStatus.Success)
{
break;
}
frames++;
}
stopwatch.Stop();
var framesPerSecond = frames / Math.Max(stopwatch.Elapsed.TotalSeconds, 0.001);
return new DirectIngestThroughputValidationResult(
frames,
framesPerSecond,
BenchmarkEnvironment.TargetFramePublishesPerSecond,
BenchmarkEnvironment.FrameThroughputDurationSeconds,
status,
framesPerSecond >= BenchmarkEnvironment.TargetFramePublishesPerSecond && status == StoreStatus.Success);
}
}
public readonly record struct DirectIngestThroughputValidationResult(
long FrameCount,
double FramesPerSecond,
int TargetFramesPerSecond,
int DurationSeconds,
StoreStatus FinalStatus,
bool Passed);