Back to godoc.org

Package resources

v0.9.0
Latest Go to latest

The highest tagged major version is .

Published: Aug 10, 2020 | License: | Module:

Constants ¶

```const (
MEMORY = "memory"
VCORE  = "vcore"
)```

const keys

Variables ¶

`var Zero = NewResource()`

Never update value of Zero

func CompUsageRatio¶

`func CompUsageRatio(left, right, total *Resource) int`

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(left, leftTotal, right, rightTotal *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 CompUsageShares¶

`func CompUsageShares(left, right *Resource) int`

Compare two resources usage shares and assumes a nil total resource. The share is thus equivalent to the usage passed in. 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 Equals¶

`func Equals(left, right *Resource) bool`

Compare the resources equal returns the specific values for following cases: left right return nil nil true nil <set> false <set> nil false <set> <set> true/false *based on the individual Quantity values

func FairnessRatio¶

`func FairnessRatio(left, right, total *Resource) float64`

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 FitIn¶

`func FitIn(larger, smaller *Resource) bool`

Check if smaller fitin larger, negative values will be treated as 0 A nil resource is treated as an empty resource (zero)

func IsZero¶

`func IsZero(zero *Resource) bool`

Check that the whole resource is zero A nil resource is zero (contrary to StrictlyGreaterThanZero)

func StrictlyGreaterThan¶

`func StrictlyGreaterThan(larger, smaller *Resource) bool`

Return true if all quantities in larger > smaller Two resources that are equal are not considered strictly larger than each other.

func StrictlyGreaterThanOrEquals¶

`func StrictlyGreaterThanOrEquals(larger, smaller *Resource) bool`

Return true if all quantities in larger > smaller or if the two objects are exactly the same.

func StrictlyGreaterThanZero¶

`func StrictlyGreaterThanZero(larger *Resource) bool`

Have at least one quantity > 0, and no quantities < 0 A nil resource is not strictly greater than zero.

type Quantity¶

`type Quantity int64`

No unit defined here for better performance

func MaxQuantity¶

`func MaxQuantity(x, y Quantity) Quantity`

Return the largest quantity

func MinQuantity¶

`func MinQuantity(x, y Quantity) Quantity`

Return the smallest quantity

type Resource¶

```type Resource struct {
Resources map[string]Quantity
}```

`func Add(left, right *Resource) *Resource`

Add resources returning a new resource with the result A nil resource is considered an empty resource

func CalculateAbsUsedCapacity¶

`func CalculateAbsUsedCapacity(capacity, used *Resource) *Resource`

func ComponentWiseMax¶

`func ComponentWiseMax(left, right *Resource) *Resource`

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¶

`func ComponentWiseMin(left, right *Resource) *Resource`

Returns a new resource with the smallest value for each quantity in the resources If either resource passed in is nil a zero resource is returned

func Multiply¶

`func Multiply(base *Resource, ratio int64) *Resource`

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¶

`func MultiplyBy(base *Resource, ratio float64) *Resource`

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¶

`func NewResourceFromConf(configMap map[string]string) (*Resource, error)`

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. TODO support size modifiers

func NewResourceFromMap¶

`func NewResourceFromMap(m map[string]Quantity) *Resource`

func NewResourceFromProto¶

`func NewResourceFromProto(proto *si.Resource) *Resource`

func NewResourceFromString¶

`func NewResourceFromString(str string) (*Resource, error)`

Create a new resource from a string. The string must be a json marshalled si.Resource.

func Sub¶

`func Sub(left, right *Resource) *Resource`

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¶

`func SubEliminateNegative(left, right *Resource) *Resource`

Subtract 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¶

`func SubErrorNegative(left, right *Resource) (*Resource, error)`

Subtract 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 (r *Resource) AddTo(add *Resource)`

Add additional resource to the base updating the base resource Should be used by temporary computation only A nil base resource is considered an empty resource A nil addition is treated as a zero valued resource and leaves base unchanged

func (*Resource) Clone¶

`func (r *Resource) Clone() *Resource`

Return 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) DAOString¶

`func (r *Resource) DAOString() string`

func (*Resource) FitInScore¶

`func (r *Resource) FitInScore(fit *Resource) float64`

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) MultiplyTo¶

`func (r *Resource) MultiplyTo(ratio float64)`

Multiply the resource by the ratio updating the resource it is called on. Should be used by temporary computation only.

func (*Resource) String¶

`func (r *Resource) String() string`

func (*Resource) SubFrom¶

`func (r *Resource) SubFrom(sub *Resource)`

Subtract from the resource the passed in resource by updating the resource it is called on. A nil passed in resource is treated as a zero valued resource and leaves the called on resource unchanged. Should be used by temporary computation only

func (*Resource) ToProto¶

`func (r *Resource) ToProto() *si.Resource`

Convert to a protobuf implementation

Package Files ¶

Documentation was rendered with GOOS=linux and GOARCH=amd64.