-
Notifications
You must be signed in to change notification settings - Fork 299
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
support services run with multiple threads #315
base: master
Are you sure you want to change the base?
support services run with multiple threads #315
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I can just use the empty string as the key
src/dynamic_bridge.cpp
Outdated
@@ -784,11 +787,11 @@ int main(int argc, char * argv[]) | |||
|
|||
|
|||
// ROS 1 asynchronous spinner | |||
ros::AsyncSpinner async_spinner(1); | |||
ros::AsyncSpinner async_spinner(0, &ros1_callback_queue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
async_spinner.start(); | ||
|
||
// ROS 2 spinning loop | ||
rclcpp::executors::SingleThreadedExecutor executor; | ||
rclcpp::executors::MultiThreadedExecutor executor; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall this looks good to me. but i guess we need to discuss on the changes in community.
@@ -119,6 +123,7 @@ bool parse_command_options( | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be we create one more thread here and use ros::MultiThreadedSpinner?
Fixes #314
Signed-off-by: Chen Lihui lihui.chen@sony.com