-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Iggy_SDK\Iggy_SDK.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using System.Diagnostics; | ||
using System.Text; | ||
using Iggy_SDK.Contracts.Http; | ||
using Iggy_SDK.Enums; | ||
using Iggy_SDK.Factory; | ||
using Iggy_SDK.Messages; | ||
|
||
const int messagesCount = 1000; | ||
const int messagesBatch = 1000; | ||
const int messageSize = 69; | ||
const int producerCount = 7; | ||
const int streamId = 14; | ||
const int topicId = 1; | ||
ulong totalMessages = messagesBatch * messagesCount; | ||
ulong totalMessagesBytes = totalMessages * messageSize; | ||
|
||
|
||
var bus = MessageStreamFactory.CreateMessageStream(options => | ||
{ | ||
options.BaseAdress = "127.0.0.1:8090"; | ||
options.Protocol = Protocol.Tcp; | ||
options.ReceiveBufferSize = Int32.MaxValue; | ||
options.SendBufferSize = Int32.MaxValue; | ||
}); | ||
|
||
try | ||
{ | ||
var stream = await bus.GetStreamByIdAsync(streamId); | ||
} | ||
catch | ||
{ | ||
await bus.CreateStreamAsync(new StreamRequest | ||
{ | ||
Name = "Test bench stream", | ||
StreamId = streamId | ||
}); | ||
await bus.CreateTopicAsync(streamId, new TopicRequest | ||
{ | ||
Name = "Test bench topic", | ||
PartitionsCount = 1, | ||
TopicId = topicId | ||
}); | ||
} | ||
|
||
async Task SendMessages(int producerNumber) | ||
{ | ||
List<TimeSpan> latencies = new(); | ||
long memoryBefore = GC.GetTotalMemory(true); | ||
|
||
for (int i = 0; i < messagesBatch; i++) | ||
{ | ||
var startTime = Stopwatch.GetTimestamp(); | ||
await bus.SendMessagesAsync(streamId, topicId, new MessageSendRequest | ||
{ | ||
Key = new Key | ||
{ | ||
Kind = KeyKind.PartitionId, | ||
Length = 4, | ||
Value = BitConverter.GetBytes(1), | ||
}, | ||
Messages = CreateMessages(), | ||
}); | ||
var diff = Stopwatch.GetElapsedTime(startTime); | ||
latencies.Add(diff); | ||
} | ||
|
||
long memoryAfter = GC.GetTotalMemory(true); | ||
long memoryUsed = memoryAfter - memoryBefore; | ||
GC.Collect(); | ||
var avgLatency = latencies.Average(x=>x.TotalSeconds); | ||
var totalLatencies = latencies.Sum(x => x.TotalSeconds); | ||
Console.WriteLine($"Total message bytes: {totalMessagesBytes}, average latency: {avgLatency} seconds"); | ||
var avgThroughput = totalMessagesBytes / (totalLatencies) / 1024.0 / 1024.0; | ||
Console.WriteLine( | ||
$"Producer number: {producerNumber} send Messages: {messagesCount} in {messagesBatch} batches, with average throughput {avgThroughput} MB/s, allocated {memoryUsed} bytes of memory "); | ||
|
||
} | ||
|
||
Parallel.For(1, producerCount + 1, async iter => | ||
{ | ||
Console.WriteLine($"Executing producer number: {iter}"); | ||
await SendMessages(iter); | ||
}); | ||
Console.ReadLine(); | ||
|
||
static List<Message> CreateMessages() | ||
{ | ||
var messages = new List<Message>(); | ||
for (int i = 0; i < messagesCount; i++) | ||
{ | ||
messages.Add(new Message | ||
{ | ||
Id = Guid.NewGuid(), | ||
Payload = CreatePayload(messageSize) | ||
}); | ||
} | ||
|
||
return messages; | ||
} | ||
|
||
static byte[] CreatePayload(uint size) | ||
{ | ||
StringBuilder payloadBuilder = new StringBuilder((int)size); | ||
for (uint i = 0; i < size; i++) | ||
{ | ||
char character = (char)((i % 26) + 97); | ||
payloadBuilder.Append(character); | ||
} | ||
|
||
string payloadString = payloadBuilder.ToString(); | ||
return Encoding.ASCII.GetBytes(payloadString); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters