Documentation ¶
Index ¶
- Variables
- func CompUsageRatio(left, right, total *Resource) int
- func CompUsageRatioSeparately(...) int
- func DeepEquals(left, right *Resource) bool
- func Equals(left, right *Resource) bool
- func EqualsOrEmpty(left, right *Resource) bool
- func EqualsTracked(left, right *TrackedResource) bool
- func FairnessRatio(left, right, total *Resource) float64
- func IsZero(zero *Resource) bool
- func StrictlyGreaterThan(larger, smaller *Resource) bool
- func StrictlyGreaterThanOrEquals(larger, smaller *Resource) bool
- func StrictlyGreaterThanZero(larger *Resource) bool
- type Quantity
- type Resource
- func Add(left, right *Resource) *Resource
- func AddOnlyExisting(base, delta *Resource) *Resource
- func CalculateAbsUsedCapacity(capacity, used *Resource) *Resource
- func ComponentWiseMax(left, right *Resource) *Resource
- func ComponentWiseMin(left, right *Resource) *Resource
- func ComponentWiseMinOnlyExisting(left, right *Resource) *Resource
- func MergeIfNotPresent(left, right *Resource) *Resource
- func Multiply(base *Resource, ratio int64) *Resource
- func MultiplyBy(base *Resource, ratio float64) *Resource
- func NewResource() *Resource
- func NewResourceFromConf(configMap map[string]string) (*Resource, error)
- func NewResourceFromMap(m map[string]Quantity) *Resource
- func NewResourceFromProto(proto *si.Resource) *Resource
- func NewResourceFromString(str string) (*Resource, error)
- func Sub(left, right *Resource) *Resource
- func SubEliminateNegative(left, right *Resource) *Resource
- func SubErrorNegative(left, right *Resource) (*Resource, error)
- func SubOnlyExisting(base, delta *Resource) *Resource
- func (r *Resource) AddTo(add *Resource)
- func (r *Resource) Clone() *Resource
- func (r *Resource) DAOMap() map[string]int64
- func (r *Resource) DominantResourceType(capacity *Resource) string
- func (r *Resource) FitIn(smaller *Resource) bool
- func (r *Resource) FitInMaxUndef(smaller *Resource) bool
- func (r *Resource) FitInScore(fit *Resource) float64
- func (r *Resource) HasNegativeValue() bool
- func (r *Resource) IsEmpty() bool
- func (r *Resource) MatchAny(other *Resource) bool
- func (r *Resource) MultiplyTo(ratio float64)
- func (r *Resource) Prune()
- func (r *Resource) StrictlyGreaterThanOnlyExisting(smaller *Resource) bool
- func (r *Resource) String() string
- func (r *Resource) SubFrom(sub *Resource)
- func (r *Resource) ToProto() *si.Resource
- type TrackedResource
Constants ¶
This section is empty.
Variables ¶
var Zero = NewResource()
Never update value of Zero
Functions ¶
func CompUsageRatio ¶
Calculate share for left of total and right of total. This returns the same value as compareShares does: 0 for equal shares 1 if the left share is larger -1 if the right share is larger
func CompUsageRatioSeparately ¶
func CompUsageRatioSeparately(leftAllocated, leftGuaranteed, leftFairMax, rightAllocated, rightGuaranteed, rightFairMax *Resource) int
Calculate share for left of total and right of total separately. This returns the same value as compareShares does: 0 for equal shares 1 if the left share is larger -1 if the right share is larger
func DeepEquals ¶ added in v1.6.0
DeepEquals Compare the resources based on resource type existence and its values as well False in case anyone of the resources is nil False in case resource length differs False in case resource type existed in left Resource not exist in right Resource False in case resource type value differs True in case when all resource type and its values of left Resource matches with right Resource
func Equals ¶
Equals Compare the resources based on common resource type available in both left and right Resource Resource type available in left Resource but not in right Resource and vice versa is not taken into account False in case anyone of the resources is nil False in case resource type value differs True in case when resource type values of left Resource matches with right Resource if resource type is available
func EqualsOrEmpty ¶
Compare the resources equal returns the specific values for following cases: left right return nil nil true nil <set> false nil zero res true <set> nil false zero res nil true <set> <set> true/false *based on the individual Quantity values
func EqualsTracked ¶ added in v1.6.0
func EqualsTracked(left, right *TrackedResource) bool
func FairnessRatio ¶
Get fairness ratio calculated by: highest share for left resource from total divided by highest share for right resource from total. If highest share for the right resource is 0 fairness is 1
func IsZero ¶
Check that the whole resource is zero A nil or empty resource is zero (contrary to StrictlyGreaterThanZero)
func StrictlyGreaterThan ¶
Return true if all quantities in larger > smaller Two resources that are equal are not considered strictly larger than each other.
func StrictlyGreaterThanOrEquals ¶
Return true if all quantities in larger > smaller or if the two objects are exactly the same.
func StrictlyGreaterThanZero ¶
Have at least one quantity > 0, and no quantities < 0 A nil resource is not strictly greater than zero.
Types ¶
type Quantity ¶
type Quantity int64
No unit defined here for better performance
func ParseQuantity ¶
ParseQuantity is used to parse user-provided values into int64 quantities.
func ParseVCore ¶
ParseVCore is similar to ParseQuantity but allows the 'm' suffix. Additionally, the base unit returned is a millicore, so values without units will be converted to milliCPUs (i.e. '10' will result in 10000, and '500m' will result in 500).
type Resource ¶
func Add ¶
Add resources returning a new resource with the result A nil resource is considered an empty resource
func AddOnlyExisting ¶ added in v1.6.0
AddOnlyExisting adds delta to base resource, ignoring any type not defined in the base resource.
func CalculateAbsUsedCapacity ¶
CalculateAbsUsedCapacity returns absolute used as a percentage, a positive integer value, for each defined resource named in the capacity comparing usage to the capacity. If usage is 0 or below 0, absolute used is always 0 if capacity is 0 or below 0, absolute used is always 100 if used is larger than capacity a value larger than 100 can be returned. The percentage value returned is capped at math.MaxInt32 (resolved value 2147483647)
func ComponentWiseMax ¶
Returns a new resource with the largest value for each quantity in the resources If either resource passed in is nil a zero resource is returned
func ComponentWiseMin ¶
ComponentWiseMin returns a new Resource with the smallest value for each quantity in the Resources If either Resource passed in is nil the other Resource is returned If a Resource type is missing from one of the Resource, it is considered empty and the quantity from the other Resource is returned
func ComponentWiseMinOnlyExisting ¶ added in v1.6.0
ComponentWiseMinOnlyExisting Returns a new Resource with the smallest value for resource type existing only in left but not vice versa.
func MergeIfNotPresent ¶ added in v1.6.0
MergeIfNotPresent Returns a new Resource by merging resource type values present in right with left only if resource type not present in left. If either Resource passed in is nil the other Resource is returned If a Resource type is missing from one of the Resource, it is considered empty and the quantity from the other Resource is returned
func Multiply ¶
Multiply the resource by the integer ratio returning a new resource. Result is protected from overflow (positive and negative). A nil resource passed in returns a new empty resource (zero)
func MultiplyBy ¶
Multiply the resource by the floating point ratio returning a new resource. The result is rounded down to the nearest integer value after the multiplication. Result is protected from overflow (positive and negative). A nil resource passed in returns a new empty resource (zero)
func NewResource ¶
func NewResource() *Resource
func NewResourceFromConf ¶
Create a new resource from the config map. The config map must have been checked before being applied. The check here is just for safety so we do not crash.
func NewResourceFromMap ¶
func NewResourceFromProto ¶
func NewResourceFromString ¶
Create a new resource from a string. The string must be a json marshalled si.Resource.
func Sub ¶
Subtract resource returning a new resource with the result A nil resource is considered an empty resource This might return negative values for specific quantities
func SubEliminateNegative ¶
SubEliminateNegative subtracts resource returning a new resource with the result A nil resource is considered an empty resource This will return 0 values for negative values
func SubErrorNegative ¶
SubErrorNegative subtracts resource returning a new resource with the result. A nil resource is considered an empty resource. This will return an error if any value in the result is negative. The caller should at least log the error. The returned resource is valid and has all negative values reset to 0
func SubOnlyExisting ¶ added in v1.6.0
SubOnlyExisting subtracts delta from base resource, ignoring any type not defined in the base resource.
func (*Resource) AddTo ¶
AddTo adds the resource to the base updating the base resource Should be used by temporary computation only A nil base resource does not change A nil passed in resource is treated as a zero valued resource and leaves base unchanged
func (*Resource) Clone ¶
Clone returns a clone (copy) of the resource it is called on. This provides a deep copy of the object with the exact same member set. NOTE: this is a clone not a sparse copy of the original.
func (*Resource) DominantResourceType ¶ added in v1.4.0
DominantResourceType calculates the most used resource type based on the ratio of used compared to the capacity. If a capacity type is set to 0 assume full usage. Dominant type should be calculated with queue usage and capacity. Queue capacities should never contain 0 values when there is a usage also, however in the root queue this could happen. If the last node reporting that resource was removed but not everything has been updated. immediately Ignores resources types that are used but not defined in the capacity.
func (*Resource) FitIn ¶ added in v1.5.0
FitIn checks if smaller fits in the defined resource Types not defined in resource this is called against are considered 0 for Quantity A nil resource is treated as an empty resource (no types defined)
func (*Resource) FitInMaxUndef ¶
FitInMaxUndef checks if smaller fits in the defined resource Types not defined in resource this is called against are considered the maximum value for Quantity A nil resource is treated as an empty resource (no types defined)
func (*Resource) FitInScore ¶
Calculate how well the receiver fits in "fit"
- A score of 0 is a fit (similar to FitIn)
- The score is calculated only using resource type defined in the fit resource.
- The score has a range between 0..#fit-res (the number of resource types in fit)
- Same score means same fit
- The lower the score the better the fit (0 is a fit)
- Each individual score is calculated as follows: score = (fitVal - resVal) / fitVal That calculation per type is summed up for all resource types in fit. example 1: fit memory 1000; resource 100; score = 0.9 example 2: fit memory 150; resource 15; score = 0.9 example 3: fit memory 100, cpu 1; resource memory 10; score = 1.9
- A nil receiver gives back the maximum score (number of resources types in fit)
func (*Resource) HasNegativeValue ¶
func (*Resource) IsEmpty ¶ added in v1.4.0
IsEmpty returns true if the resource is nil or has no component resources specified.
func (*Resource) MatchAny ¶ added in v1.6.0
MatchAny returns true if at least one type in the defined resource exists in the other resource. False if none of the types exist in the other resource. A nil resource is treated as an empty resource (no types defined) and returns false Values are not considered during the checks
func (*Resource) MultiplyTo ¶
Multiply the resource by the ratio updating the resource it is called on. Should be used by temporary computation only.
func (*Resource) Prune ¶ added in v1.6.0
func (r *Resource) Prune()
Prune removes any resource type that has a zero value set. Note that a zero value set and a type not being set are interpreted differently for quotas.
func (*Resource) StrictlyGreaterThanOnlyExisting ¶ added in v1.6.0
StrictlyGreaterThanOnlyExisting returns true if all quantities for types in the defined resource are greater than the quantity for the same type in smaller. Types defined in smaller that are not in the defined resource are ignored. Two resources that are equal are not considered strictly larger than each other.
type TrackedResource ¶ added in v1.4.0
type TrackedResource struct { // TrackedResourceMap is a two-level map for aggregated resource usage. // The top-level key is the instance type, and the value is a map: // resource type (CPU, memory, etc.) -> aggregated used time (in seconds) of the resource type. TrackedResourceMap map[string]*Resource locking.RWMutex }
TrackedResource is a utility struct to keep track of application resource usage.
func NewTrackedResource ¶ added in v1.4.0
func NewTrackedResource() *TrackedResource
NewTrackedResource creates a new instance of TrackedResource.
func NewTrackedResourceFromMap ¶ added in v1.5.0
func NewTrackedResourceFromMap(m map[string]map[string]Quantity) *TrackedResource
NewTrackedResourceFromMap creates NewTrackedResource from the given map. Using for Testing purpose only.
func (*TrackedResource) AggregateTrackedResource ¶ added in v1.4.0
func (tr *TrackedResource) AggregateTrackedResource(instType string, resource *Resource, bindTime time.Time)
AggregateTrackedResource aggregates resource usage to TrackedResourceMap[instType]. The time the given resource used is the delta between the resource createTime and currentTime.
func (*TrackedResource) Clone ¶ added in v1.4.0
func (tr *TrackedResource) Clone() *TrackedResource
Clone creates a deep copy of TrackedResource.
func (*TrackedResource) String ¶ added in v1.5.0
func (tr *TrackedResource) String() string