Documentation
¶
Overview ¶
Package bitrate is the bandwidth type the dispatcher admits and the executor enforces, so both compute with the same units and bounds.
Index ¶
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 Max = Petabit
Max is the largest bandwidth the dispatcher admits and the executor accepts on any boundary. It is far above any capacity a real executor announces and low enough that the aggregate of every run a schedule can hold stays an exact int64. api/openapi.yaml documents the same bound for floor_bw and ceil_bw.
const MaxByteCount = math.MaxInt64 / bitsPerByte
MaxByteCount is the largest byte count that has an exact bit count.
Variables ¶
This section is empty.
Functions ¶
func InPolicyRange ¶
InPolicyRange reports whether bps, a bandwidth in bits per second as the control protocol and the HTTP contract carry it, lies in [0, Max]. The dispatcher's admission and the executor's own checks both apply it, so neither role can accept a bandwidth the other rejects.
Types ¶
type Bitrate ¶
type Bitrate int64
Bitrate in bits/s.
func Add ¶
Add adds two bandwidths and reports whether the sum is exact. Every aggregate admission decision uses it, so a sum that would wrap rejects the request instead of admitting it against a negative total.
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.