Faster rclpy executor now in Rolling

I’m announcing a new executor that’s now available for rclpy in Rolling, which is a port of the rclcpp EventsExecutor approach for use in Python. This was motivated by the large increase in CPU usage my company (Merlin Labs) experienced when porting an existing project from Noetic to Iron, most especially among our Python-based nodes. More background and benchmarks are available here, but the upshot is CPU usage has been observed to be as little as a tenth of that of the default SingleThreadedExecutor for some workloads!

Functionally, it should largely be a drop-in replacement substituting rclpy.experimental.EventsExecutor for rclpy.executors.SingleThreadedExecutor in your code. Being single threaded, it does functionally ignore all callback groups and treat every event as mutually exclusive in its current form. Additionally, it may start to get inefficient if you have a large number of ROS timers running in the same process.

This feature is expected to be part of the upcoming Kilted release, and there is also an effort underway to backport it to Jazzy.

19 Likes

Thanks million times for this work! I hope that once it’s tested and mature, it will find its way even to the beginners’ tutorials and become the default :slight_smile:

Most of our nodes never even specified one (like most tutorials). But I guess you can just replace
rclpy.spin(my_node)
by
rclpy.spin(my_node, rclpy.experimental.EventsExecutor)