support services run with multiple threads#315
support services run with multiple threads#315iuhilnehc-ynos wants to merge 10 commits intoros2:masterfrom
Conversation
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
…ubsciption Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
|
This patch is to:
running without this patch, the log as following,
running without this patch, the log as following, Notice that supporting the service with running multiple threads is for not only the one service(a custom callback group with reentrant set by user) but also multiple different services. Could somebody help to review this PR? |
and resotre the original main loop logic Signed-off-by: Chen Lihui <lihui.chen@sony.com>
to fix 'Not all nodes were finished before finishing the context' since ros2 PublisherBase passed into ros1 subscriber as parameter which might be freed after ros2 context. Signed-off-by: Chen Lihui <lihui.chen@sony.com>
|
The failure about |
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
include/ros1_bridge/factory.hpp
Outdated
| auto group = node_base->get_default_callback_group(); | ||
| if (topic_name.empty()) { | ||
| // create a callback group with Reentrant for creating ros2 clients and services | ||
| static auto s_shared_callbackgroup = |
There was a problem hiding this comment.
do we need this static memory? how about returning ros2_node->create_callback_group(rclcpp::CallbackGroupType::Reentrant) instead?
There was a problem hiding this comment.
I want to reuse only one callbackgroup for all services and clients.
include/ros1_bridge/factory.hpp
Outdated
| } | ||
|
|
||
| typedef std::map<std::string, rclcpp::CallbackGroup::SharedPtr> TopicCallbackGroupMap; | ||
| static TopicCallbackGroupMap s_topic_callbackgroups; |
There was a problem hiding this comment.
instead of introducing static auto s_shared_callbackgroup, can we have everything in this map including rclcpp::CallbackGroup::SharedPtr for service and client?
There was a problem hiding this comment.
Using a specific string as a key is difficult and seems a little ugly, that's the reason why I introduce another static variable. If we can make an agreement, I'll update it. To use shared-callbackgroup as a key, which is not a valid topic name due to the character -, after that, it will not conflict with other topic names. what do you think?
There was a problem hiding this comment.
Maybe I can just use the empty string as the key
src/dynamic_bridge.cpp
Outdated
|
|
||
| // ROS 1 asynchronous spinner | ||
| ros::AsyncSpinner async_spinner(1); | ||
| ros::AsyncSpinner async_spinner(0, &ros1_callback_queue); |
There was a problem hiding this comment.
this will use the all cores in the system to spin. i think using Single or Multi threaded executor is dependent on the use case. for example, someone just bridge the certain topic only, in that case we do not need Multi threaded executor.
i think at least we would want to provide the option for user, then user can decide what they need.
There was a problem hiding this comment.
OK, I'll introduce an option, and also append an argument (bool multithread = false) to some methods to check if it's necessary to create a custom callbackgroup or not.
src/dynamic_bridge.cpp
Outdated
|
|
||
| // ROS 2 spinning loop | ||
| rclcpp::executors::SingleThreadedExecutor executor; | ||
| rclcpp::executors::MultiThreadedExecutor executor; |
Co-authored-by: Tomoya Fujita <Tomoya.Fujita@sony.com> Signed-off-by: Chen Lihui <lihui.chen@sony.com>
Signed-off-by: Chen Lihui <lihui.chen@sony.com>
fujitatomoya
left a comment
There was a problem hiding this comment.
overall this looks good to me. but i guess we need to discuss on the changes in community.
| bool bridge_all_topics = get_flag_option(args, "--bridge-all-topics"); | ||
| bridge_all_1to2_topics = bridge_all_topics || get_flag_option(args, "--bridge-all-1to2-topics"); | ||
| bridge_all_2to1_topics = bridge_all_topics || get_flag_option(args, "--bridge-all-2to1-topics"); | ||
| multi_threads = get_flag_option(args, "--multi-threads"); |
There was a problem hiding this comment.
option either all core will be used or single thread would be okay, but how about option to choose number of threads? 0 means all core threads, and if more threads are specified than platform possesses then print warning to use all core threads.
There was a problem hiding this comment.
I think this needs to be discussed.
There was a problem hiding this comment.
Yeah, maybe some guys want to set two different values for the threads count of ros1 and ros2 spinner.
|
@clalancette @sloretz friendly ping. |
|
Any chance in this getting merged? @iuhilnehc-ynos @sloretz @clalancette |
|
I am sorry about not figuring out an elegant fix for this. The answer is no for this PR, at least. |
| // ROS 1 asynchronous spinner | ||
| ros::AsyncSpinner async_spinner(1); | ||
| async_spinner.start(); | ||
| std::unique_ptr<ros::AsyncSpinner> async_spinner = nullptr; |
There was a problem hiding this comment.
May be we create one more thread here and use ros::MultiThreadedSpinner?
Fixes #314
Signed-off-by: Chen Lihui lihui.chen@sony.com