Explorar el Código

Extended performance test app

release/3.x.x
Christian Kratky hace 7 años
padre
commit
0e48076d25
Se han modificado 2 ficheros con 24 adiciones y 25 borrados
  1. +23
    -24
      Tests/MQTTnet.TestApp.NetFramework/PerformanceTest.cs
  2. +1
    -1
      Tests/MQTTnet.TestApp.NetFramework/Program.cs

+ 23
- 24
Tests/MQTTnet.TestApp.NetFramework/PerformanceTest.cs Ver fichero

@@ -5,6 +5,7 @@ using MQTTnet.Core.Protocol;
using MQTTnet.Core.Server;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -16,12 +17,12 @@ namespace MQTTnet.TestApp.NetFramework
public static async Task RunAsync()
{
var server = Task.Run(() => RunServerAsync());
var client = Task.Run(() => RunClientAsync(50, TimeSpan.FromMilliseconds(10)));
var client = Task.Run(() => RunClientAsync(1000, 50000, TimeSpan.FromMilliseconds(10)));

await Task.WhenAll(server, client).ConfigureAwait(false);
}

private static async Task RunClientAsync( int msgChunkSize, TimeSpan interval )
private static async Task RunClientAsync(int messageChunkSize, int totalMessageCount, TimeSpan interval)
{
try
{
@@ -76,35 +77,33 @@ namespace MQTTnet.TestApp.NetFramework

Console.WriteLine("### WAITING FOR APPLICATION MESSAGES ###");

var last = DateTime.Now;
var msgs = 0;
var applicationMessage = new MqttApplicationMessage(
"A/B/C",
Encoding.UTF8.GetBytes("Hello World"),
MqttQualityOfServiceLevel.AtLeastOnce,
false
);

while (true)
var overallCount = 0;
while (overallCount < totalMessageCount)
{
for (int i = 0; i < msgChunkSize; i++)
var stopwatch = Stopwatch.StartNew();
var count = 0;
for (var i = 0; i < messageChunkSize; i++)
{
var applicationMessage = new MqttApplicationMessage(
"A/B/C",
Encoding.UTF8.GetBytes("Hello World"),
MqttQualityOfServiceLevel.AtLeastOnce,
false
);

//do not await to send as much messages as possible
await client.PublishAsync(applicationMessage);
msgs++;
await client.PublishAsync(applicationMessage).ConfigureAwait(false);
count++;
overallCount++;
}

var now = DateTime.Now;
if (last < now - TimeSpan.FromSeconds(1))
{
Console.WriteLine( $"sending {msgs} inteded {msgChunkSize / interval.TotalSeconds}" );
msgs = 0;
last = now;
}
stopwatch.Stop();

Console.WriteLine($"Sent {count} messages within {stopwatch.ElapsedMilliseconds} ms ({stopwatch.ElapsedMilliseconds / (float)count} ms / message).");
await Task.Delay(interval).ConfigureAwait(false);
}

Console.WriteLine($"Completed sending {totalMessageCount} messages.");
}
catch (Exception exception)
{
@@ -134,12 +133,12 @@ namespace MQTTnet.TestApp.NetFramework
};
var mqttServer = new MqttServerFactory().CreateMqttServer(options);
var last = DateTime.Now;
var last = DateTime.UtcNow;
var msgs = 0;
mqttServer.ApplicationMessageReceived += (sender, args) =>
{
msgs++;
var now = DateTime.Now;
var now = DateTime.UtcNow;
if (last < now - TimeSpan.FromSeconds(1))
{
Console.WriteLine($"received {msgs}");


+ 1
- 1
Tests/MQTTnet.TestApp.NetFramework/Program.cs Ver fichero

@@ -33,7 +33,7 @@ namespace MQTTnet.TestApp.NetFramework
}
else if (pressedKey.Key == ConsoleKey.D3)
{
Task.Run(() => PerformanceTest.RunAsync());
Task.Run(PerformanceTest.RunAsync);
Thread.Sleep(Timeout.Infinite);
}
}


Cargando…
Cancelar
Guardar