Skip to content

Volume Scheduler

The class "vVolume" is implemented to resemble a volume that can be attached to a container in Docker or Kubernetes which consumes the ROM from "vHost". A "vContainer" could be attached with multiple "vVolume" and those "vVolume" could be allocated on different "vHost" rather than the "vHost" where the "vContainer" is hosted. The "vVolume" must be allocated first before a "vContainer" is scheduled. If any "vVolume" is failed to be allocated onto "vHost", the schedule of its associated "vContainer" will be on hold.

BestfitVolumeScheduler

Bases: VolumeScheduler

Bestfit volume scheduler. It will return the host with the least amount of resources.

Source code in PyCloudSim\scheduler\volume_scheduler.py
69
70
71
72
73
74
75
76
77
78
79
class BestfitVolumeScheduler(VolumeScheduler):
    """Bestfit volume scheduler. It will return the host with the least amount of resources."""

    def __init__(self) -> None:
        super().__init__()

    def find_host(self, volume: vVolume) -> vHost | None:
        simulation.hosts.sort(key=lambda host: host.rom_reservoir.amount)
        for host in simulation.hosts:
            if host.powered_on and host.rom_reservoir.amount >= volume.size:
                return host

DefaultVolumeScheduler

Bases: VolumeScheduler

Default volume scheduler. It will return the first available host.

Source code in PyCloudSim\scheduler\volume_scheduler.py
57
58
59
60
61
62
63
64
65
66
class DefaultVolumeScheduler(VolumeScheduler):
    """Default volume scheduler. It will return the first available host."""

    def __init__(self) -> None:
        super().__init__()

    def find_host(self, volume: vVolume) -> vHost | None:
        for host in simulation.hosts:
            if host.powered_on and host.rom_reservoir.amount >= volume.size:
                return host

VolumeScheduler

Bases: ABC, Entity

Base for all container schedulers.

Source code in PyCloudSim\scheduler\volume_scheduler.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
class VolumeScheduler(ABC, Entity):
    """Base for all container schedulers."""

    def __init__(self) -> None:
        super().__init__(label="Volume Scheduler", create_at=0, precursor=None)
        simulation._volume_scheduler = self

    def on_creation(self):
        super().on_creation()

        @self.continuous_event(
            at=simulation.now,
            interval=simulation.min_time_unit,
            duration=inf,
            label="Scheduling Volumes",
            priority=inf,
        )
        def scheduling():
            for volume in simulation.volumes:
                # skip if container is already scheduled
                if volume.scheduled:
                    continue

                # find a host for the container
                host = self.find_host(volume)
                # if a host is found, allocate the container to the host
                if host:
                    host.allocate_volume(volume)
                else:
                    logger.debug(f"{simulation.now}:\t{volume} cannot be scheduled.")

    def on_termination(self):
        return super().on_termination()

    def on_destruction(self):
        return super().on_destruction()

    @abstractmethod
    def find_host(self, volume: vVolume) -> vHost | None:
        pass

WorstfitVolumeScheduler

Bases: VolumeScheduler

Worstfit volume scheduler. It will return the host with the most amount of resources.

Source code in PyCloudSim\scheduler\volume_scheduler.py
82
83
84
85
86
87
88
89
90
91
92
class WorstfitVolumeScheduler(VolumeScheduler):
    """Worstfit volume scheduler. It will return the host with the most amount of resources."""

    def __init__(self) -> None:
        super().__init__()

    def find_host(self, volume: vVolume) -> vHost | None:
        simulation.hosts.sort(key=lambda host: host.rom_reservoir.amount, reverse=True)
        for host in simulation.hosts:
            if host.powered_on and host.rom_reservoir.amount >= volume.size:
                return host