paho.mqtt.c icon indicating copy to clipboard operation
paho.mqtt.c copied to clipboard

Saw-tooth latencies due to poll system call in paho.mqtt.c v1.3.10

Open lreiher opened this issue 2 years ago • 7 comments

Describe the bug

Starting with paho.mqtt.c v1.3.10, I'm seeing saw-tooth latencies measured by our ROS-MQTT-Interface mqtt_client. Our mqtt_client is using paho.mqtt.cpp to send arbitrary ROS messages via MQTT to a second instance of the mqtt_client. I am filing an issue here, since this behavior wasn't present with paho.mqtt.c v1.3.9.

From the release notes of v1.3.10:

A significant internal change is to use the poll system call instead of select to monitor sockets. Most people should notice no difference, except that poll does not exist on Windows XP as select does. You can use the USE_SELECT compile definition to switch back to use select for those platforms that don't have poll.

I have successfully verified that the issue is in fact due to the above mentioned change. If I build paho.mqtt.c with -DPAHO_USE_SELECT=ON, the issue is gone.

Unfortunately, my knowledge of poll vs. select is close to none. Could you please help to identify whether this might be a bug in paho.mqtt.c, or expected behavior, or rather a bug on our side in how we are using the paho.mqtt.cpp?

To Reproduce

Please see https://github.com/ika-rwth-aachen/mqtt_client/issues/2 for easy steps to reproduce. Note that a ROS Noetic installation is required.

Expected behavior

No saw-tooth latencies, pretty consistent latencies.

Screenshots

image

Environment:

  • OS: Linux Ubuntu
  • Version 20.04
  • Docker container with ROS Noetic installed

lreiher avatar Aug 04 '22 12:08 lreiher

I put some changes into the develop branch that may address this, if you'd like to try them.

icraggs avatar Aug 05 '22 10:08 icraggs

I started to try to reproduce to see if my changes would fix it, but I don't know where to get the ros-noetic-mqtt-client package from.

icraggs avatar Aug 05 '22 10:08 icraggs

Thank you very much, I will try this out as soon as possible!

If ROS is installed, the package can simply be installed via sudo apt install ros-noetic-mqtt-client.

lreiher avatar Aug 08 '22 15:08 lreiher

I tried that command, but I presume I'd need to add some extra sources as it didn't find the package.

icraggs avatar Aug 08 '22 19:08 icraggs

Thanks, I just tried it out with the most recent changes on develop and -DPAHO_USE_SELECT=OFF.
Looks like the saw-tooth pattern is gone.
The behavior is now equivalent to v1.3.9 or v1.3.10 with -DPAHO_USE_SELECT=ON.

image

Are the changes going to be part of a new release v1.3.11? Can you already estimate when that is going to happen?

lreiher avatar Aug 09 '22 11:08 lreiher

Great, thanks for trying it out. I'll think about the next release but as this is pretty important sometime in August seems a good idea.

icraggs avatar Aug 09 '22 14:08 icraggs

Perfect, thanks a lot for your help. Looking forward to the release!

lreiher avatar Aug 10 '22 15:08 lreiher