msgrate

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package msgrate allows estimating the throughput of peers for more balanced syncs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker estimates the throughput capacity of a peer with regard to each data type it can deliver. The goal is to dynamically adjust request sizes to max out network throughput without overloading either the peer or th elocal node.

By tracking in real time the latencies and bandiwdths peers exhibit for each packet type, it's possible to prevent overloading by detecting a slowdown on one type when another type is pushed too hard.

Similarly, real time measurements also help avoid overloading the local net connection if our peers would otherwise be capable to deliver more, but the local link is saturated. In that case, the live measurements will force us to reduce request sizes until the throughput gets stable.

Lastly, message rate measurements allows us to detect if a peer is unsuaully slow compared to other peers, in which case we can decide to keep it around or free up the slot so someone closer.

Since throughput tracking and estimation adapts dynamically to live network conditions, it's fine to have multiple trackers locally track the same peer in different subsystem. The throughput will simply be distributed across the two trackers if both are highly active. 用于追踪和一个远程节点进行通信的吞吐量和往返时间 针对每一种类型的消息都有一个吞吐量的值

func NewTracker

func NewTracker(caps map[uint64]float64, rtt time.Duration) *Tracker

NewTracker creates a new message rate tracker for a specific peer. An initial RTT is needed to avoid a peer getting marked as an outlier compared to others right after joining. It's suggested to use the median rtt across all peers to init a new peer tracker. 创建针对某个节点的消息速率追踪器 需要指定一个初始的RTT时间,建议使用当前所有节点的平均RTT时间

func (*Tracker) Capacity

func (t *Tracker) Capacity(kind uint64, targetRTT time.Duration) int

Capacity calculates the number of items the peer is estimated to be able to retrieve within the alloted time slot. The method will round up any division errors and will add an additional overestimation ratio on top. The reason for overshooting the capacity is because certain message types might not increase the load proportionally to the requested items, so fetching a bit more might still take the same RTT. By forcefully overshooting by a small amount, we can avoid locking into a lower-that-real capacity. 计算指定类型的消息在输入的时间内可以发送的数量

func (*Tracker) Update

func (t *Tracker) Update(kind uint64, elapsed time.Duration, items int)

Update modifies the peer's capacity values for a specific data type with a new measurement. If the delivery is zero, the peer is assumed to have either timed out or to not have the requested data, resulting in a slash to 0 capacity. This avoids assigning the peer retrievals that it won't be able to honour. 每次接收到数据调用Update方法 elapsed代表此次的往返时间,items为接收到消息条数

type Trackers

type Trackers struct {

	// The fields below can be used to override certain default values. Their
	// purpose is to allow quicker tests. Don't use them in production.
	OverrideTTLLimit time.Duration
	// contains filtered or unexported fields
}

Trackers is a set of message rate trackers across a number of peers with the goal of aggregating certain measurements across the entire set for outlier filtering and newly joining initialization.

func NewTrackers

func NewTrackers(log log.Logger) *Trackers

NewTrackers creates an empty set of trackers to be filled with peers. 创建聚合追踪器

func (*Trackers) Capacity

func (t *Trackers) Capacity(id string, kind uint64, targetRTT time.Duration) int

Capacity is a helper function to access a specific tracker without having to track it explicitly outside. 获取内部某个追踪器的吞吐量

func (*Trackers) MeanCapacities

func (t *Trackers) MeanCapacities() map[uint64]float64

MeanCapacities returns the capacities averaged across all the added trackers. The purpos of the mean capacities are to initialize a new peer with some sane starting values that it will hopefully outperform. If the mean overshoots, the peer will be cut back to minimal capacity and given another chance. 获取各个消息的平均吞吐量

func (*Trackers) MedianRoundTrip

func (t *Trackers) MedianRoundTrip() time.Duration

MedianRoundTrip returns the median RTT across all known trackers. The purpose of the median RTT is to initialize a new peer with sane statistics that it will hopefully outperform. If it seriously underperforms, there's a risk of dropping the peer, but that is ok as we're aiming for a strong median. 获取聚合追踪器中的所有往返时间的中位数,在初始化一个追踪器时使用

func (*Trackers) TargetRoundTrip

func (t *Trackers) TargetRoundTrip() time.Duration

TargetRoundTrip returns the current target round trip time for a request to complete in.The returned RTT is slightly under the estimated RTT. The reason is that message rate estimation is a 2 dimensional problem which is solvable for any RTT. The goal is to gravitate towards smaller RTTs instead of large messages, to result in a stabler download stream. 计算往返时间,公式:平均往返时间 * 0.9

func (*Trackers) TargetTimeout

func (t *Trackers) TargetTimeout() time.Duration

TargetTimeout returns the timeout allowance for a single request to finish under. The timeout is proportional to the roundtrip, but also takes into consideration the tracker's confidence in said roundtrip and scales it accordingly. The final value is capped to avoid runaway requests. 计算超时时间,计算公式:3 * 平均往返时间 / 置信度

func (*Trackers) Track

func (t *Trackers) Track(id string, tracker *Tracker) error

Track inserts a new tracker into the set.

func (*Trackers) Untrack

func (t *Trackers) Untrack(id string) error

Untrack stops tracking a previously added peer.

func (*Trackers) Update

func (t *Trackers) Update(id string, kind uint64, elapsed time.Duration, items int)

Update is a helper function to access a specific tracker without having to track it explicitly outside. 更新内部某个追踪器的数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL