This repository was archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathStreamSubscription.cs
More file actions
92 lines (77 loc) · 3.22 KB
/
Copy pathStreamSubscription.cs
File metadata and controls
92 lines (77 loc) · 3.22 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
86
87
88
89
90
91
92
namespace LoadTests
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using EasyConsole;
using SqlStreamStore.Streams;
public class StreamSubscription : LoadTest
{
public override async Task Run(CancellationToken ct)
{
Output.WriteLine("");
Output.WriteLine(ConsoleColor.Green,
"Subscribes to multiple individual streams and appends to each of them in turn, multiple times.");
Output.WriteLine("");
var (streamStore, dispose) = await GetStore(ct);
try
{
int numberOfStreams = Input.ReadInt(
"Number of independent streams, each will have it's own subscriber: ",
1,
1000);
int numberOfAppends = Input.ReadInt("Number of times each stream will have an append: ", 1, 1000);
string jsonData = "{}";
var subscriptions = new List<IDisposable>();
int messagesReceived = 0;
for(int i = 0; i < numberOfStreams; i++)
{
var subscription = streamStore.SubscribeToStream(
$"stream-{i}",
StreamVersion.None,
(_, __, ___) =>
{
Interlocked.Increment(ref messagesReceived);
return Task.CompletedTask;
});
subscriptions.Add(subscription);
}
int amendAcount = 0;
int eventNumber = 1;
var totalMessages = numberOfAppends * numberOfStreams;
var stopwatch = Stopwatch.StartNew();
while(amendAcount < numberOfAppends)
{
for(int i = 0; i < numberOfStreams; i++)
{
var newStreamMessages = MessageFactory.CreateNewStreamMessages(jsonData, eventNumber);
await streamStore.AppendToStream($"stream-{i}", ExpectedVersion.Any, newStreamMessages, ct);
eventNumber++;
}
amendAcount++;
Console.Write(
$"\r> Appending: {amendAcount} / {numberOfAppends} . Received: {messagesReceived} / {totalMessages}");
}
while(messagesReceived < totalMessages)
{
Console.Write(
$"\r> Appending: {amendAcount} / {numberOfAppends} . Received: {messagesReceived} / {totalMessages}");
await Task.Delay(100, ct);
}
Console.WriteLine(
$"\r> Appending: {amendAcount} / {numberOfAppends} . Received: {messagesReceived} / {totalMessages}");
foreach(var subscription in subscriptions)
{
subscription.Dispose();
}
Output.WriteLine($"> Complete in {stopwatch.Elapsed:c}");
}
finally
{
dispose();
}
}
}
}