rageping

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLatencyBuckets

func DefaultLatencyBuckets() []float64

Default latency histogram bucket boundaries, denoted in seconds

Types

type LatencyMetricsService

type LatencyMetricsService interface {
	// Adds the given list of peers to the service. Registering the same peers multiple times is supported, upon each
	// registration, an internal reference count is incremented.
	RegisterPeers(peerIDs []ragetypes.PeerID)

	// Decremented the internal reference count for each of the given peers. Only if a reference count reaches zero,
	// the execution of the core ping/pong protocol is stopped.
	UnregisterPeers(peerIDs []ragetypes.PeerID)

	// Unregisters all peers (if any) and releases all resources.
	Close()
}

func NewLatencyMetricsService

func NewLatencyMetricsService(
	host *ragep2p.Host,
	registerer prometheus.Registerer,
	logger loghelper.LoggerWithContext,
	configs []*LatencyMetricsServiceConfig,
) LatencyMetricsService

Initializes a new instance for collecting latency metrics. Metrics are collected for each passed configuration (PING request size, periods, ...). The passed configurations must be pairwise distinct, i.e., do not pass the same configuration multiple times as parameter. (This minor restriction is a result of how the underlying streams are initialized, and may be lifted if needed.)

type LatencyMetricsServiceConfig

type LatencyMetricsServiceConfig struct {
	// The size of the PING message to be sent in bytes.
	// The minimal allowed value is 20 (4 bytes for the message type, 16 bytes for a random tag).
	// The size of the corresponding PONG message is constant (36 bytes: 4 bytes for message type, 32 bytes hash).
	PingSize int

	// The minimal, and maximal configured delay between two consecutive requests.
	// The actual delay used is computed uniformly at random from the interval [MinPeriod, maxPeriod].
	MinPeriod time.Duration
	MaxPeriod time.Duration

	// The maximal time to wait for a PONG message in response to a sent PING message, before considering the request to
	// be failed. Note: As long no PONG message was received for an active PING message and no Timeout was reached, the
	// protocol does not send out a new PING message.
	Timeout time.Duration

	// Extra time to wait until the first PING messages are sent out.
	// Useful, e.g., to avoid failing PING messages during testing when all nodes are started roughly at the same time.
	StartupDelay time.Duration

	// The bucket values for the prometheus.Histogram metric capturing the round-trip latencies, to be specified in
	// fractional seconds.
	//
	// Example: The bucket values [0.05, 0.10, 0.5, 1.0, 5.0] capture latencies in the following ranges:
	//  -   0 ms <= x <=  50 ms
	//  -  50 ms <  x <= 100 ms
	//  - 100 ms <  x <= 500 ms
	//  - 500 ms <  x <=   1 s
	//  -   1 s  <  x <=   5 s
	//  -   5 s  <  x <= infinity
	//
	// The value `nil` may be specified to use a set of pre-configured default bucket values.
	// See DefaultLatencyBuckets() for the default values.
	Buckets []float64
}

func DefaultConfigs

func DefaultConfigs() []*LatencyMetricsServiceConfig

The default configurations run the protocol for two different ping sizes:

  • a small 20 B ping, every 10-20s (10 second timeout)
  • a larger 200 KiB ping, every 2-3min (30 second timeout)

During testing, significant latency differences between the two message sizes have been found. So it makes sense to run the protocol for different ping sizes. However, there is no particular reason to use those exact values. Timeouts and startup delay are set quite conservatively. There is no need to make those tighter.

Jump to

Keyboard shortcuts

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