question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timer at high rate causes a high CPU usage on armhf

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lukicdarkoocommented, Oct 21, 2020

I cannot test it on Raspberry Pi now, but it seems it works ok on a PC:

import rclpy
from rclpy.node import Node


PUBLISH_PERIOD = 1e-3


class Test(Node):
    def __init__(self):
        super().__init__('test')
        self.timer = self.create_timer(PUBLISH_PERIOD, self.timer_callback)

    def timer_callback(self):
        pass


def main(args=None):
    rclpy.init(args=args)
    test = Test()
    rclpy.spin(test)
    test.destroy_node()
    rclpy.shutdown()


if __name__ == '__main__':
    main()

CPU reaches 100% utilization (on PC) only when PUBLISH_PERIOD = 1e-4 (10KHz), that seems to be reasonable I guess.

1reaction
hidmiccommented, Mar 21, 2020

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 and rclpy, both on amd64 and arm64. 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

High CPU usage when you enable the High Precision Event ...
In this situation, you experience high CPU usage on the computer. Cause. This issue occurs because the timer counter has a data path...
Read more >
How to find cause of high kernel_task cpu usage? - Ask Different
High kernel_task CPU Usage is due to high chassis temperature caused by charging. In particular Left Thunderbolt port usage.
Read more >
Troubleshooting high CPU usage
CPU usage can range from 0.0 for a process that is sleeping to higher values for a process that's taking a lot of...
Read more >
Chapter 19. Profiling CPU usage in real time with perf top
You can use the perf top command to measure CPU usage of different functions in real time. Prerequisites. You have the perf user...
Read more >
How to Fix High CPU Usage - Intel
“Turn it off and on again” is classic troubleshooting advice for a reason. This may resolve the issue, especially if it's been a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found