Aeron:Position

一、Understanding Aeron Position

在 Aeron 中,位置被定义为每个数据流中字节在不同时间的唯一标识。位置是特定于特定通道上的 streamId 和特定channel/streamId 上的 sessionId 。此外,termId 和 termOffset 也会发挥作用,因为位置会随着日志缓冲区项的旋转( log buffer terms are rotated)而不断增加。应用程序发送的数据大小只是位置增量的一部分,报头和填充数据也会对其产生影响。

为了说明位置(Position)的作用,我们将看一对简单的应用程序,一个持有 Aeron 订阅(Subscriber Application),另一个持有 Aeron publication (Publisher Application)。发布应用程序(Publisher Application)正在向订阅应用程序(Subscriber Application)发送一个小数据包。在这样的流程中,主要的活动部件是发布应用程序(Publisher Application)中的 Aeron 发布(publication)和发送器(sender),以及订阅者应用程序(Subscriber Application)中的接收器(receiver)和订阅(subscription)。

以上述示例为例,在 Aeron 计数器中可以找到以下位置:

  • Publication Application
    • pub-pos - 这是Publication的采样位置(this is the Publication's sampled position)
    • pub-lmt - this is the Publication's limit
    • snd-pos - 这是发送方(sender)在Media Driver中的位置(this is the position of the Sender in the Media Driver)
    • snd-lmt - this is the limit of the Sender in the Media Driver
    • snd-bpe - 这是该channel/stream/session中背压事件的计数(this is the count of Back Pressure events in this channel/stream/session (see Back Pressure))
  • Subscription Application
    • rcv-hwm - 这是Media Driverreceiver的高水位线位置(this is the high water mark position of the Receiver in the Media Driver)
    • rcv-pos - 这是receiverMedia Driver中的完成位置(this is the completed position of the Receiver in the Media Driver)
    • sub-pos - 订阅消费的位置(this is the Subscription's position)

当数据的移动以动画的形式呈现时,位置的流动会更容易理解:

在happy路径方案中,位置移动如下(In a happy path scenario, the positions are moved as follows):

  • 当Publisher Application向Publication写入数据时,publisher位置就会增加。数据被添加到术语缓冲区(term buffer),从而更新了已提交数据的位置(即 pub-pos
  • The Publisher Application Media Driver Sender会检查是否有新数据添加到术语缓冲区(term buffer)中。如果发现要发送的数据,就会发送数据并更新 snd-pos
  • The Subscriber Application Media Driver Receiver从网络缓冲区接收数据。在将数据追加到本地术语缓冲区(term buffer)后,它会更新 rcv-hwmrcv-pos
  • 订阅者(Subscriber )轮询术语缓冲区(term buffer),一旦消费信息,sub-pos就会增加。

由于上述示例针对的是单条信息,因此receiver位置和receiver高水位不会变化。例如,当Media Driver Receiver收到的信息不按顺序排列时,它们就会发生变化:

二、Term Length & Positions

支持的最大位置由术语(term)长度决定,即术语(term)长度 * 2^31。

三、MTU & Positions

Aeron 的位置并不完全取决于应用数据的位置,Aeron 头和填充数据也包含在位置中。反过来,报文头和填充数据的数量也直接受 MTU 长度的影响,因为提供给 Publication 的数据是按照给定的 MTU 长度处理的。如果报文长度超过 MTU 长度(减去报文头),报文将被分割成 MTU 大小的报文,并添加额外的报文头和填充数据。短于 MTU 的报文可以合并,并添加报文头(可能还有填充)。

这种与 MTU 的直接联系就是为什么发布(publication)和订阅 (subscription )MTU 必须始终完全一致的原因。这同样适用于 Aeron Archive。

四、Viewing positions at runtime(运行时查看position) 

Position 通过 Aeron 计数器发布。Aeron 计数器可通过程序( viewed programmatically)或内置的Aeron Tooling样本进行查看。最常用的工具是 Aeron StatStreamStat是一个类似的工具,主要用于显示 channel/stream/session 位置。

Aeron Stat

Aeron Stat 显示Media Driver上每个活动会话(active session)的位置。在下面的片段中,会话 1985493803 代表上述Publication process/Subscription process。 

有关如何读取 Aeron Stat 的更多信息,请参阅 Aeron Tooling

Publication Application

    10:02:06 - Aeron Stat (CnC v0.2.0), pid 49446, heartbeat age 635ms
 ======================================================================
 ...
 26:                    1 - snd-channel: aeron:udp?endpoint=localhost:2000 127.0.0.1:55785
 27:                    1 - send-local-sockaddr: 26 127.0.0.1:55785
 28:                   64 - pub-pos (sampled): 1 1985493803 1 aeron:udp?endpoint=localhost:2000
 29:            8,388,896 - pub-lmt: 1 1985493803 1 aeron:udp?endpoint=localhost:2000
 30:                   64 - snd-pos: 1 1985493803 1 aeron:udp?endpoint=localhost:2000
 31:              131,360 - snd-lmt: 1 1985493803 1 aeron:udp?endpoint=localhost:2000
 32:                    0 - snd-bpe: 1 1985493803 1 aeron:udp?endpoint=localhost:2000
 33:    1,597,672,926,244 - client-heartbeat: 0
 34:                    1 - rcv-channel: aeron:udp?endpoint=localhost:2001 127.0.0.1:2001
 35:                    1 - rcv-local-sockaddr: 34 127.0.0.1:2001

Subscription Application

	10:02:03 - Aeron Stat (CnC v0.2.0), pid 49492, heartbeat age 314ms
 ======================================================================
 ...  
 26:                    1 - rcv-channel: aeron:udp?endpoint=localhost:2000 127.0.0.1:2000
 27:                    1 - rcv-local-sockaddr: 26 127.0.0.1:2000
 28:    1,597,672,923,134 - client-heartbeat: 0
 29:                   64 - sub-pos: 1 1985493803 1 aeron:udp?endpoint=localhost:2000 @0
 30:                   64 - rcv-hwm: 2 1985493803 1 aeron:udp?endpoint=localhost:2000
 31:                   64 - rcv-pos: 2 1985493803 1 aeron:udp?endpoint=localhost:2000
 32:                    1 - snd-channel: aeron:udp?endpoint=localhost:2001 127.0.0.1:61000
 33:                    1 - send-local-sockaddr: 32 127.0.0.1:61000

  • 16
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值