Closed tomwimmenhove closed 4 years ago
I just did a quick check using M2Mqtt, which seems to do a little under 10k req/sec under the same circumstances. So it doesn't seem to be an issue with my setup.
Hi, please answer the following questions so that I can try to analyze this issue:
Please try 3.0.10-rc2 in the meantime.
use async version and run it in release mode, i didnt try your code but when running the benchmarks im above 200K msg/sec
if i run your code slightly modified i get 50k / sec with mqttnet and 300K msg/sec with kesterel as server and pipelines based transport in the client
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MQTTnet;
using MQTTnet.AspNetCore;
using MQTTnet.AspNetCore.Client;
using MQTTnet.Client.Options;
using MQTTnet.Server;
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static async Task Main()
{
await MqttNet();
await MqttNetAspnetCore();
Console.ReadLine();
}
static async Task MqttNet()
{
var factory = new MqttFactory();
var server = factory.CreateMqttServer();
var mqttClient = factory.CreateMqttClient();
var options = new MqttClientOptionsBuilder()
.WithTcpServer("127.0.0.1")
.WithKeepAlivePeriod(new TimeSpan(1, 0, 0, 0))
.Build();
await server.StartAsync(new MqttServerOptionsBuilder().Build());
await mqttClient.ConnectAsync(options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
.WithTopic("SomeTopic")
.Build();
var sw = Stopwatch.StartNew();
var total = 100000;
for (var n = 0; n < total; n++)
{
message.Payload = Encoding.UTF8.GetBytes($"test {n}");
await mqttClient.PublishAsync(message, CancellationToken.None);
if (n % 1000 == 0)
{
//Console.WriteLine($"n: {n}");
}
}
sw.Stop();
Console.WriteLine($"msg/sec {total / sw.Elapsed.TotalSeconds}");
}
class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddHostedMqttServer(mqttServer => mqttServer.WithoutDefaultEndpoint())
.AddMqttConnectionHandler()
.AddConnections();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
}
}
static async Task MqttNetAspnetCore()
{
var factory = new MqttFactory();
var host = WebHost.CreateDefaultBuilder()
.UseKestrel(o =>
{
o.ListenAnyIP(1883, l => l.UseMqtt());
})
.UseStartup<Startup>()
.Build();
var mqttClient = factory.CreateMqttClient(new MqttClientConnectionContextFactory() );
var options = new MqttClientOptionsBuilder()
.WithTcpServer("127.0.0.1")
.WithKeepAlivePeriod(new TimeSpan(1, 0, 0, 0))
.Build();
await host.StartAsync();
await mqttClient.ConnectAsync(options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
.WithTopic("SomeTopic")
.Build();
var sw = Stopwatch.StartNew();
var total = 100000;
for (var n = 0; n < total; n++)
{
message.Payload = Encoding.UTF8.GetBytes($"test {n}");
await mqttClient.PublishAsync(message, CancellationToken.None);
if (n % 1000 == 0)
{
//Console.WriteLine($"n: {n}");
}
}
sw.Stop();
Console.WriteLine($"msg/sec {total / sw.Elapsed.TotalSeconds}");
}
}
}
Can this be closed? It seems like we're not able to reproduce your issue, @tomwimmenhove...
Strange. I'll look into it again if/when I have the time. I'll close it and maybe re-open if I find out more. Thanks for your trouble!
Describe the bug
I read issue #31, which addressed bad performance issues. It looked like it had been fixed, but I'm still not able to squeeze much more than 500req/sec out of it. I'm connecting from a windows VM to a Linux server running mosquitto. Both are running on the same hardware. The mosquitto is practically asleep, while the .NET application is running at full tilt. I've tried it with both with and without async calls.
Which project is your bug related to?
To Reproduce
Steps to reproduce the behavior:
Expected behavior
A clear and concise description of what you expected to happen.
Additional context / logging
KeepAlive timespan is set to 1 day
Code example