eclipse / paho.mqtt.java

Eclipse Paho Java MQTT client library. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
2.12k stars 883 forks source link

deliveryCompleted Callback is comming late. #471

Closed senniraf closed 6 years ago

senniraf commented 6 years ago

I've been doing some researches on MQTT's Performance. I'm measuring the latencies of messages sent via MQTT using the MqttAsyncClient from Version 1.2.0. To achieve this I'm using the callback functions to measure timestamps when they are called. I'm sending messages from one client to another, both in the same application. The messages are sent via a Mosquitto broker running on a Raspberry PI, connected with Ethernet to the application system.

Sometimes the deliveryCompleted callback is called after the message is received by the other client.

This is happening every time when I send messages with a "At Most Once" Quality of Service and a time lag of 100ms between two messages. It's always happening that the deliveryCompleted callback of the 22nd message is coming late. The payload of each message is 4 to 100 Bytes

The application is compiled by a JDK v1.8.0_151 and running on a JRE of the same version on a Windows 10 64-Bit System.

jpwsutton commented 6 years ago

Hi,

It could be that you are reaching a limit with the max number of inflight messages. You can change this value with MqttConnectOptions.setMaxInflight, the default is 10, but you could increase this value as much as you like.

jonquark commented 6 years ago

The delivery completed callback will be called (for qos=1) at some point after the server has sent an acknowledgement of receipt to the publisher. The server can choose to send that acknowledgement after it has sent the message to the other client (and this is a common choice that servers often make).

Hence the methodology you are trying to use (to compare the time delta of the delivery callback to the msg arrived callback) is flawed and cannot be fixed by changes to the client.