mavros icon indicating copy to clipboard operation
mavros copied to clipboard

ROS2 very high CPU usage when several instances are launched at once

Open vidalperezbohoyo opened this issue 6 months ago • 3 comments

Context

I'm working with ROS2 and attempting to replicate a setup that works correctly in ROS1: launching multiple instances of SITL (ArduPilot Copter v4.5.7) and MAVROS2 on the same PC for multi-UAV simulation.

Problem

When I launch multiple instances (between 4 to 7) of SITL + MAVROS2 simultaneously on an Intel i7-12700H (20 threads), CPU usage spikes close to 100% in every core.
Each MAVROS2 process consumes around 250% CPU (2.5 cores), and the usage never decreases over time.

Image

As a result, ROS2 service calls to MAVROS2 either receive no response or the callbacks are not triggered—likely because other callbacks are consuming too much CPU.

Interestingly, if I stagger the launch of each MAVROS2 + SITL instance by 30 seconds, the CPU usage per MAVROS2 process drops to ~40%, and all simulated drones operate correctly.

Note: However, if we want to simulate a large number of UAVs, waiting 30 seconds between each instance is not a viable solution. This workaround does not scale and significantly increases the total setup time.

Image

Steps to Reproduce

At the same time (with a script or launch.py):

  • Launch mavros_node with the px4_config.yaml and px4_pluginlists.yaml from the mavros package.
    Each instance with different tgt_system and fcu_url

  • Launch SITL with:

    /home/user/Libraries/ardupilot/ardupilot-Copter-v4.5.7/Tools/autotest/sim_vehicle.py -N -I <tgt_system> -l ,,1003,285 -v ArduCopter --frame quad

  • Repeat the process with a 30-second delay between each instance launch and compare behavior.

Expected Behavior

  • Simultaneous Launch:

    • Each MAVROS2 instance consumes about 250% CPU
    • CPU usage does not decrease over time
    • ROS2 service calls may fail or hang due to callback starvation
  • Staggered Launch (30s delay):

    • MAVROS2 instances initially spike in CPU usage
    • CPU usage drops to 30–40% per instance after a few seconds
    • All simulated UAVs operate as expected

Note:
Each SITL process uses approximately 10% CPU
(Significantly less than MAVROS2 or mavproxy.py)

vidalperezbohoyo avatar Jun 24 '25 08:06 vidalperezbohoyo

我的mavros运行在树莓派有限资源的树莓派上,cpu占用率能达到恐怖的80~90,根本无法运行其余的程序

guang544 avatar Jul 01 '25 14:07 guang544

Need to run it under profiler to find out where it spend all that cpu time. Since in v2 each plugin is a Node, i assume that RMW takes a lot to build all the connections...

Can you also try to run a separate Router and the UAS? And what DDS library used?

vooon avatar Jul 02 '25 08:07 vooon

Relates to https://github.com/mavlink/mavros/issues/2031

Ryanf55 avatar Sep 22 '25 18:09 Ryanf55