ZeroMQ - pub / sub延迟 [英] ZeroMQ - pub / sub latency

查看:1148
本文介绍了ZeroMQ - pub / sub延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找ZeroMQ,看看它是否适合软实时应用程序。我非常高兴地看到小有效载荷的延迟在30微秒左右的范围内。

I'm looking into ZeroMQ to see if it's a fit for a soft-realtime application. I was very pleased to see that the latency for small payloads were in the range of 30 micro-seconds or so. However in my simple tests, I'm getting about 300 micro-seconds.

我有一个简单的发布商和订阅者,基本上是从网络上的例子复制而来,通过localhost发送一个字节。

I have a simple publisher and subscriber, basically copied from examples off the web and I'm sending one byte through localhost.

我玩了两天w /不同 sockopts m出去。

I've played around for about two days w/ different sockopts and I'm striking out.

任何帮助将不胜感激。

pub

publisher:

#include <iostream>
#include <zmq.hpp>
#include <unistd.h>

#include <sys/time.h>


int main()
{
    zmq::context_t context (1);
    zmq::socket_t publisher (context, ZMQ_PUB);
    publisher.bind("tcp://*:5556");

    struct timeval timeofday;
    zmq::message_t msg(1);
    while(true)
    {
        gettimeofday(&timeofday,NULL);
        publisher.send(msg);
        std::cout << timeofday.tv_sec << ", " << timeofday.tv_usec << std::endl;
        usleep(1000000);
    } 
}  

sub scriber: / p>

subscriber:

#include <iostream>
#include <zmq.hpp>
#include <sys/time.h>


int main()
{
    zmq::context_t context (1);
    zmq::socket_t subscriber (context, ZMQ_SUB);
    subscriber.connect("tcp://localhost:5556");
    subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);

    struct timeval timeofday;
    zmq::message_t update;
    while(true)
    {
        subscriber.recv(&update);
        gettimeofday(&timeofday,NULL);
        std::cout << timeofday.tv_sec << ", " << timeofday.tv_usec << std::endl;
    }
}


推荐答案

任务定义real?



一旦谈到* - 实时设计,架构能力验证比下面的实现本身更重要。

Is the Task Definition real?

Once speaking about *-real-time design, the architecture-capability validation is more important, than the following implementation itself.

如果把你的源代码原样,你的读数(pitty,没有与您的代码片断一起交叉验证复制的MCVE重新测试)将不会提供太多,因为数字不区分在发送侧循环器上,在发送侧zmq数据获取/复制/ schedulling /线路级格式化/数据报调度上和在接收侧上花费的部分(什么时间量)从媒体卸载/复制/解码/模式匹配/传播到接收缓冲区

If taking your source code as-is, your readings ( which are pitty that were not posted together with your code-snippets for a cross-validation of replicated MCVE-retest ) will not serve much, as the numbers do not distinguish what portions ( what amounts of time ) were spent on sending-side loop-er, on sending side zmq-data-acquisition/copy/schedulling/wire-level formatting/datagram-dispatch and on receiving side unloading from media/copy/decode/pattern-match/propagate to receiver buffer(s)

如果对ZeroMQ内部组件感兴趣,可以使用良好的性能相关应用笔记。

If interested in ZeroMQ internals, there are good performance-related application notes available.

如果要争取最小延迟设计,请执行以下操作:

If striving for a minimum-latency design do:


  • 删除所有开销


    • 替换 tcp PUB / SUB 频道

    • 避免所有非主要来自处理的逻辑开销(无意义,在 sub scribe端花费时间(确实,较新版本的ZMQ已经转移到 pub lisher端过滤,但这个想法很清楚)使用在所选原型处理中编码的模式匹配(使用 ZMQ_PAIR 避免任何此类,独立于传输类)阻止某些东西,然后相应地改变信号套接字布局,以便主要避免阻塞(这应该是一个实时系统,如上所述)

    • 在可能的情况下,在目标多核/多核硬件架构中应用延迟掩蔽,以便从您的硬件/工具功能中挤出最后一缕空闲时间...使用更多I / O线程的帮助 zmq :: context_t context(N); ,其中 N> 1 li>
    • remove all overheads
      • replace all tcp-header processing from the proposed PUB/SUB channel
      • avoid all non-cardinal logic overheads from processing ( no sense to spend time on subscribe-side ( sure, newer versions of ZMQ have moved into publisher-side filtering, but the idea is clear ) with pattern-matching encoded in the selected archetype processing ( using ZMQ_PAIR avoids any such, independently from the transport class ) - if it is intended to block something, then rather change the signalling socket layout accordingly, so as to principally avoid blocking ( this ought to be a real-time system, as you have said above)
      • apply a "latency-masking" where possible in the target multi-core / many-core hardware architectures so as to squeeze the last drops of spare-time from your hardware / tools capabilities ... benchmark with experiments setups with more I/O-threads' help zmq::context_t context( N );, where N > 1

      由于爱丽丝梦游仙境在一个多世纪前就表明,只要没有定义目标,任何道路都会导向目标。没有一个问题来说明最大允许的端到端延迟,并且从中导出了传输层延迟的约束。

      Having a soft-real time ambition, there shan´t be an issue to state a maximum allowed end-to-end latency and from that derive a constraint for transport-layer latency.

      没有这样做, 30 us,300 us甚至3 ms本身没有意义,所以没有人可以决定这些数字对于某些子系统是否足够。

      Having not done so, 30 us, 300 us or even 3 ms have no meaning per se, so no-one can decide, whether these figures are "enough" for some subsystem or not.


      • 定义实时稳定性视野...如果使用实时控制

      • 定义实时设计约束...用于信号/数据采集,用于处理任务,诊断和控制服务

      • 避免任何阻止,设计和验证/证明在所有可能的现实操作环境下都不会出现阻塞(正式的证明方法已经准备好了这样的任务)(没有人希望看到 AlertPanel [等待数据] 在下一次喷气式飞机着陆或有最后的事情看到,在自动车撞到墙上,一个可爱的 [小时玻璃] 动画图标 在控制系统忙碌时移动沙子,无论其背后的原因是什么。

      • define real-time stability horizon(s) ... if using for a real-time control
      • define real-time design constraints ... for signal / data acquisition(s), for processing task(s), for self-diagnostic & control services
      • avoid any blocking, design-wise & validate / prove no blocking will ever appear under all possible real-world operations circumstances [formal proof methods are ready for such task] ( no one would like to see an AlertPanel [ Waiting for data] during your next jet landing or have the last thing to see, before an autonomous car crashes right into the wall, a lovely looking [hour-glass] animated-icon as it moves the sand while the control system got busy, whatever a reason for that was behind it, in a devastatingly blocking manner.

      如果给定的阈值允许有500 ms的稳定性范围是对于液压致动器/控制回路的安全值,但是对于导弹控制系统可能无法工作,对于任何[质量和惯性动量无]系统(类似的DSP系列

      If a given treshold permits to have 500 ms stability horizon ( which may be a safe value for a slo-mo hydraulic-actuator/control-loop, but may fail to work for a guided missile control system, the less for any [mass&momentum-of-inertia]-less system ( alike DSP family of RT-control-systems ) ), you can test end-to-end if your processing fits in between.

      如果你知道,你的传入数据流带来了10个

      If you know, your incoming data-stream brings about 10 kB each 500 us, you can test your design if it can keep the pace with the burst traffic or not.

      如果您测试,您的模型设计会错过目标(不符合性能/时间有限的数字),你知道设计或建筑需要改进的地方。

      If you test, your mock-up design does miss the target ( not meeting the performance / time-constrained figures ) you know pretty well, where the design or where the architecture needs to get improved.

      这篇关于ZeroMQ - pub / sub延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆