-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecoveryOwnershipBenchmarks.cs
More file actions
52 lines (42 loc) · 1.4 KB
/
Copy pathRecoveryOwnershipBenchmarks.cs
File metadata and controls
52 lines (42 loc) · 1.4 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
using BenchmarkDotNet.Attributes;
using Store = SharedMemoryStore.MemoryStore;
namespace SharedMemoryStore.Benchmarks;
[MemoryDiagnoser]
public class RecoveryOwnershipBenchmarks
{
private Store _store = null!;
[GlobalSetup]
public void Setup() => _store = BenchmarkStoreFactory.Create(slotCount: 1, leaseRecordCount: 1);
[GlobalCleanup]
public void Cleanup() => _store.Dispose();
[Benchmark]
public RecoveryOwnershipBenchmarkResult CurrentProcessRecoveryCycles()
{
var recovered = 0;
var active = 0;
var failed = 0;
for (var i = 0; i < 1_000; i++)
{
var key = BitConverter.GetBytes(i);
if (_store.TryPublish(key, [1]) != StoreStatus.Success)
{
failed++;
break;
}
if (_store.TryAcquire(key, out _) != StoreStatus.Success)
{
failed++;
break;
}
if (_store.TryRecoverLeases(new LeaseRecoveryOptions(true), out var report) != StoreStatus.Success)
{
failed++;
break;
}
recovered += report.RecoveredLeaseCount;
active += report.ActiveLeaseCount;
_ = _store.TryRemove(key);
}
return new RecoveryOwnershipBenchmarkResult(1_000, recovered, active, failed, failed == 0 && recovered > 0);
}
}