Package haizea :: Package core :: Package scheduler :: Module slottable :: Class ResourceTuple
[hide private]
[frames] | no frames]

Class ResourceTuple

source code


A resource tuple

This is an internal data structure used by the slot table. To manipulate "quantities of resources" in Haizea, use Capacity instead.

A resource tuple represents a quantity of resources. For example, "50% of a CPU and 512 MB of memory" is a resource tuple with two components (CPU and memory). The purpose of having a class for this (instead of a simpler structure, like a list or dictionary) is to be able to perform certain basic operations, like determining whether one tuple "fits" in another (e.g., the previous tuple fits in "100% of CPU and 1024 MB of memory", but in "100% of CPU and 256 MB of memory".

A resource tuple is tightly coupled to a particular slot table. So, if a slot table defines that each node has "CPUs, memory, and disk space", the resource tuples will depend on this definition (the specification of valid resources is not repeated in each resource tuple object).

Resources in a resource tuple can be of two types: single instance and multi instance. Memory is an example of a single instance resource: there is only "one" memory in a node (with some capacity). CPUs are an example of a multi instance resource: there can be multiple CPUs in a single node, and each CPU can be used to satisfy a requirement for a CPU.

Instance Methods [hide private]
 
__init__(self, slottable, single_instance, multi_instance=None)
Constructor.
source code
bool
fits_in(self, rt)
Determines if this resource tuple fits in a given resource tuple
source code
 
incr(self, rt)
Increases the resource tuple with the amounts in a given resource tuple
source code
 
decr(self, rt)
Decreases the resource tuple with the amounts in a given resource tuple
source code
int
get_by_type(self, restype)
Gets the amount of a given resource type.
source code
int
any_less(self, rt)
Determines if any amount of a resource is less than that in a given resource tuple
source code
 
min(self, rt)
Modifies the resource amounts to the minimum of the current amount and that in the given resource tuple
source code
str
__repr__(self)
Creates a string representation of the resource tuple
source code
str
__eq__(self, rt)
Determines if the resource tuple is equal to a given resource tuple
source code
 
__getstate__(self)
Returns state necessary to unpickle a ResourceTuple object
source code
 
__setstate__(self, state)
Restores state when unpickling a ResourceTuple object
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Methods [hide private]
ResourceTuple
copy(cls, rt)
Creates a deep copy of a resource tuple
source code
Class Variables [hide private]
  SINGLE_INSTANCE = 1
  MULTI_INSTANCE = 2
Instance Variables [hide private]
SlotTable slottable
Slot table
list _single_instance
Resource quantities
dict _multi_instance
Resource quantities
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, slottable, single_instance, multi_instance=None)
(Constructor)

source code 

Constructor. Should only be called from SlotTable.

The constructor is not meant to be called directly and should only be called from SlotTable.

The res parameter is a list with the quantities of each resource. The list starts with the single-instance resources, followed by the multi-instance resources. The slottable contains information about the layout of this list:

  • The mapping of resource to position in the list is contained in attribute

rtuple_restype2pos of the slottable.

  • For single-instance resources, the position returned by this mapping contains

the quantity.

  • For multi-instance resources, the position returns the

quantity of the first instance. The number of instances of a given resource is contained in attribute rtuple_nres of the slottable.

  • The number of single-instance resources is contained in attribute rtuple_len of

the slottable.

Parameters:
  • slottable (SlotTable) - Slot table
  • single_instance (list) - Quantities of single instance resources
  • multi_instance (dict) - Quantities of multi instance resources
Overrides: object.__init__

copy(cls, rt)
Class Method

source code 

Creates a deep copy of a resource tuple

Parameters:
Returns: ResourceTuple
Copy of resource tuple

fits_in(self, rt)

source code 

Determines if this resource tuple fits in a given resource tuple

Parameters:
Returns: bool
True if this resource tuple fits in rt. False otherwise.

incr(self, rt)

source code 

Increases the resource tuple with the amounts in a given resource tuple

Parameters:

decr(self, rt)

source code 

Decreases the resource tuple with the amounts in a given resource tuple

Precondition: rt must be known to fit in the resource tuple (via fits_in)

Parameters:

get_by_type(self, restype)

source code 

Gets the amount of a given resource type.

Parameters:
  • restype (str) - Resource type
Returns: int
For single-instance resources, returns the amount. For multi-instance resources, returns the sum of all the instances.

any_less(self, rt)

source code 

Determines if any amount of a resource is less than that in a given resource tuple

In the case of multi-instance resources, this method will only work when both resource tuples have the same number of instances, and makes the comparison instance by instance. For example, if a CPU resource has two instances A and B: ___A__B_ R1|75 50 R2|50 75

R2.any_less(R1) returns True. However:

___A__B_ R1|75 50 R2|75 50

R2.any_less(R1) returns False, even though one instance (R2.B) is less than another (R1.A)

Parameters:
Returns: int
True if these is any resource such that its amount is less than that in rt.

min(self, rt)

source code 

Modifies the resource amounts to the minimum of the current amount and that in the given resource tuple

As in any_less, for multi-instance resources this method will only work when both resource tuples have the same number of instances, and makes the change instance by instance.

Parameters:

__repr__(self)
(Representation operator)

source code 

Creates a string representation of the resource tuple

Returns: str
String representation
Overrides: object.__repr__

__eq__(self, rt)
(Equality operator)

source code 

Determines if the resource tuple is equal to a given resource tuple

Returns: str
True if they equal, False otherwise

__setstate__(self, state)

source code 

Restores state when unpickling a ResourceTuple object

After unpickling, the object still has to be bound to a slottable.