You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
High CPU usage when using MultiThreadedExecutor & TimerCallback #1618
checked with source build ros2/ros2@0e6cc1c, i cannot reproduce the problem.
terminal-1
root@134f29e8f25f:~/ros2_ws/colcon_ws# ros2 run sample sample
[INFO] [1617930704.586983609] [chatter]: update is called
[INFO] [1617930705.587006977] [chatter]: update is called
[INFO] [1617930706.587756538] [chatter]: update is called
...<snip>
there is a lot of race condition, and this makes really hard to remove executed Timer from the list. on the other hand, other threads just keep trying to get mutex and execute the Timer (which is already scheduled). this loop runs and consumes CPU resources.
btw, i do not think MutexTwoPriorities is perfect solution. in theory Timer should be taken by thread once, and nobody else needs to get that Timer via get_next_executable.
i might be missing something, any comments are welcome 😄
I'm writing on behalf of @k0suke-murakami. Thank you for your information. We have confirmed that the CPU usage decreased significantly on master. (We were originally testing on foxy)
Do you know if this feature is going to be back-ported to foxy?
as far as i see, it will break the ABI. so i guess it is unlikely to happen...but i think this could change user experience significantly.
Yes, if it changes ABI, we can't put it into Foxy. However, if someone were to come up with an ABI-compatible version of it, we could consider putting that into Foxy.
Activity
fujitatomoya commentedon Apr 9, 2021
checked with source build ros2/ros2@0e6cc1c, i cannot reproduce the problem.
Karsten1987 commentedon Apr 9, 2021
We had the same issue over at ros2-control: ros-controls/ros2_control#275
Even without any load, the multithreaded executor would exhaust all CPU and could not achieve the desired update rates.
fujitatomoya commentedon Apr 9, 2021
I think this can be also fixed by #1516, which introduces MutexTwoPriorities to reduce race condition for
get_next_executable.before MutexTwoPriorities, it is really hard to remove
Timerwithrclcpp/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp
Line 109 in 6a1b6a3
it is because the same mutex
wait_mutex_is used withget_next_executablerclcpp/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp
Line 79 in 6a1b6a3
there is a lot of race condition, and this makes really hard to remove executed
Timerfrom the list. on the other hand, other threads just keep trying to get mutex and execute theTimer(which is already scheduled). this loop runs and consumes CPU resources.btw, i do not think MutexTwoPriorities is perfect solution. in theory
Timershould be taken by thread once, and nobody else needs to get thatTimerviaget_next_executable.i might be missing something, any comments are welcome 😄
mitsudome-r commentedon Apr 9, 2021
@Karsten1987 @fujitatomoya
I'm writing on behalf of @k0suke-murakami. Thank you for your information. We have confirmed that the CPU usage decreased significantly on master. (We were originally testing on foxy)
Do you know if this feature is going to be back-ported to foxy?
fujitatomoya commentedon Apr 9, 2021
good to know 👍 thanks for the confirmation.
as far as i see, it will break the ABI. so i guess it is unlikely to happen...but i think this could change user experience significantly.
@ivanpauno @clalancette what do you think about this backport?
clalancette commentedon Apr 9, 2021
Yes, if it changes ABI, we can't put it into Foxy. However, if someone were to come up with an ABI-compatible version of it, we could consider putting that into Foxy.
mitsudome-r commentedon Apr 9, 2021
Thanks. We will take a deeper look into #1516 and see if we can do that without breaking the ABI.
ivanpauno commentedon Apr 9, 2021
I cannot imagine a ABI compatible fix for this, but if someone can figure out a ABI compatible fix that would be great.
The bug is fixed in master though, so I think that we can close this ticket.
@mitsudome-r @k0suke-murakami do you think that's ok.