Timer at high rate causes a high CPU usage on armhf
See original GitHub issueI installed ROS2 Eloquent on Raspberry Pi Zero W and I have issues publishing messages at a high rate (~31Hz). The problem is high CPU usage and it is caused by calling a callback via create_timer()
. Therefore, even though the callback function does nothing (pass
) the CPU usage is still very high. Also, it seems the CPU usage rises linearly with callback calling rate, but I didn’t save the results support this (CPU usage is low for the timer running at 0.5s interval).
Required Info:
-
Operating System: Raspbian Buster
-
Installation type: from source
-
Version or commit hash: 42cabefef332c394cfa96f08f1e35fe1cd82e6b8
-
DDS implementation: Fast-RTPS
-
Client library (if applicable): rclpy
Steps to reproduce issue
For tests I used a simple publisher example given at: https://raw.githubusercontent.com/ros2/examples/master/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py with the following modifications:
- timer interval is set to 32/1000 (32ms) and
- logger method is deleted (
self.get_logger().info('Publishing: "%s"' % msg.data)
)
Expected behaviour
This is CPU and memory usage for equivalent example in C++ running on the same device: https://i.imgur.com/N093gQV.png
Actual behavior
The same test for the Python example: https://i.imgur.com/wO1cmsF.png
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (6 by maintainers)
I cannot test it on Raspberry Pi now, but it seems it works ok on a PC:
CPU reaches 100% utilization (on PC) only when
PUBLISH_PERIOD = 1e-4
(10KHz), that seems to be reasonable I guess.I do not have your exact same hardware to reproduce, nor a 32 bit ARM platform at hand, but I can see the significant gap between
rclcpp
andrclpy
, both onamd64
andarm64
. I’ll try do some profiling next week, see if there’s a clear bottleneck.You’re welcome to contribute as well. Thanks for reporting.