Are messages sent once per node or once per subscriber?

asked 2021-07-06 15:30:36 -0600

JunTuck gravatar image

updated 2021-07-06 15:36:35 -0600

Hi! My question is related but not identical to this.

If there are N subscribers in one node on Machine A, that are all listening to the same publisher from Machine B over Wifi, how are the messages handled exactly?

  1. Is one message being transmitted over Wifi and duplicated N times locally on Machine A?
  2. Are N messages being transmitted over Wifi?
  3. If N messages are being transmitted, does this mean the publisher has to serialize the same message N times?
edit retag flag offensive close merge delete

Comments

In ROS1, connections are peer-to-peer. I believe, option 2 is definitely Yes. About Option 3, i am not sure of implementation.

prince gravatar image prince  ( 2021-07-07 00:42:43 -0600 )edit

For question 3, see rospy's publish behavior and roscpp's publish behavior (they are slightly different).

abhishek47 gravatar image abhishek47  ( 2021-07-07 02:25:25 -0600 )edit

This seems to be a duplicate of #q289237.

From that answer:

Once all copies of a specific Subscriber go out of scope, the subscription callback associated with that handle will stop being called. Once all Subscriber for a given topic go out of scope the topic will be unsubscribed.

This implies that there may be multiple Subscriber (i.e., multiple callbacks) on the same topic.

Indeed, looking at roscpp/topic_manager.cpp, we can see that subscribe first attempts to reuse an existing Subscription on the requested topic. If there is one, the new callback is appended to the Subscription's list of callbacks (std::vector<CallbackInfoPtr>).

this corresponds to my own understanding and the roscpp documentation for NodeHandle::subscribe(..), which mentions shared_ptrs passed to callbacks must not be used to change the incoming msg.

This answer focuses on roscpp of course. But @JunTuck has not specified which client library he/she's using.

gvdhoorn gravatar image gvdhoorn  ( 2021-07-07 04:15:39 -0600 )edit