Documentation
¶
Overview ¶
Package timer provides time utilities including mockable clocks
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MaxTime = time.Unix(1<<63-62135596801, 0)
MaxTime is the maximum representable time
Functions ¶
func EstimateETA ¶
EstimateETA estimates the remaining time to complete a task given the startTime and its current progress.
func ProgressFromHash ¶
ProgressFromHash returns the progress out of MaxUint64 assuming [b] is a key in a uniformly distributed sequence that is being iterated lexicographically.
func StoppedTimer ¶
StoppedTimer returns a stopped timer so that there is no entry on the C channel (and there isn't one scheduled to be added).
This means that after calling Reset there will be no events on the channel until the timer fires (at which point there will be exactly one event sent to the channel).
It enables re-using the timer across loop iterations without needing to have the first loop iteration perform any == nil checks to initialize the first invocation.
Types ¶
type AdaptiveTimeoutConfig ¶
type AdaptiveTimeoutConfig struct {
InitialTimeout time.Duration `json:"initialTimeout"`
MinimumTimeout time.Duration `json:"minimumTimeout"`
MaximumTimeout time.Duration `json:"maximumTimeout"`
// Timeout is [timeoutCoefficient] * average response time
// [timeoutCoefficient] must be > 1
TimeoutCoefficient float64 `json:"timeoutCoefficient"`
// Larger halflife --> less volatile timeout
// [timeoutHalfLife] must be positive
TimeoutHalflife time.Duration `json:"timeoutHalflife"`
}
AdaptiveTimeoutConfig contains the parameters provided to the adaptive timeout manager.
type AdaptiveTimeoutManager ¶
type AdaptiveTimeoutManager interface {
// Start the timeout manager.
// Must be called before any other method.
// Must only be called once.
Dispatch()
// Stop the timeout manager.
// Must only be called once.
Stop()
// Returns the current network timeout duration.
TimeoutDuration() time.Duration
// Registers a timeout for the item with the given [id].
// If the timeout occurs before the item is Removed, [timeoutHandler] is called.
Put(id ids.RequestID, measureLatency bool, timeoutHandler func())
// Remove the timeout associated with [id].
// Its timeout handler will not be called.
Remove(id ids.RequestID)
// ObserveLatency manually registers a response latency.
// We use this to pretend that it a query to a benched validator
// timed out when actually, we never even sent them a request.
ObserveLatency(latency time.Duration)
}
func NewAdaptiveTimeoutManager ¶
func NewAdaptiveTimeoutManager( config *AdaptiveTimeoutConfig, registry metric.Registry, ) (AdaptiveTimeoutManager, error)
type Clock ¶
type Clock struct {
// contains filtered or unexported fields
}
Clock provides a mockable time source
type EtaTracker ¶
type EtaTracker struct {
// contains filtered or unexported fields
}
EtaTracker provides exponentially weighted moving average ETA estimates
func NewEtaTracker ¶
func NewEtaTracker(total uint64, alpha float64) *EtaTracker
NewEtaTracker creates a new ETA tracker with the given total and smoothing factor. Alpha should be between 0 and 1; higher values give more weight to recent observations.
func (*EtaTracker) Progress ¶
func (e *EtaTracker) Progress() uint64
Progress returns the current progress.
func (*EtaTracker) Rate ¶
func (e *EtaTracker) Rate() float64
Rate returns the current estimated rate per second.
func (*EtaTracker) Total ¶
func (e *EtaTracker) Total() uint64
Total returns the total amount of work.
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter tracks event rates
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer wraps a timer object. This allows a user to specify a handler. Once specifying the handler, the dispatch thread can be called. The dispatcher will only return after calling Stop. SetTimeoutIn will result in calling the handler in the specified amount of time.
func NewStagedTimer
deprecated
NewStagedTimer returns a timer that will execute [f] when a timeout occurs and execute an additional timeout after the returned duration if [f] returns true and some duration.
Deprecated: NewStagedTimer exists for historical compatibility and should not be used.
func (*Timer) SetTimeoutIn ¶
SetTimeoutIn will set the timer to fire the handler in [duration]