ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size

原创 2017年01月17日 14:55:54

ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size

ref  link


queue_size: publish() behavior and queuing

publish() in rospy is synchronous by default (for backward compatibility reasons) which means that the invocation is blocking until:

  • the messages has been serialized into a buffer
  • and that buffer has been written to the transport of every current subscriber

If any of the connections has connectivity problems that might lead to publish() blocking for an indefinite amount of time. This is a common problem when subscribing to topics via a wireless connection.

(sonictl: publish() 在rospy 里是同步进行的,为了向老版兼容。这就意味着对消息的调用会出现阻塞。直到:
      >> message 序列性地进入 buffer
      >> 并且buffer 已经被写入每一个subscriber的 transport(运输机)
如果这些连接出现任何连接性问题, 会导致 publish() 函数阻塞长达一个不确定的时间。这是通过无线网连接时,常见的问题。)

自从 hydro 以后,推荐使用新的 asynchronous ,异步的,发布机制,它更像是roscpp的做法。

为了使用新的发布机制,the keyword queue_size 就要传给 subscribe() ,它定义了在消息丢失之前的最大队列大小。


  • 0 - 无限长的buffer,直到被取走,不扔掉。可能会导致取不过来,内存耗尽掉~不推荐。
  • 1, 2, 3, - 基本上1秒能有10次数据处理能力的话(),这种小的buffer 就够了。对于只关心最新的值的情况,最适用。
  • 10或更多 - 用户界面msg 是比较好的例子,这种东东不能丢失。另一个例子就是当你想要记录所有的值,这样的值又是高速发布的。

Choosing a good queue_size

It is hard to provide a rule of thumb for what queue size is best for your application, as it depends on many variables of your system. Still, for beginners who do not care much about message passing, here we provide some guidelines.

If you're just sending one message at a fixed rate it is fine to use a queue size as small as the frequency of the publishing.

If you are sending multiple messages in a burst you should make sure that the queue size is big enough to contain all those messages. Otherwise it is likely to lose messages.

Generally speaking using a bigger queue_size will only use more memory when you are actually behind with the processing - so it is recommended to pick a value which is bigger than it needs to be rather than a too small value.

But if your queue is much larger than it needs to be that will queue up a lot of messages if a subscriber is lagging behind. This might lead to messages arriving with large latency since all messages will be delivered in FIFO order to the subscriber once it catches up.

queue_size Omitted

If the keyword argument is omitted, None is passed or for Groovy and older ROS distributions the publishing is handled synchronously. As of Indigo not passing the keyword argument queue_size will result in a warning being printed to the console.

queue_size None

Not recommended. Publishing is handled synchronously which means that one blocking subscriber will block all publishing. As of Indigo passing None will result in a warning being printed to the console.

queue_size Zero

While a value of 0 means an infinite queue, this can be dangerous since the memory usage can grow infinitely and is therefore not recommended.

queue_size One, Two, Three

If your system is not overloaded you could argue that a queued message should be picked up by the dispatcher thread within a tenth of a second. So a queue size of 1 / 2 / 3 would be absolutely fine when using 10 Hz.

Setting the queue_size to 1 is a valid approach if you want to make sure that a new published value will always prevent any older not yet sent values to be dropped. This is good for, say, a sensor that only cares about the latest measurement. e.g. never send older measurements if a newer one exists.

queue_size Ten or More

An example of when to use a large queue size, such as 10 or greater, is user interface messages (e.g. digital_io, a push button status) that would benefit from a larger queue_size to prevent missing a change in value. Another example is when you want to record all published values including the ones which would be dropped when publishing with a high rate / small queue size.


  • zong596568821xp
  • zong596568821xp
  • 2017年09月25日 19:06
  • 803


开始之前,首先要认识一下ROS里面的传感器1 Imu.msg 陀螺仪数据,加速度m/s2,旋转速度rad/s, (1)Header header 时间戳与坐标系 (2)geometry_msgs...
  • u010256153
  • u010256153
  • 2017年02月08日 10:35
  • 2571


分析的内核版本截止到2014-04-15,基于1.05正式版,blogs会及时跟进最新版本的内核开发进度,若源码注释出现”???”字样,则是未深究理解部分。         Raw-OS官方网站:ht...
  • tortoisechan
  • tortoisechan
  • 2014年06月30日 08:39
  • 1067


我的C++功底很差,除了自己看着视频学了一点,就是在波特兰的天坑小学里某不是教授的教授讲的东西。所以人生苦短,我选择Python。 Rospy是什么 Rospy官方wiki Rospy是ROS对...
  • seeseeatre
  • seeseeatre
  • 2018年01月27日 10:35
  • 89


转自 ROS的单线程Spinning和多线程Spinning 单线程Spinning ros::spin()是最简单的单线程自旋, 它会一直调用直到结束 用法:  ros::spin(); ...
  • yngki
  • yngki
  • 2016年12月02日 17:53
  • 1468


ROS笔记:Python@(ROS)[ROS|Python|rospy|环境变量] 记录并分析ROS的整个Python系统体系,争取搞清楚内部原理。同时深入学习Python编程。ROS笔记Pytho...
  • keyearth
  • keyearth
  • 2015年06月02日 13:40
  • 8809


Queue简介 ² queue是队列容器,是一种“先进先出”的容器。 ² queue是简单地装饰deque容器而成为另外的一种容器。 ² #include   queue对象的默认构造 q...
  • sum_TW
  • sum_TW
  • 2017年02月13日 23:54
  • 2004


1.mkdir -p ~/catkin_ws/src/beginner_tutorials/src 先在beginner_tutorials下创建一个src。 -p的意思是如果路径中有不存在的文件夹...
  • BenjaminYoung29
  • BenjaminYoung29
  • 2015年08月02日 21:36
  • 1555

ROS相关:使用rospy 编写ros程序并使用rosbag存储数据

  • songrotek
  • songrotek
  • 2016年03月03日 16:22
  • 8297

ROS进二阶学习笔记(8)-- 关于rospy 和 parameters

rospy + params的使用方法
  • sonictl
  • sonictl
  • 2017年01月11日 17:53
  • 1923
您举报文章:ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size