我用 MQTTNet 进行了几次性能测试,得到了意想不到的结果 寻求帮助以查看是否有一些我错过的配置更改或 MQTTNet 实现限制。环境:我在一个盒子上有 3 个进程:发件人 -> 服务器 -> 订阅者
测试:
Messages Sender Server Subscriber Time
100K 1 instance sends 100K messages -> 1 -> 1 instance 30sec
100K (1000*100) 1k instances sends 100 messages -> 1 -> 1 instance 32sec
100k (10000*10) 10K instances sends 10 messages -> 1 -> 1 instance 340sec
我看到从 1 个实例迁移到 1000 个不会显着影响性能,但迁移到 10K 发送者(1 个进程和 10k 客户端实例)会显着影响性能。
在最后一次测试中,所有消息在 50 秒内以及服务器向订阅者发送消息之后传递到服务器。50 秒后 CPU 降至 25%
服务器启动
var optionsBuilder = new MqttServerOptionsBuilder()
.WithConnectionBacklog(10000)
.WithDefaultEndpointPort(8883)
.WithDefaultEndpointBoundIPAddress(IPAddress.Parse("xxx"))
.WithApplicationMessageInterceptor(context =>
{
Interlocked.Increment(ref cnt);
}
)
.WithMaxPendingMessagesPerClient(100);
mqttServer = new MqttFactory().CreateMqttServer();
await mqttServer.StartAsync(optionsBuilder.Build());
客户端启动
var options = new MqttClientOptionsBuilder()
.WithClientId(name)
.WithTcpServer("xxxx", 8883)
.Build();
var factory = new MqttFactory();
mqttClient = factory.CreateMqttClient();
mqttClient.UseApplicationMessageReceivedHandler(e =>
{
Interlocked.Increment(ref cnt);
});
// for receiver
mqttClient.UseConnectedHandler(async e =>
{
Console.WriteLine("### CONNECTED WITH SERVER ###");
await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic("my/topic").Build());
Console.WriteLine("### SUBSCRIBED ###");
});
MQTTNet 3.0.11 版,
操作系统视窗 10
为什么我观察到 10K 客户端的降级如此之大,而 1000 个客户端几乎没有降级。我可以错过一些配置吗?