Documentation
¶
Index ¶
- Constants
- func PongHandler(logger logger.Logger) func(s network.Stream)
- type Collector
- func (mc *Collector) AdjustEmaAlpha(newAlpha float64)
- func (mc *Collector) CalculateUtilityScore(p peer.ID) float64
- func (mc *Collector) GetAllMetrics() map[peer.ID]*share.Metrics
- func (mc *Collector) GetMetrics(p peer.ID) *share.Metrics
- func (mc *Collector) MapPeerToAddress(p peer.ID, address types.Address)
- func (mc *Collector) RemoveOldMetrics(threshold time.Duration)
- func (mc *Collector) UpdateBandwidthUsage(p peer.ID, value float64)
- func (mc *Collector) UpdateComputational(p peer.ID, value float64)
- func (mc *Collector) UpdateReliability(p peer.ID, success bool)
- func (mc *Collector) UpdateResponsiveness(p peer.ID, latency float64, success bool)
- func (mc *Collector) UpdateStorage(p peer.ID, value float64)
- func (mc *Collector) UpdateUptime(p peer.ID, value float64)
- type PerformanceMonitor
Constants ¶
const (
PerformanceProtocolID protocol.ID = "/peerdns/performance/1.0.0"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector collects and updates utility metrics for peers.
Fields: - metrics: A map of peer IDs to their associated Metrics. - mu: A read-write mutex for synchronizing access to metrics. - weights: Weights assigned to different metrics for utility score calculation. - emaAlpha: Smoothing factor used in Exponential Moving Average calculations. - maxRespScore: Maximum cap for responsiveness to prevent extreme values.
func NewCollector ¶
func NewCollector(ctx context.Context, logger logger.Logger, weights share.Metrics, emaAlpha float64, maxRespScore float64) *Collector
NewCollector initializes a new Collector with the provided weights and EMA alpha.
Parameters: - weights: Weights for each metric used in utility score calculation. - emaAlpha: Smoothing factor for Exponential Moving Average calculations. - maxRespScore: Maximum cap for responsiveness to prevent extreme values.
Returns: - A pointer to the initialized Collector.
func (*Collector) AdjustEmaAlpha ¶
AdjustEmaAlpha dynamically adjusts the smoothing factor used in EMA calculations.
Parameters: - newAlpha: The new EMA alpha value to be set.
func (*Collector) CalculateUtilityScore ¶
CalculateUtilityScore computes the overall utility score for a peer.
Parameters: - p: The peer ID of the peer for which the utility score is computed.
Returns: - The computed utility score as a float64.
func (*Collector) GetAllMetrics ¶
GetAllMetrics returns a copy of all collected metrics.
Returns: - A map of peer IDs to their corresponding Metrics structs.
func (*Collector) GetMetrics ¶
GetMetrics retrieves the metrics for a given peer.
Parameters: - p: The peer ID of the peer whose metrics are retrieved.
Returns: - A pointer to the Metrics struct containing the peer's metrics.
func (*Collector) MapPeerToAddress ¶
func (*Collector) RemoveOldMetrics ¶
RemoveOldMetrics removes metrics that haven't been updated within the specified threshold.
Parameters: - threshold: A duration specifying the age threshold for removing old metrics.
func (*Collector) UpdateBandwidthUsage ¶
UpdateBandwidthUsage updates the bandwidth usage metric for a peer.
Parameters: - p: The peer ID of the peer being updated. - value: The new bandwidth usage value.
func (*Collector) UpdateComputational ¶
UpdateComputational updates the computational metric for a peer.
Parameters: - p: The peer ID of the peer being updated. - value: The new computational metric value.
func (*Collector) UpdateReliability ¶
UpdateReliability updates the reliability metric for a peer.
Parameters: - p: The peer ID of the peer being updated. - success: Indicates whether the communication attempt was successful.
func (*Collector) UpdateResponsiveness ¶
UpdateResponsiveness updates the responsiveness metric for a peer.
Parameters: - p: The peer ID of the peer being updated. - latency: The latency observed in communication with the peer. - success: Indicates whether the communication attempt was successful.
func (*Collector) UpdateStorage ¶
UpdateStorage updates the storage metric for a peer.
Parameters: - p: The peer ID of the peer being updated. - value: The new storage metric value.
type PerformanceMonitor ¶
type PerformanceMonitor struct {
// contains filtered or unexported fields
}
PerformanceMonitor pings peers and collects performance metrics.
func NewPerformanceMonitor ¶
func NewPerformanceMonitor( ctx context.Context, host host.Host, logger logger.Logger, obs *observability.Observability, collector *Collector, pingInterval time.Duration, concurrency int, metricsTimeout time.Duration, cleanupInterval time.Duration, cleanupThreshold time.Duration, stakingUpdateInterval time.Duration, ) *PerformanceMonitor
NewPerformanceMonitor initializes a new PerformanceMonitor.
func (*PerformanceMonitor) AdjustEmaAlpha ¶
func (pm *PerformanceMonitor) AdjustEmaAlpha(newAlpha float64)
AdjustEmaAlpha dynamically adjusts the EMA smoothing factor.
func (*PerformanceMonitor) Start ¶
func (pm *PerformanceMonitor) Start()
Start begins the peer monitoring and cleanup processes.
func (*PerformanceMonitor) Stop ¶
func (pm *PerformanceMonitor) Stop()
Stop halts the performance monitoring process gracefully.