Multiple publishers in single node

asked 2021-11-03 05:08:28 -0500

BhanuKiran.Chaluvadi gravatar image

updated 2021-11-04 02:33:44 -0500

Hi ,

I have a multiple publishers (~20) running on a single thread and each has their own topic to publish, in other words no two publishers publish to a same topic. My node/thread has only publishers (zero subscribers) and my thread has a requirement of loop rate 500 Hz (2 ms).

The loop rates is achieved when only few topic were subscribed but when i run ros2 bag record -a the loop rate is not achieved. After lttng user space tracing we figured once in a while publisher->publish(msg) is consuming more time than expected.

I am wondering if publisher->publish(msg) hold a mutex in a very low level ? Does it hold mutex on io / network card etc . Any suggestion to speed up the loop rate ?

edit retag flag offensive close merge delete


You tagged this question as multi-thread, but your description is of a single thread implementation.

How big are your output queues? How big are these messages that are being published? Expecting to sustain 0.1 milliseconds per message seems very optimistic to me, even on server-class hardware.

If this were a ros1 question, I'd wonder if you were passing a ::Ptr to publish(), and how many spinners you had allocated for roscpp.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-11-03 08:46:51 -0500 )edit

@ Mike Scheutzow Does publishes also have queues like subscribers ? I have seen this articles explaining problems with subscription and how multithreaded_executor/thread helps in that regard. But none when it comes to publishers.

BhanuKiran.Chaluvadi gravatar image BhanuKiran.Chaluvadi  ( 2021-11-03 09:04:58 -0500 )edit

@Mike Scheutzow We have only single spinner. I know that it will effect subscriber call backs but not sure about the publishers. Also when ever i define a publisher the queue size is always 1 as if now.

BhanuKiran.Chaluvadi gravatar image BhanuKiran.Chaluvadi  ( 2021-11-03 09:09:21 -0500 )edit

Which version of ros2 are you using? If you are using foxy, are you using the improved implementation of rosbag2?

You could also look at this post for suggestions on improving publisher speed

shonigmann gravatar image shonigmann  ( 2021-11-03 11:43:53 -0500 )edit