MQTTnet icon indicating copy to clipboard operation
MQTTnet copied to clipboard

I send a lot of data every second, which seems to be slow?

Open bbhxwl opened this issue 1 year ago • 7 comments

I try to send 20 pieces of data every second. It seems that sending will be delayed for a long time.

Is there any best way?

bbhxwl avatar Sep 09 '22 02:09 bbhxwl

Are you using the managed client? Can you share more information so that this issue becomes actionable? With the info given nothing can be done, except refering to the https://github.com/dotnet/MQTTnet/wiki

gfoidl avatar Sep 09 '22 08:09 gfoidl

Are you using the managed client? Can you share more information so that this issue becomes actionable? With the info given nothing can be done, except refering to the https://github.com/dotnet/MQTTnet/wiki This is my complete code. I send data circularly. There may be 20 in one second.

    IMqttClient mqtt = new MqttFactory().CreateMqttClient();
var op= new MqttClientOptionsBuilder().WithTcpServer("*******").Build();
          mqtt.ConnectAsync(op).ContinueWith(rs =>
          {
              if (rs.Result.ResultCode== MqttClientConnectResultCode.Success)
              {
                  
              }
          });

mqtt.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("470138890").WithQualityOfServiceLevel(MQTTnet.Protocol.MqttQualityOfServiceLevel.AtMostOnce).WithPayload(JsonConvert.SerializeObject(model)).Build());

bbhxwl avatar Sep 09 '22 09:09 bbhxwl

Are you using the managed client? Can you share more information so that this issue becomes actionable? With the info given nothing can be done, except refering to the https://github.com/dotnet/MQTTnet/wiki

image If you call this method frequently, there will be no error and no return value. I don't know why?

bbhxwl avatar Sep 09 '22 12:09 bbhxwl

From code perspective it looks okay to me. Which broker do you use? And why do you expect an error? If there was no error the message was transmitted. And what means "no return value"? The task always has a return value.

chkr1011 avatar Sep 16 '22 21:09 chkr1011

No problems using a mosquitto server on localhost, but I also notice some heavy slowness using the MQTT managed client connected to a remote mosquitto server. Clients such as mqtt.js have no issues.

fungiboletus avatar Sep 20 '22 12:09 fungiboletus

Do you experience the same slowness when not using the managed client (MqttClient instead)?

chkr1011 avatar Sep 20 '22 12:09 chkr1011

Thanks for the clue! I quickly converted my code to MQTTClient and it's as fast as I produce the messages.

That's without waiting for the publishAsync tasks, which makes VisualStudio a bit sad. I don't know whether I should mind. If I wait for them sequentially it's very slow, but this is normal.

So in my case (a remote mosquitto server over secure websocket with about HTTP 4ms of ping according to curl), the managed client is a bit slow when it receives and publishes many messages at the same time.

fungiboletus avatar Sep 20 '22 18:09 fungiboletus

The managed client is currently being rewritten from scratch so that performance issues will no longer happen. I close this issue because I assume the problem is gone when using the regular client instead of the managed one.

chkr1011 avatar Oct 01 '22 09:10 chkr1011