Open zflat opened 1 year ago
Hi @zflat, I'm aware of the callback groups, etc. In my case, it is using multiple threads(I tested by printing log message with thread ID inside subscription callback), even though it shouldn't, because groups are not assigned, as you said. Looks like something is broken in rclcpp, at least on Mac, or I'm missing something. My initial intention was to have one thread per client, so I was assigning the client's callbacks to MutuallyExclusive group, but the executor was still calling callbacks assigned to single MutuallyExclusive group in multiple threads, as if I assigned them to Reentrant group, go figure. However, I didn't change the executor to StaticSingleThreadedExecutor because in my case it's better to have multiple threads per multiple clients than single thread per multiple clients.
Right now, I don't have time, but I want to come back to this issue later, and also test more on Linux, to see how executors behave there. If you'd like and know how to help, feel free to contribute. Thanks.
Hi @v-kiniv
The multithreaded executor is not actually using more than one thread. In order to achieve that you need multiple callback groups, see the example at https://github.com/ros2/examples/blob/95c3b145e4f75c24e1617d97acc3d349ad67e78f/rclcpp/executors/multithreaded_executor/multithreaded_executor.cpp#L78-L81
However, to minimize CPU usage, I suggest testing out the "static" single threaded executor. See https://github.com/ros2/rclcpp/pull/1034 and https://github.com/ros2/rclcpp/pull/873
After switching
rclcpp::executors::MultiThreadedExecutor executor;
torclcpp::executors::StaticSingleThreadedExecutor executor;
I suggest testing to see if CPU usage decreases.