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

2023-05-16

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() ,它定义了在消息丢失之前的最大队列大小。
当publish()被调用时,会把串行化了的数据发到每一个subscriber,连接会异步地发生自不同的线程,但串行化仍将同步地发生。这就使得只有出现连接问题的subscriber会接收不到新的消息。
如果你发布消息的速度快于rospy能发送出去的速度,rospy会把老的messges丢掉。
注意,传输层上还会有个操作系统级的序列,比如TCP/IP发送buffer.

如何选择queue_size值:

  • 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.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ROS进二阶学习笔记(10) -- rospy.Publisher() 之 queue_size 的相关文章

  • 如何缩小自定义 Skobbler 离线地图应用程序的大小

    我正在将 Skobbler 地图集成到我的 iOS 应用程序中 目前 该应用程序的大小为 160Mb 这太大了 但我注意到已经集成了一堆地图 我想删除所有地图并让用户下载他需要的地图 现在 当我包含 SKMaps framework 时 其
  • Android 位图图像大小

    我正在从网络下载图像 并使用图库小部件来显示图像 如果下载的图像很大 我的应用程序会崩溃并显示以下日志 E GraphicsJNI 3378 VM won t let us allocate 5591040 bytes 仅当图像大小达到会使
  • “入队”和“出队”之间的区别

    有人可以解释一下主要区别吗 我对任何语言编程中的这些函数都没有明确的了解 C 和 C 等编程语言中的一些基本数据结构是堆栈和队列 堆栈数据结构遵循 先进后出 策略 FILO 其中插入或 推入 堆栈的第一个元素是最后一个从堆栈中删除或 弹出
  • Java 中保存最后 N 个元素的大小受限队列

    关于 Java 库的一个非常简单快速的问题 是否有一个现成的类可以实现Queue具有固定的最大大小 即它始终允许添加元素 但它会默默地删除头元素以为新添加的元素提供空间 当然 手动实现它很简单 import java util Linked
  • FFT 的窗口大小与数据长度

    我正在尝试对流音频数据进行快速频谱分析以捕获元音 类似于 JLip sync 使用 PyAudio 在短时间内 0 0625 秒 捕获小块 1024 的语音数据 使用 numpy fft 进行分析 并使用 numpy hanning 窗口消
  • 如何检查视频文件是否大于2MB?

    假设我从 iPhone 库中获取了一个视频文件 我想检查视频文件不应大于 2MB 我无法使用 videoMaximumDuration 方法 因为如果任何视频是高清质量的 即使是 1 分钟持续时间的视频也可能会很大 有什么意见吗 urlvi
  • 用于 SQL 更新语句的 Java 单工作线程

    我正在开发一个基于 Java 的服务器 其中有多个线程 每个连接的用户一个线程 一些额外的线程 会涉及到一些数据库连接 所以我在想服务器每次创建一个SELECT查询数据库时 它将为此启动一个新线程 以防止当前线程阻塞 我计划为此使用连接池
  • 通过值获取 std::queue 中元素的索引

    有没有一种简单的方法来获取元素在 a 中的位置std queue通过它在 C 中的值 例如 std queue
  • 如何在 Kivy 中设置小部件/布局的最小允许宽度/高度?

    我有包含 3 个元素的 BoxLayout 我需要第一个和最后一个元素占据最小的可用空间 中间元素具有固定比例 1 1 因此当我调整窗口大小时 侧面元素变得太小并且内容会超出其中 我需要例如标签 或按钮 甚至不同元素的集合 文本始终insi
  • 如何向队列发送参数?

    请考虑以下工作
  • C# 中类实例的内存使用情况[重复]

    这个问题在这里已经有答案了 可能的重复 C NET 对象使用多少内存 https stackoverflow com questions 426396 how much memory does a c net object use 就像标题
  • 如何设置按钮的大小?

    我将按钮放在带有 GridLayout 的 JPane 中 然后我用 BoxLayout Y AXIS 将 JPanel 放入另一个 JPanel 中 我希望 GridLayout 中的按钮是方形的 我使用 tmp setSize 30 3
  • GCD获取队列名称/标签

    如何获取当前队列名称 我的意思是队列标签com example myqueue 在 Xcode 4 调试器中我只能看到 block invoke 1 怎么样dispatch queue get label http developer ap
  • Java Reflection - 获取数组对象的大小

    我想知道是否有人知道如何使用反射获取数组对象的大小 我有一个Vehicles包含类型数组对象的组件Car 车辆 java public class Vehicles private Car cars Getter and Setters C
  • 我如何在 C++ 中将数组存储到队列

    queue lt int gt qq for int i 0 i lt N i int cc 2 i i 1 qq push cc N很大但不精确 所以我想使用队列 我想存储很多数组来排队 但是 qq 存储的数组是同一个 我该怎么做 你的代
  • 如何获取队列中的第 n 个项目?

    我的应用程序中有许多队列和优先级队列 我想轻松访问这些队列中的第 n 个项目 但没有看到使用 API 实现此目的的简单方法 我想我可以创建一个Iterator并迭代到第 n 个元素或使用toArray index 但似乎应该有一个更简单的方
  • Laravel:运行队列:在 Windows Azure Web App 上连续监听

    我觉得问这个问题有点傻 但我似乎无法在互联网上找到这个问题的答案 经过几个小时的搜索后 我发现在 Linux 服务器上 您使用 Supervisor 在您的网站上连续运行 php artisanqueue listen 无论有或没有守护进程
  • 为什么 std::queue 使用 std::dequeue 作为底层默认容器?

    继续阅读cplusplus com http www cplusplus com reference queue queue std queue实现如下 队列被实现为容器适配器 这些类 使用特定容器类的封装对象作为其 底层容器 提供一组特定
  • 为什么Android应用程序在发布到市场后尺寸会增加?

    我最近在 Android 市场上发布了我的应用程序 显示应用程序大小为 5 4MB 而实际 apk 大小为 2 8MB 为什么显示多出2MB 我应该如何限制我的应用程序大小 请帮我 您的应用程序大小会增加 因为您使用了复制保护选项ON在发布
  • Laravel 异常队列最大尝试次数超出

    我创建了一个应用程序来向多个用户发送电子邮件 但在处理大量收件人时遇到问题 该错误出现在failed jobs table Illuminate Queue MaxAttemptsExceededException App Jobs ESe

随机推荐