mavros icon indicating copy to clipboard operation
mavros copied to clipboard

CPU usage 4x higher in ROS 2 than ROS 1

Open Ryanf55 opened this issue 8 months ago • 4 comments

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

Image

Ryanf55 avatar Apr 22 '25 18:04 Ryanf55

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.

vooon avatar Apr 25 '25 18:04 vooon

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.

Ryanf55 avatar Apr 25 '25 19:04 Ryanf55

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.

Ryanf55 avatar Sep 22 '25 18:09 Ryanf55

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.

vooon avatar Sep 24 '25 08:09 vooon