Skip to content

Host Provisioner

The "HostProvisioner" class is responsible for handling the provisioning and decommissioning of "vHost" instances in the simulation environment. Its main tasks include provisioning a new "vHost" if any "vContainer" cannot be scheduled and decommissioning idle "vHost" instances that have been inactive for an extended period.

The provisioning process is implemented as an event, and only one provisioning process can exist at any given time during the simulation. When triggered, the provisioning process evaluates the current state of the simulation and checks if there are any "vContainer" instances that cannot be scheduled onto available "vHost" instances. If such a situation is detected, a new "vHost" is provisioned to accommodate the unscheduled "vContainer" and ensure the continuity of the simulation.

On the other hand, the decommissioning process is continuously associated with each "vHost" instance. It periodically checks if a "vHost" is idle, meaning it is not currently hosting any "vContainer" instances. If an idle state is detected, the decommissioning process is engaged, resulting in the shutdown of the idle "vHost" instance. However, if the "vHost" is not idle, indicating it is still hosting active "vContainer" instances, the decommissioning process will back off and wait for the next evaluation cycle. It's important to note that multiple decommissioning processes can coexist during the simulation, each associated with a specific "vHost" instance.

By incorporating the "HostProvisioner" class into the simulation environment, the provisioning and decommissioning of "vHost" instances can be managed dynamically, optimizing resource utilization and ensuring efficient allocation of computational resources.

HostProvisioner

Source code in PyCloudSim\scheduler\host_provisioner.py
class HostProvisioner:
    _power_saving: bool
    _evaluation_interval: Union[int, float]

    def __init__(
        self, power_saving: bool = True, evaluation_interval: Union[int, float] = 1
    ) -> None:
        """Host provisioner.

        Args:
            power_saving (bool, optional): set to true for power saving, that the host will be powered off if no container or volume is being hosted. Defaults to True.
            evaluation_interval (Union[int, float], optional): the interval for the host provisioner to check on the host. Defaults to 1.
        """
        self._power_saving = power_saving
        if evaluation_interval <= 0:
            raise ValueError(
                "Host privisioner evaluation delay must be greater than 0."
            )
        self._evaluation_interval = evaluation_interval
        simulation._host_privisioner = self

    def privision(self, host: vHost):
        """Provision a host."""
        def _evaluation():
            if host.powered_on:
                if len(host.containers) == 0:
                    host.power_off()
                else:
                    Actor(
                        at=simulation.now + self.evaluation_interval,
                        action=_evaluation,
                        label="Host Privisioning Evaluation",
                        priority=HOST_EVALUATION,
                    )

        if host.privisioned:
            return
        host._privisioned = True
        host.power_on()
        simulation.container_scheduler.schedule()
        simulation.volume_allocator.allocate()
        if self.power_saving:
            Actor(
                at=simulation.now + self.evaluation_interval,
                action=_evaluation,
                label="Host Privisioning Evaluation",
                priority=HOST_EVALUATION,
            )

    @property
    def power_saving(self) -> bool:
        """return true if power saving is enabled."""
        return self._power_saving

    @property
    def evaluation_interval(self) -> Union[int, float]:
        """return the evaluation interval."""
        return self._evaluation_interval

evaluation_interval: Union[int, float] property

return the evaluation interval.

power_saving: bool property

return true if power saving is enabled.

__init__(power_saving=True, evaluation_interval=1)

Host provisioner.

Parameters:

Name Type Description Default
power_saving bool

set to true for power saving, that the host will be powered off if no container or volume is being hosted. Defaults to True.

True
evaluation_interval Union[int, float]

the interval for the host provisioner to check on the host. Defaults to 1.

1
Source code in PyCloudSim\scheduler\host_provisioner.py
def __init__(
    self, power_saving: bool = True, evaluation_interval: Union[int, float] = 1
) -> None:
    """Host provisioner.

    Args:
        power_saving (bool, optional): set to true for power saving, that the host will be powered off if no container or volume is being hosted. Defaults to True.
        evaluation_interval (Union[int, float], optional): the interval for the host provisioner to check on the host. Defaults to 1.
    """
    self._power_saving = power_saving
    if evaluation_interval <= 0:
        raise ValueError(
            "Host privisioner evaluation delay must be greater than 0."
        )
    self._evaluation_interval = evaluation_interval
    simulation._host_privisioner = self

privision(host)

Provision a host.

Source code in PyCloudSim\scheduler\host_provisioner.py
def privision(self, host: vHost):
    """Provision a host."""
    def _evaluation():
        if host.powered_on:
            if len(host.containers) == 0:
                host.power_off()
            else:
                Actor(
                    at=simulation.now + self.evaluation_interval,
                    action=_evaluation,
                    label="Host Privisioning Evaluation",
                    priority=HOST_EVALUATION,
                )

    if host.privisioned:
        return
    host._privisioned = True
    host.power_on()
    simulation.container_scheduler.schedule()
    simulation.volume_allocator.allocate()
    if self.power_saving:
        Actor(
            at=simulation.now + self.evaluation_interval,
            action=_evaluation,
            label="Host Privisioning Evaluation",
            priority=HOST_EVALUATION,
        )