Refactor async/await and ConcurrentDictionary usage.

This commit is contained in:
Christian Kratky
2018-06-20 20:07:25 +02:00
parent bc20850fba
commit 0322660561
20 changed files with 409 additions and 245 deletions
@@ -12,7 +12,48 @@ namespace MQTTnet.TestApp.NetCore
{
public static class PerformanceTest
{
public static void Run()
public static void RunClientOnly()
{
try
{
var options = new MqttClientOptions
{
ChannelOptions = new MqttClientTcpOptions
{
Server = "127.0.0.1"
},
CleanSession = true
};
var client = new MqttFactory().CreateMqttClient();
client.ConnectAsync(options).GetAwaiter().GetResult();
var message = CreateMessage();
var stopwatch = new Stopwatch();
for (var i = 0; i < 10; i++)
{
var sentMessagesCount = 0;
stopwatch.Restart();
while (stopwatch.ElapsedMilliseconds < 1000)
{
client.PublishAsync(message).GetAwaiter().GetResult();
sentMessagesCount++;
}
Console.WriteLine($"Sending {sentMessagesCount} messages per second. #" + (i + 1));
GC.Collect();
}
}
catch (Exception exception)
{
Console.WriteLine(exception);
}
}
public static void RunClientAndServer()
{
try
{