[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users



Hi,
I was wondering if it's bad in terms of resources to have a great amount of publishers and subscriptions to the same topic in a single application / node or does ROS2/DDS manage them in the background ? Would it be better to have some kind of TopicManager that returns / manages instances of publishers/subscription inside an application. (And all classes that want to use a publisher ask the TopicManager for an instance of this publisher)


Also do I have to worry about a large amount of different topics in the system? Is the amount of topics somehow related to a increase in cpu / memory usage or do I just pay cpu/memory if I'm sending/recieving messages on a topic?

Lennart






---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/1) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users



[quote="firesurfer, post:1, topic:1391"]
I was wondering if it's bad in terms of resources to have a great amount of publishers and subscriptions to the same topic in a single application / node or does ROS2/DDS manage them in the background ? Would it be better to have some kind of TopicManager that returns / manages instances of publishers/subscription inside an application. (And all classes that want to use a publisher ask the TopicManager for an instance of this publisher)
[/quote]

I would say that is bad to have many instances of publishers or subscriptions on the same topic in the same node, if you can avoid it and you don't mind them sharing queues.

In ROS 1, at least publishers, and I think subscribers, for topics were singletons. I know that if you created a publisher on topic foo in one place, and in another part of the code you created a publisher on the same topic foo then you'd get a handle to the same publisher. This is bad, for example, when you wanted to specify a different queue size for each, see:

https://github.com/ros/ros_comm/pull/450

But is was good, on the other hand, for avoiding duplication of resources when you didn't mean to do so.

If it the same is true for subscribers in ROS 1 (I didn't check yet), then it could also be bad that they would share the same queue. Consider a subscriber with a queue size of 10 and the user creates two subscribers, each with a different callback but on the same topic. When a new message is received on the topic, does the message get delivered to both callbacks or just one? If it is delivered to both, what happens when one callback is really slow, does it keep the messages in the queue until all callbacks are done with each message?

In ROS 2 we wanted to make sure that each instance of a publisher or a subscription had the option to have their own queue. That makes the semantics clearer and it makes it possible to write code that cannot be interfered with from other code in the same process (which can be a concern when using the ROS API's from within a library or when making nodelets). The trade-off is that each time a user creates a publisher in ROS 2, there will a queue and any other associated overhead generated as well.

That all being said, I think that we make users aware of this, then making a singleton for your publishers and subscriptions is something the user can do on their own.

[quote="firesurfer, post:1, topic:1391"]
Also do I have to worry about a large amount of different topics in the system? Is the amount of topics somehow related to a increase in cpu / memory usage or do I just pay cpu/memory if I'm sending/recieving messages on a topic?
[/quote]

I don't think you need to worry about it too much. I'm not 100% certain about the overhead on the network, but you could expect some overhead in memory/cpu usage and possibly some overhead on network due to introspection and discovery processes. However, it would always be better to only create new publisher and subscription instances when you explicitly need a unique one with it's own settings and resources.






---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/2) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users
In reply to this post by Joshua Whitley via ros-users



Thanks for your detailed answer!
I'm going to create my own management class for publisher/subscriptions.

 [quote="wjwwood, post:2, topic:1391"]
I don't think you need to worry about it too much. I'm not 100% certain about the overhead on the network, but you could expect some overhead in memory/cpu usage and possibly some overhead on network due to introspection and discovery processes. However, it would always be better to only create new publisher and subscription instances when you explicitly need a unique one with it's own settings and resources.
[/quote]

As far as I can see every node creates some topics for interacting with a parameter server by default. Can I somehow disable this behaviour ?






---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/3) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users
In reply to this post by Joshua Whitley via ros-users



[quote="firesurfer, post:3, topic:1391"]
As far as I can see every node creates some topics for interacting with a parameter server by default. Can I somehow disable this behaviour ?
[/quote]

Not currently. Right now this publisher is always created:

https://github.com/ros2/rclcpp/blob/master/rclcpp/src/rclcpp/node_interfaces/node_parameters.cpp#L40-L45

We've often talked about adding an option to the node constructor which would avoid this, but we've always stopped short because we wanted to implement a proper way to pass lots of options to a node constructor other than lots of arguments, i.e. some sort of rclcpp specific node options struct.

However, if you proposed a new argument to the node constructor which disabled this topic, then I'd consider it for merge in the meantime.

[quote="firesurfer, post:3, topic:1391"]
I also have another implementation specific question: Is it possible to have a subscription call multiple callbacks?
[/quote]

Not right now, but we also would like to do that at some point. You can implement it trivially though, by creating a single callback for the subscription which then iterates over a list of callbacks, calling each in turn.

We thought about multiple callbacks for single subscriber in the context of multi threading and executors and callback groups but that's quite a bit more complicated and needs some more thought I think.






---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/4) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users
In reply to this post by Joshua Whitley via ros-users


So how do we have call backs from our publisher or subscriber? Has multiple call backs been enabled?





---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/5) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users
In reply to this post by Joshua Whitley via ros-users


[quote="arunava_nag, post:5, topic:1391"]
So how do we have call backs from our publisher or subscriber?
[/quote]

You can have one callback per subscription, I don't know why you'd have a callback for a publisher. We might have callbacks for events like when a subscription is matched on a publisher or something like that, but in typical use cases you'd never have a callback on a publisher...

[quote="arunava_nag, post:5, topic:1391"]
Has multiple call backs been enabled?
[/quote]

No, but as I said above, you can have your own list of callbacks which you call in your subscriptions single callback.





---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/6) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>
Reply | Threaded
Open this post in threaded view
|

[Discourse.ros.org] [Next Generation ROS] Maximum amount of publisher / subscriptions per node

Joshua Whitley via ros-users
In reply to this post by Joshua Whitley via ros-users


My bad, I have edited my question. Typed out wrong while generalizing my question. No callbacks for publisher.





---
[Visit Topic](https://discourse.ros.org/t/maximum-amount-of-publisher-subscriptions-per-node/1391/7) or reply to this email to respond.


If you do not want to receive messages from ros-users please use the unsubscribe link below. If you use the one above, you will stop all of ros-users from receiving updates.
______________________________________________________________________________
ros-users mailing list
[hidden email]
http://lists.ros.org/mailman/listinfo/ros-users
Unsubscribe: <http://lists.ros.org/mailman//options/ros-users>