throttler

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultMaxNonStakerPendingMsgs rate limits the number of queued messages
	// from non-stakers.
	DefaultMaxNonStakerPendingMsgs uint32 = 3

	// DefaultStakerPortion describes the percentage of resources that are
	// reserved for stakers.
	DefaultStakerPortion float64 = 0.2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUTracker

type CPUTracker interface {
	UtilizeCPU(ids.ShortID, time.Duration)
	GetUtilization(ids.ShortID) float64
	EndInterval()
}

CPUTracker tracks the consumption of CPU time

func NewEWMATracker

func NewEWMATracker(
	vdrs validators.Set,
	stakerCPUPortion float64,
	period time.Duration,
	log logging.Logger,
) CPUTracker

NewEWMATracker returns a CPUTracker that uses exponentially weighted moving average to estimate CPU utilization.

[stakerCPUPortion] is the portion of CPU utilization to reserve for stakers (range (0, 1]) [period] is the interval of time to use for the calculation of EWMA

Note: ewmaCPUTracker uses the period as the total amount of time per interval, which is not the limit since it tracks consumption using EWMA.

func NewNoCPUTracker

func NewNoCPUTracker() CPUTracker

NewNoCPUTracker returns a CPUTracker that does not track CPU usage and always returns 0 for the utilization value

type CountingThrottler

type CountingThrottler interface {
	Add(ids.ShortID)
	Remove(ids.ShortID)
	Throttle(ids.ShortID) bool
	EndInterval()
}

CountingThrottler tracks the usage of a discrete resource (ex. pending messages) by a peer and determines whether or not a peer should be throttled.

func NewMessageThrottler

func NewMessageThrottler(
	vdrs validators.Set,
	maxMessages,
	maxNonStakerPendingMsgs uint32,
	stakerMsgPortion float64,
	log logging.Logger,
) CountingThrottler

NewMessageThrottler returns a MessageThrottler that throttles peers when they have too many pending messages outstanding.

[maxMessages] is the maximum number of messages allotted to this chain [stakerMsgPortion] is the portion of messages to reserve exclusively for stakers should be in the range (0, 1]

func NewNoCountThrottler

func NewNoCountThrottler() CountingThrottler

NewNoCountThrottler returns a CountingThrottler that will never throttle

type Throttler

type Throttler interface {
	AddMessage(ids.ShortID)
	RemoveMessage(ids.ShortID)
	UtilizeCPU(ids.ShortID, time.Duration)
	GetUtilization(ids.ShortID) (float64, bool) // Returns the CPU based priority and whether or not the peer has too many pending messages
	EndInterval()                               // Notify throttler that the current period has ended
}

Throttler provides an interface to register consumption of resources and prioritize messages from nodes that have used less CPU time.

Jump to

Keyboard shortcuts

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