creation hundreds of nodes

asked 2020-01-16 23:43:38 -0600

marney gravatar image

Now, I try to create many nodes and investigate behavior. Here is the code to create any number of subscribers for one topic topic_name. However, after number of nodes n exceeds around 100, $ ros2 node info /node_${any number} prints as follows.

I wonder that other DDS implementation instead of FastRTPS solve this issue. What is the reason ?

Thanks

Expected

/node_100
Subscribers:
/topic_name: std_msgs/msg/Int16
Publishers:
/rosout: rcl_interfaces/msg/Log
Services:
...

Actual

/node_100
Subscribers:

Publishers:

Services:

or

/node_100
[ERROR] [rmw_fastrtps_shared_cpp]: Unable to find GUID for node: node_147
Failed to get_subscriber_names_and_types: Unable to find GUID for node , at /tmp/binarydeb/ros-dashing-rmw-fastrtps-shared-cpp-0.7.6/src/rmw_node_info_and_types.cpp:87

The ROS 2 code is bellow.

#include <rclcpp/rclcpp.hpp>
#include <std_msgs/msg/int16.hpp>

int main(int argc,char*argv[]){
using namespace std_msgs::msg;
rclcpp::init(0, nullptr);

int n = 150; // create many nodes

rclcpp::executors::SingleThreadedExecutor exec; // create executor
std::vector<rclcpp::Node::SharedPtr> node_refs; // create vector to store node references
std::vector<rclcpp::Subscription<Int16>::SharedPtr> sub_refs; // create vector to store sub references

for (int i = 0; i < n; i++) { 
  auto node = std::make_shared<rclcpp::Node>("node_" + std::to_string(i)); // create a node
  auto sub = node->create_subscription<Int16>("topic_name", 10,
                                               [](Int16::SharedPtr) {}); // add a sub to the node
  sub_refs.push_back(sub); // save a referene to the sub
  node_refs.push_back(node); // save  a reference to the node
  exec.add_node(node); // add the node with the sub to executor
} 
exec.spin(); 
rclcpp::shutdown();
return 0;
}
edit retag flag offensive close merge delete