Class VmSchedulerAbstract

java.lang.Object
org.cloudbus.cloudsim.schedulers.vm.VmSchedulerAbstract
All Implemented Interfaces:
VmScheduler
Direct Known Subclasses:
VmSchedulerSpaceShared, VmSchedulerTimeShared

public abstract class VmSchedulerAbstract
extends java.lang.Object
implements VmScheduler
An abstract class for implementation of VmSchedulers.
Since:
CloudSim Toolkit 1.0
Author:
Rodrigo N. Calheiros, Anton Beloglazov, Manoel Campos da Silva Filho
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static double DEFAULT_VM_MIGRATION_CPU_OVERHEAD
    The default percentage to define the CPU overhead of VM migration if one is not explicitly set.

    Fields inherited from interface org.cloudbus.cloudsim.schedulers.vm.VmScheduler

    NULL
  • Constructor Summary

    Constructors 
    Constructor Description
    VmSchedulerAbstract​(double vmMigrationCpuOverhead)
    Creates a VmScheduler, defining a CPU overhead for VM migration.
  • Method Summary

    Modifier and Type Method Description
    boolean allocatePesForVm​(Vm vm)
    Requests the allocation of PEs for a VM, according to the number of PEs and MIPS defined by VM attributes.
    boolean allocatePesForVm​(Vm vm, java.util.List<java.lang.Double> requestedMips)
    Requests the allocation of PEs for a VM.
    protected abstract boolean allocatePesForVmInternal​(Vm vm, java.util.List<java.lang.Double> mipsShareRequested)  
    void deallocatePesForAllVms()
    Releases PEs allocated to all the VMs of the host the VmScheduler is associated to.
    void deallocatePesFromVm​(Vm vm)
    Releases all PEs allocated to a VM.
    void deallocatePesFromVm​(Vm vm, int pesToRemove)
    Releases a given number of PEs from a VM.
    protected abstract void deallocatePesFromVmInternal​(Vm vm, int pesToRemove)  
    java.util.List<java.lang.Double> getAllocatedMips​(Vm vm)
    Gets the MIPS share of each host's Pe that is allocated to a given VM.
    protected java.util.Map<Vm,​java.util.List<java.lang.Double>> getAllocatedMipsMap()
    Gets a map of MIPS allocated to each VM, were each key is a VM and each value is the List of currently allocated MIPS from the respective physical PEs which are being used by such a VM.
    double getAvailableMips()
    Gets the total amount of MIPS that is currently free.
    Host getHost()
    Gets the host that the VmScheduler get the list of PEs to allocate to VMs.
    double getMaxAvailableMips()
    Gets the maximum available MIPS among all the host's PEs.
    double getMaxCpuUsagePercentDuringOutMigration()
    Gets the max percentage of CPU a VM migrating out of this Host can use.
    protected java.util.List<java.lang.Double> getMipsShareRequestedReduced​(Vm vm, java.util.List<java.lang.Double> mipsShareRequested)
    Gets an adjusted List of MIPS requested by a VM, reducing every MIPS which is higher than the capacity of each physical PE to that value.
    long getPeCapacity()
    Gets PE capacity in MIPS.
    java.util.List<java.lang.Double> getRequestedMips​(Vm vm)
    Gets a copy of the List of MIPS requested by a VM, avoiding the original list to be changed.
    protected java.util.Map<Vm,​java.util.List<java.lang.Double>> getRequestedMipsMap()
    Gets a map of MIPS requested by each VM, where each key is a VM and each value is a list of MIPS requested by that VM.
    double getTotalAllocatedMipsForVm​(Vm vm)
    Gets the actual total allocated MIPS for a VM along all its allocated PEs.
    double getVmMigrationCpuOverhead()
    Defines the percentage of Host's CPU usage increase when a VM is migrating in or out of the Host.
    java.util.List<Pe> getWorkingPeList()
    Gets the list of working PEs from the Host, which excludes failed PEs.
    boolean isSuitableForVm​(Vm vm)
    Checks if the PM using this scheduler has enough MIPS capacity to host a given VM.
    boolean isSuitableForVm​(Vm vm, java.util.List<java.lang.Double> requestedMips)
    Checks if a list of MIPS requested by a VM is allowed to be allocated or not.
    protected abstract boolean isSuitableForVmInternal​(Vm vm, java.util.List<java.lang.Double> requestedMips)  
    protected double percentOfMipsToRequest​(Vm vm)
    Gets the percentage of the MIPS requested by a VM that will be in fact requested to the Host, according to the VM migration status: VM is migrating out of this Host: the MIPS requested by VM will be reduced according to the CPU migration overhead.
    protected <T> int removePesFromMap​(Vm vm, java.util.Map<Vm,​java.util.List<T>> map, int pesToRemove)
    Remove a given number of PEs from a given Vm -> List<PE> Map, where each PE in the List associated to each Vm may be an actual Pe object or just its capacity in MIPS (Double).
    VmScheduler setHost​(Host host)
    Sets the host that the VmScheduler get the list of PEs to allocate to VMs.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • VmSchedulerAbstract

      public VmSchedulerAbstract​(double vmMigrationCpuOverhead)
      Creates a VmScheduler, defining a CPU overhead for VM migration.
      Parameters:
      vmMigrationCpuOverhead - the percentage of Host's CPU usage increase when a VM is migrating in or out of the Host. The value is in scale from 0 to 1 (where 1 is 100%).
  • Method Details

    • isSuitableForVm

      public final boolean isSuitableForVm​(Vm vm)
      Description copied from interface: VmScheduler
      Checks if the PM using this scheduler has enough MIPS capacity to host a given VM.
      Specified by:
      isSuitableForVm in interface VmScheduler
      Parameters:
      vm - the vm to check if there is enough available resource on the PM to host it
      Returns:
      true, if it is possible to allocate the the VM into the host; false otherwise
      See Also:
      VmScheduler.isSuitableForVm(Vm)
    • isSuitableForVm

      public boolean isSuitableForVm​(Vm vm, java.util.List<java.lang.Double> requestedMips)
      Description copied from interface: VmScheduler
      Checks if a list of MIPS requested by a VM is allowed to be allocated or not. Depending on the VmScheduler implementation, the return value of this method may have different effects:
      • true: requested MIPS can be allocated, partial or totally;
      • false: requested MIPS cannot be allocated because there is no availability at all or there is just a partial amount of the requested MIPS available and the VmScheduler implementation doesn't allow allocating less than the VM is requesting. If less than the required MIPS is allocated to a VM, it will cause performance degradation. Such situation defines an over-subscription situation which just specific VmSchedulers accept.
      Specified by:
      isSuitableForVm in interface VmScheduler
      Parameters:
      vm - the Vm to check if there are enough MIPS to allocate to
      requestedMips - a list of MIPS requested by a VM
      Returns:
      true if the requested MIPS List is allowed to be allocated to the VM, false otherwise
    • isSuitableForVmInternal

      protected abstract boolean isSuitableForVmInternal​(Vm vm, java.util.List<java.lang.Double> requestedMips)
    • allocatePesForVm

      public final boolean allocatePesForVm​(Vm vm)
      Description copied from interface: VmScheduler
      Requests the allocation of PEs for a VM, according to the number of PEs and MIPS defined by VM attributes.
      Specified by:
      allocatePesForVm in interface VmScheduler
      Parameters:
      vm - the vm to allocate PEs to
      Returns:
      true if the PEs were allocated to the VM, false otherwise
    • allocatePesForVm

      public final boolean allocatePesForVm​(Vm vm, java.util.List<java.lang.Double> requestedMips)
      Description copied from interface: VmScheduler
      Requests the allocation of PEs for a VM.
      Specified by:
      allocatePesForVm in interface VmScheduler
      Parameters:
      vm - the vm to allocate PEs to
      requestedMips - the list of MIPS share to be allocated to a VM
      Returns:
      true if the PEs were allocated to the VM, false otherwise
    • allocatePesForVmInternal

      protected abstract boolean allocatePesForVmInternal​(Vm vm, java.util.List<java.lang.Double> mipsShareRequested)
    • deallocatePesFromVm

      public void deallocatePesFromVm​(Vm vm)
      Description copied from interface: VmScheduler
      Releases all PEs allocated to a VM. After that, the PEs may be used on demand by other VMs.
      Specified by:
      deallocatePesFromVm in interface VmScheduler
      Parameters:
      vm - the vm to deallocate PEs from
    • deallocatePesFromVm

      public void deallocatePesFromVm​(Vm vm, int pesToRemove)
      Description copied from interface: VmScheduler
      Releases a given number of PEs from a VM. After that, the PEs may be used on demand by other VMs.
      Specified by:
      deallocatePesFromVm in interface VmScheduler
      Parameters:
      vm - the vm to deallocate PEs from
      pesToRemove - number of PEs to deallocate
    • removePesFromMap

      protected <T> int removePesFromMap​(Vm vm, java.util.Map<Vm,​java.util.List<T>> map, int pesToRemove)
      Remove a given number of PEs from a given Vm -> List<PE> Map, where each PE in the List associated to each Vm may be an actual Pe object or just its capacity in MIPS (Double).

      In other words, the map can be Map<Vm, List<Double>> or Map<Vm, List<Pe>>.

      Type Parameters:
      T - the type of the elements into the List associated to each map key, which can be a MIPS number (Double) or an actual Pe object.
      Parameters:
      vm - the VM to remove PEs from
      map - the map where the PEs will be removed
      pesToRemove - the number of PEs to remove from the List of PEs associated to the Vm
      Returns:
      the number of removed PEs
    • deallocatePesFromVmInternal

      protected abstract void deallocatePesFromVmInternal​(Vm vm, int pesToRemove)
    • deallocatePesForAllVms

      public void deallocatePesForAllVms()
      Description copied from interface: VmScheduler
      Releases PEs allocated to all the VMs of the host the VmScheduler is associated to. After that, all PEs will be available to be used on demand for requesting VMs.
      Specified by:
      deallocatePesForAllVms in interface VmScheduler
    • getAllocatedMips

      public java.util.List<java.lang.Double> getAllocatedMips​(Vm vm)
      Description copied from interface: VmScheduler
      Gets the MIPS share of each host's Pe that is allocated to a given VM.
      Specified by:
      getAllocatedMips in interface VmScheduler
      Parameters:
      vm - the vm to get the MIPS share
      Returns:
    • getMipsShareRequestedReduced

      protected java.util.List<java.lang.Double> getMipsShareRequestedReduced​(Vm vm, java.util.List<java.lang.Double> mipsShareRequested)
      Gets an adjusted List of MIPS requested by a VM, reducing every MIPS which is higher than the capacity of each physical PE to that value.
      Parameters:
      vm - the VM to get the MIPS requested
      mipsShareRequested - the VM requested MIPS List
      Returns:
      the VM requested MIPS List without MIPS higher than the PE capacity.
    • getTotalAllocatedMipsForVm

      public double getTotalAllocatedMipsForVm​(Vm vm)
      Description copied from interface: VmScheduler
      Gets the actual total allocated MIPS for a VM along all its allocated PEs. If the VM is migrating into the Host, then just a fraction of the requested MIPS is actually allocated, representing the overhead of the migration process.

      The MIPS requested by the VM are just actually allocated after the migration is completed.

      Specified by:
      getTotalAllocatedMipsForVm in interface VmScheduler
      Parameters:
      vm - the VM to get the total allocated MIPS
      Returns:
      See Also:
      VmScheduler.getVmMigrationCpuOverhead()
    • getMaxAvailableMips

      public double getMaxAvailableMips()
      Description copied from interface: VmScheduler
      Gets the maximum available MIPS among all the host's PEs.
      Specified by:
      getMaxAvailableMips in interface VmScheduler
      Returns:
    • getPeCapacity

      public long getPeCapacity()
      Gets PE capacity in MIPS.
      Returns:
      To do something:
      It considers that all PEs have the same capacity, what has been shown doesn't be assured. The peList received by the VmScheduler can be heterogeneous PEs.
    • getWorkingPeList

      public final java.util.List<Pe> getWorkingPeList()
      Gets the list of working PEs from the Host, which excludes failed PEs.
      Returns:
    • getRequestedMipsMap

      protected java.util.Map<Vm,​java.util.List<java.lang.Double>> getRequestedMipsMap()
      Gets a map of MIPS requested by each VM, where each key is a VM and each value is a list of MIPS requested by that VM. When a VM is going to be placed into a Host, its requested MIPS is a list where each element is the MIPS capacity of each VM Pe and the list size is the number of PEs.
      Returns:
      the requested MIPS map
    • getRequestedMips

      public java.util.List<java.lang.Double> getRequestedMips​(Vm vm)
      Description copied from interface: VmScheduler
      Gets a copy of the List of MIPS requested by a VM, avoiding the original list to be changed.
      Specified by:
      getRequestedMips in interface VmScheduler
      Parameters:
      vm - the VM to get the List of requested MIPS
      Returns:
    • getAllocatedMipsMap

      protected java.util.Map<Vm,​java.util.List<java.lang.Double>> getAllocatedMipsMap()
      Gets a map of MIPS allocated to each VM, were each key is a VM and each value is the List of currently allocated MIPS from the respective physical PEs which are being used by such a VM.

      When VM is in migration, the allocated MIPS in the source Host is reduced due to migration overhead, according to the getVmMigrationCpuOverhead(). This is a situation that the allocated MIPS will be lower than the requested MIPS.

      Returns:
      the allocated MIPS map
      See Also:
      getAllocatedMips(Vm), getRequestedMipsMap()
    • getAvailableMips

      public double getAvailableMips()
      Description copied from interface: VmScheduler
      Gets the total amount of MIPS that is currently free. If there are VMs migrating into the Host, their requested MIPS will already be allocated, reducing the total available MIPS.
      Specified by:
      getAvailableMips in interface VmScheduler
      Returns:
    • percentOfMipsToRequest

      protected double percentOfMipsToRequest​(Vm vm)
      Gets the percentage of the MIPS requested by a VM that will be in fact requested to the Host, according to the VM migration status:
      • VM is migrating out of this Host: the MIPS requested by VM will be reduced according to the CPU migration overhead. The number of MIPS corresponding to the CPU overhead is used by the Host to perform the migration;
      • VM is migrating into this Host: only a fraction of its requested MIPS will be in fact requested to the Host. This amount is computed by reducing the CPU migration overhead;
      • VM is not in migration: 100% of its requested MIPS will be in fact requested to the Host
      Parameters:
      vm - the VM that is requesting MIPS from the Host
      Returns:
      the percentage of MIPS requested by the VM that will be in fact requested to the Host (in scale from [0 to 1], where is 100%)
    • getMaxCpuUsagePercentDuringOutMigration

      public double getMaxCpuUsagePercentDuringOutMigration()
      Description copied from interface: VmScheduler
      Gets the max percentage of CPU a VM migrating out of this Host can use. Since there may be an overhead associated to the migration process (if the CPU overhead for VM migration is greater than 0), during the migration, the amount of MIPS the VM can use is reduced due to this overhead.
      Specified by:
      getMaxCpuUsagePercentDuringOutMigration in interface VmScheduler
      Returns:
      the max percentage of CPU usage during migration (in scale from [0 to 1], where 1 is 100%)
    • getVmMigrationCpuOverhead

      public double getVmMigrationCpuOverhead()
      Description copied from interface: VmScheduler
      Defines the percentage of Host's CPU usage increase when a VM is migrating in or out of the Host. The value is in scale from 0 to 1 (where 1 is 100%).
      Specified by:
      getVmMigrationCpuOverhead in interface VmScheduler
      Returns:
      the Host's CPU migration overhead percentage.
    • getHost

      public Host getHost()
      Description copied from interface: VmScheduler
      Gets the host that the VmScheduler get the list of PEs to allocate to VMs.
      Specified by:
      getHost in interface VmScheduler
      Returns:
    • setHost

      public final VmScheduler setHost​(Host host)
      Description copied from interface: VmScheduler
      Sets the host that the VmScheduler get the list of PEs to allocate to VMs. A host for the VmScheduler is set when the VmScheduler is set to a given host. Thus, the host is in charge to set itself to a VmScheduler.
      Specified by:
      setHost in interface VmScheduler
      Parameters:
      host - the host to be set
      Returns: