CPU usage 4x higher in ROS 2 than ROS 1
Description
Hello,
When testing the same MAVROS set of plugins and stream rates, we observe MAVROS on ROS 2 using 4x the CPU usage of ROS1. Is this expected, or are there any mitigations?
Enabled Plugins:
/mavros/cmd
/mavros/debug_value
/mavros/distance_sensor
/mavros/geofence
/mavros/global_position
/mavros/gps_input
/mavros/gpsstatus
/mavros/guided_target
/mavros/imu
/mavros/local_position
/mavros/mavros
/mavros/mavros_node
/mavros/mavros_router
/mavros/mission
/mavros/nav_controller_output
/mavros/rangefinder
/mavros/rc
/mavros/setpoint_raw
/mavros/sys
/mavros/terrain
/mavros/time
/mavros/transform_listener_impl_aaab0c310108
/mavros/vfr_hud
/mavros/wind
ROS DIstro: Jazzy Middlware: FastDDS
Best, Ryan
ROS 1
TBD
ROS 2 top
Well, ROS2 version is by design have more nodes as of each plugin is a node. DDS also can have more consumption, don't know. Ideally i'd like to see something OTEL for ROS2.
I'll do my best to find a way to reproduce this in SITL, outside of our hardware. We suspect that changing executors may help.
The events executor in ROS 2 jazzy helps a lot, but seemed to cause service failures only in mavros. It's a oneline change to switch from the multithreaded executor to events executor in mavros.
There are few plugins which may have locks in the callbacks, which likely may hung in event executor. That's why i believe at least 2 threads required.
Or to switch to some modern C++2x with "light threads" or coroutine-aware mutexes.