Documentation
¶
Index ¶
- Constants
- Variables
- type Bitrate
- type Limit
- type Limiter
- func (l *Limiter) ExecutorCapacity() Bitrate
- func (l *Limiter) GetAddrLimit(ID uuid.UUID, addr string) (Bitrate, bool, error)
- func (l *Limiter) GetExecLimit(ID uuid.UUID) (Bitrate, bool, error)
- func (l *Limiter) GetLimit(ID uuid.UUID, addr string) (Limit, error)
- func (l *Limiter) InsertDebuglet(ID uuid.UUID, minimum, maximum Bitrate, addrs []string) error
- func (l *Limiter) RemoveDebuglet(ID uuid.UUID)
- func (l *Limiter) SetAddrCapacity(addr string, c Bitrate)
- func (l *Limiter) SetExecutorCapacity(c Bitrate)
- func (l *Limiter) Wait(ctx context.Context, direction TransferDirection, ID uuid.UUID, addr string, ...) error
- type TransferDirection
- type UsageLimits
- type UsageTracker
Constants ¶
const ( Bit Bitrate = 1 Kilobit = 1000 * Bit Megabit = 1000 * Kilobit Gigabit = 1000 * Megabit Terabit = 1000 * Gigabit Petabit = 1000 * Terabit Byte = 8 * Bit Kilobyte = 1000 * Byte Megabyte = 1000 * Kilobyte Gigabyte = 1000 * Megabyte Terabyte = 1000 * Gigabyte Petabyte = 1000 * Terabyte )
const MaxByteCount = math.MaxInt64 / bitsPerByte
MaxByteCount is the largest byte count that has an exact bit count.
Variables ¶
var ( ErrNotRegistered = errors.New("debuglet has not been registered") ErrNotInPolicy = errors.New("address has not been registered/not in policy") )
Functions ¶
This section is empty.
Types ¶
type Bitrate ¶
type Bitrate int64
Bitrate in bits/s.
Can also be used to generally indicate size.
func FromBytes ¶
FromBytes converts a byte count into bits. A count beyond MaxByteCount in either direction has no exact bit count and saturates, rather than wrapping into a bitrate of the opposite sign.
func (Bitrate) Bytes ¶
Bytes is the buffer size that holds b bits, rounded up to a whole byte. It is a size, so it is defined for a non-negative bitrate: a negative one is a debt, has no buffer size and reports zero. Use Bitrate.SignedBytes to convert a signed token balance.
func (Bitrate) SignedBytes ¶
SignedBytes converts a signed bit count into whole bytes, rounding towards negative infinity. Applied to a token balance it reports only bytes that are fully covered and never erases part of a debt: -8 bits is one byte owed and -1 bit is still one byte owed, where rounding towards zero reports none of either and grants the next reservation early. It is exact for every int64.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter keeps track of the bandwidth being used by individual debuglets as well as the maximum bandwidth any debuglet is allowed to use on a executor level as well as per destination.
func NewLimiter ¶
func (*Limiter) ExecutorCapacity ¶
func (*Limiter) GetAddrLimit ¶
func (*Limiter) InsertDebuglet ¶
func (*Limiter) RemoveDebuglet ¶
func (*Limiter) SetAddrCapacity ¶
func (*Limiter) SetExecutorCapacity ¶
type TransferDirection ¶
type TransferDirection = int
const ( TransferIn TransferDirection = iota TransferOut )
type UsageLimits ¶
type UsageTracker ¶
type UsageTracker struct {
// contains filtered or unexported fields
}
UsageTracker tracks the amount of bandwidth that is being used by an individual debuglet. The idea is to set the executor and destination specific limit that is allowed by the debuglet and then UsageTracker.Wait will block the caller for the amount of time to ratelimit the bandwidth usage.
func NewUsageTracker ¶
func NewUsageTracker(l *zap.Logger) *UsageTracker
func (*UsageTracker) Upsert ¶
func (u *UsageTracker) Upsert(destination string, limits UsageLimits)
func (*UsageTracker) Wait ¶
func (u *UsageTracker) Wait(ctx context.Context, dir TransferDirection, destination string, size Bitrate) error
Wait uses a token bucket to sleep until either the context finishes or a packet of a given size has enough space