Ask Your Question
6

Why publish if no one is subscribing?

asked 2014-06-17 07:43:28 -0600

Airuno2L gravatar image

Although it sounds like something my wife probably wonders about me sometimes - why do I talk if no one is listening? - I've wondered the same thing many times about a ROS publisher. I've never ran into any problems as long as everything is running on the same computer, but when I'm using two computers communicating over wireless, having data flow across the network that isn't getting used is costly.

As an example, I have a pioneer with a kinect on it, most of the time the robot is in an autonomous mode and I don't use the wireless, but sometimes I want to teleoperate the robot and use the kinect's camera to see where I'm going. But running the openni node publishes a TON of data, even when I turn off almost everything in the launch file. There's so much data with all the different video feeds that the network gets flooded and the lag in the video makes it unuseable. Usually I'll just dive in hacking the code and cut out all unneeded topics and create a specialized node, but is there a better way?

When I'm creating my own nodes that produce a lot of data, I usually use the publisher.getNumSubscribers() function to check if anyone is listening to a topic before publishing anything. My question is, is there a reason that all publishers don't do something similar by default? Would it be possible to add this capability to the core publisher code? Or is there something I'm missing?

Thanks, Aaron

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
5

answered 2014-06-17 07:58:10 -0600

dornhege gravatar image

I think something in your conclusion does not match what is happening (or should be happening). First, if no one is subscribing over the network, then nothing should be happening when you publish, i.e. if network bandwidth is wasted somewhere, there must be some connection between a publisher and subscriber (rviz counts!). This is already somewhat implicitly in the core code as if there are no connections, there is no where to send to. I would also highly assume that there is no marshalling when no subscribers are present.

The publisher.getNumSubscribers() check should thus be useless - _unless_ there are some costly computations going on to create the actual message. Point Clouds from the Kinect are a good example. However, AFAIK the openni driver already does this. Now, the Kinect seems to be a somewhat special case. At least in our observation it seems that producing registered RGB point clouds for some reason is way more costly then XYZ point clouds or images alone. This does not seem to be a ROS problem, though. This might appear as if the network is clogged.

edit flag offensive delete link more

Comments

Oh, I was a little unclear. Say I have a two computer system and a node on computer 1 publishes two topics, A and B, both of which produce a bunch of data. Computer 2 only cares about topic A, however the node on computer 1 publishes topics A and B, even though no one is listening to topic B.

Airuno2L gravatar imageAiruno2L ( 2014-06-17 09:44:19 -0600 )edit

That should be perfectly fine. If only topic A is subscribed, no data is send for topic B - where would that be sent to?

dornhege gravatar imagedornhege ( 2014-06-17 12:51:37 -0600 )edit

Hmm, it appears on my system that all published data is sent to the other computer whether or not a topic is being subscribed to or not. It's not getting used, but that data is available on the 2nd computer and it uses up bandwidth. Are you saying this shouldn't be happening?

Airuno2L gravatar imageAiruno2L ( 2014-06-17 19:54:30 -0600 )edit
2

Where's it being sent to? All the information travels over TCP sockets, which need a process on each end.

Bill Smart gravatar imageBill Smart ( 2014-06-17 23:44:01 -0600 )edit

I have the same doubt, I have robot 1 and 2, robot 1 publishes topic A and B, but topic A is only used internally while topic B is used on robot 2, however robot 2 can see topic A and even if robot 2 does not use topic A, it can echo it, which makes me think that resources are being wasted.

Luis Ruiz gravatar imageLuis Ruiz ( 2016-03-25 06:18:47 -0600 )edit
2

Luis, I think what they were saying is that the data contained in topic B is only sent across the network if robot 2 asks for it. Robot 2 can always see that topic B exists, but the data isn't being sent until the echo command is entered.

Airuno2L gravatar imageAiruno2L ( 2016-03-25 06:43:52 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2014-06-17 07:43:28 -0600

Seen: 1,520 times

Last updated: Jun 17 '14