Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider different executor #1

Open
zflat opened this issue Dec 13, 2022 · 1 comment
Open

Consider different executor #1

zflat opened this issue Dec 13, 2022 · 1 comment

Comments

@zflat
Copy link

zflat commented Dec 13, 2022

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 ros2/rclcpp#1034 and ros2/rclcpp#873

After switching rclcpp::executors::MultiThreadedExecutor executor; to rclcpp::executors::StaticSingleThreadedExecutor executor; I suggest testing to see if CPU usage decreases.

@v-kiniv
Copy link
Owner

v-kiniv commented Dec 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants