[ROS2] topic hz provides wrong rate for larger msgs
While testing the ros2_intel_realsense
package on ROS eloquent (Ubuntu 18.04, ROS middleware FastRTPS) I realized, that ros2 topic hz
reports far lower rates for a pointcloud2
topic than an explicit C++ subscriber.
The rgbd point cloud has about 5MB/frame and is published at 30Hz.
C++ subscriber:
[INFO] [pointcloud2_subscriber]: Recived 27 messages in 1.00 s (27.00 Hz)
[INFO] [pointcloud2_subscriber]: Recived 28 messages in 1.00 s (28.00 Hz)
[INFO] [pointcloud2_subscriber]: Recived 30 messages in 1.00 s (30.00 Hz)
[INFO] [pointcloud2_subscriber]: Recived 27 messages in 1.00 s (27.00 Hz)
ros2 topic hz:
average rate: 12.106
min: 0.022s max: 0.641s std dev: 0.09745s window: 100
average rate: 11.019
min: 0.022s max: 0.641s std dev: 0.10628s window: 100
average rate: 10.903
min: 0.022s max: 0.641s std dev: 0.10630s window: 100
average rate: 11.917
min: 0.022s max: 0.572s std dev: 0.09033s window: 100
This difference is quite significant.
Moreover, ros2 topic hz
seems to cause a considerable load on the system, so that the rate of the C++ subscriber drops from ~25Hz to ~15Hz (ros2 topic hz drops to about 8Hz in this case).
As ros2 topic hz
is written in python I also tried setting PYTHONOPTIMIZE=0
as suggested here, however with no effect on the results.
For comparison reasons, I tested a similar setup with ROS(1) melodic, where rostopic hz
provides accurate and stable results.
Which leads me to the following questions:
- What could cause this significant difference of the measured rates? (related to QoS settings?)
- Is it possible to improve the performance of
ros2 topic hz
in some way? - What is the recommended way of measuring rates of larger messages such as point clouds or images in ros2?
ros2 topic hz
causing an unexpected load on the system and outputing a seemingly lower/bad rate is "known." I thought I had seen work being done on it in the past 6 months, but I can't find anything. Not sure what can be done though. It might be worth opening a bug and see what the maintainers say: https://github.com/ros2/ros2cli/issues@christophebedard thank you very much for your reply. It is good to know, that I am not the only one facing this issue and that this is not caused by my specific setup/configuration. I will go forward and open an Issue on GitHub as you suggested.
Hello, the subscriber "pointcloud2", was it developed by you or does it already exist in a package? I need to subscribe to a topic to get the message rate, but without using the "ros2 topic HZ" command due to its latency.
@Bruno Arieira
pointcloud2_subscriber
is just a simple C++ subscriber that increments a counter whenever a new message is received with an additional timer callback that logs the number of received messages in a given time interval. It was actually very similar to the Simple Cpp Publisher and Subscriber Tutorial (which also includes a timer in the publisher) except that I additionally specified the required QoS when creating the publisher.It was meant just as a quick comparison to
topic hz
. Depending on your use case you might need something more advanced (e.g. include filtering etc.)