Class VmAllocationPolicyMigrationAbstract
- java.lang.Object
-
- org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract
-
- org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigrationAbstract
-
- All Implemented Interfaces:
VmAllocationPolicyMigration
,VmAllocationPolicy
- Direct Known Subclasses:
VmAllocationPolicyMigrationDynamicUpperThresholdFirstFit
,VmAllocationPolicyMigrationStaticThreshold
public abstract class VmAllocationPolicyMigrationAbstract extends VmAllocationPolicyAbstract implements VmAllocationPolicyMigration
An abstract VM allocation policy that dynamically optimizes the VM allocation (placement) using migration. It's a Best Fit policy which selects the Host with most efficient power usage to place a given VM. Such a behaviour can be overridden by sub-classes.If you are using any algorithms, policies or workload included in the power package please cite the following paper:
- Since:
- CloudSim Toolkit 3.0
- Author:
- Anton Beloglazov, Manoel Campos da Silva Filho
-
-
Field Summary
-
Fields inherited from interface org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy
NULL
-
Fields inherited from interface org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigration
NULL
-
-
Constructor Summary
Constructors Constructor Description VmAllocationPolicyMigrationAbstract(PowerVmSelectionPolicy vmSelectionPolicy)
Creates a VmAllocationPolicyMigrationAbstract.VmAllocationPolicyMigrationAbstract(PowerVmSelectionPolicy vmSelectionPolicy, BiFunction<VmAllocationPolicy,Vm,Optional<Host>> findHostForVmFunction)
Creates a new VmAllocationPolicy, changing theFunction
to select a Host for a Vm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addHistoryEntryIfAbsent(Host host, double metric)
Adds an entry for each history map of a host if it doesn't contain an entry for the current simulation time.Optional<Host>
findHostForVm(Vm vm)
Finds a host that has enough resources to place a given VM.Optional<Host>
findHostForVm(Vm vm, Set<? extends Host> excludedHosts)
Finds a Host that has enough resources to place a given VM and that will not be overloaded after the placement.Optional<Host>
findHostForVm(Vm vm, Set<? extends Host> excludedHosts, Predicate<Host> predicate)
Finds a Host that has enough resources to place a given VM and that will not be overloaded after the placement.protected Optional<Host>
findHostForVmInternal(Vm vm, Stream<Host> hostStream)
Applies additional filters to the Hosts Stream and performs the actual Host selection.protected double[]
getHostCpuUsageArray(Host host)
Gets all CPU utilization values from theHost.getUtilizationHistorySum()
as an array.protected double
getMaxUtilizationAfterAllocation(Host host, Vm vm)
Gets the max power consumption of a host after placement of a candidate VM.Map<Host,List<Double>>
getMetricHistory()
Gets a read-only map of metric history.Map<Vm,Host>
getOptimizedAllocationMap(List<? extends Vm> vmList)
Gets a map of optimized allocation for VMs according to current utilization and Hosts under and overloaded conditions.protected double
getPowerAfterAllocation(Host host, Vm vm)
Gets the power consumption of a host after the supposed placement of a candidate VM.protected double
getPowerAfterAllocationDifference(Host host, Vm vm)
Gets the power consumption different after the supposed placement of a VM into a given Host and the original Host power consumption.protected List<Host>
getSwitchedOffHosts()
Gets the switched off hosts.Map<Host,List<Double>>
getTimeHistory()
Gets a read-only map of times when entries in each history list was added for each Host.double
getUnderUtilizationThreshold()
Gets the percentage of total CPU utilization to indicate that a host is under used and its VMs have to be migrated.Map<Host,List<Double>>
getUtilizationHistory()
Gets a read-only map of the utilization history for each Host.protected double
getUtilizationOfCpuMips(Host host)
Gets the utilization of the CPU in MIPS for the current potentially allocated VMs.protected PowerVmSelectionPolicy
getVmSelectionPolicy()
Gets the vm selection policy.protected List<? extends Vm>
getVmsToMigrateFromUnderUtilizedHost(Host host)
Gets the VMs to migrate from under utilized host.boolean
isHostOverloaded(Host host)
Checks if host is currently over utilized, according the the conditions defined by the Allocation Policy.boolean
isHostUnderloaded(Host host)
Checks if a host is under utilized, based on current CPU usage.protected boolean
notAllVmsAreMigratingOut(Host host)
Checks if all VMs of a Host are NOT migrating out.void
setUnderUtilizationThreshold(double underUtilizationThreshold)
Sets the percentage of total CPU utilization to indicate that a host is under used and its VMs have to be migrated.protected void
setVmSelectionPolicy(PowerVmSelectionPolicy vmSelectionPolicy)
Sets the vm selection policy.-
Methods inherited from class org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyAbstract
addPesFromHost, addUsedPes, allocateHostForVm, allocateHostForVm, deallocateHostForVm, getDatacenter, getHostFreePesMap, getHostList, removeUsedPes, scaleVmVertically, setDatacenter, setFindHostForVmFunction, setHostFreePesMap, setUsedPes
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicy
allocateHostForVm, allocateHostForVm, deallocateHostForVm, getDatacenter, getHostList, scaleVmVertically, setDatacenter, setFindHostForVmFunction
-
Methods inherited from interface org.cloudbus.cloudsim.allocationpolicies.migration.VmAllocationPolicyMigration
getOverUtilizationThreshold
-
-
-
-
Constructor Detail
-
VmAllocationPolicyMigrationAbstract
public VmAllocationPolicyMigrationAbstract(PowerVmSelectionPolicy vmSelectionPolicy)
Creates a VmAllocationPolicyMigrationAbstract.- Parameters:
vmSelectionPolicy
- the policy that defines how VMs are selected for migration
-
VmAllocationPolicyMigrationAbstract
public VmAllocationPolicyMigrationAbstract(PowerVmSelectionPolicy vmSelectionPolicy, BiFunction<VmAllocationPolicy,Vm,Optional<Host>> findHostForVmFunction)
Creates a new VmAllocationPolicy, changing theFunction
to select a Host for a Vm.- Parameters:
vmSelectionPolicy
- the policy that defines how VMs are selected for migrationfindHostForVmFunction
- aFunction
to select a Host for a given Vm. Passing null makes the Function to be set as the defaultfindHostForVm(Vm)
.- See Also:
VmAllocationPolicy.setFindHostForVmFunction(java.util.function.BiFunction)
-
-
Method Detail
-
getOptimizedAllocationMap
public Map<Vm,Host> getOptimizedAllocationMap(List<? extends Vm> vmList)
Description copied from class:VmAllocationPolicyAbstract
Gets a map of optimized allocation for VMs according to current utilization and Hosts under and overloaded conditions. The conditions that will make a new VM placement map to be proposed and returned is defined by each implementing class.This method implementation doesn't perform any VM placement optimization and, in fact, has no effect. The
VmAllocationPolicyMigrationAbstract
class provides an actual implementation for this method that can be overridden by subclasses.- Specified by:
getOptimizedAllocationMap
in interfaceVmAllocationPolicy
- Overrides:
getOptimizedAllocationMap
in classVmAllocationPolicyAbstract
- Parameters:
vmList
- the list of VMs to be reallocated- Returns:
- the new vm placement map, where each key is a VM and each value is the host where such a Vm has to be placed
-
getPowerAfterAllocationDifference
protected double getPowerAfterAllocationDifference(Host host, Vm vm)
Gets the power consumption different after the supposed placement of a VM into a given Host and the original Host power consumption.- Parameters:
host
- the host to check the power consumptionvm
- the candidate vm- Returns:
- the host power consumption different after the supposed VM placement or 0 if the power consumption could not be determined
-
isHostOverloaded
public boolean isHostOverloaded(Host host)
Checks if host is currently over utilized, according the the conditions defined by the Allocation Policy. It's based on current CPU usage.- Specified by:
isHostOverloaded
in interfaceVmAllocationPolicyMigration
- Parameters:
host
- the host to check- Returns:
- true, if the host is over utilized; false otherwise
-
isHostUnderloaded
public boolean isHostUnderloaded(Host host)
Checks if a host is under utilized, based on current CPU usage.- Specified by:
isHostUnderloaded
in interfaceVmAllocationPolicyMigration
- Parameters:
host
- the host- Returns:
- true, if the host is under utilized; false otherwise
-
findHostForVm
public Optional<Host> findHostForVm(Vm vm)
Description copied from interface:VmAllocationPolicy
Finds a host that has enough resources to place a given VM. Classes must implement this method to define how to select a Host for a given VM. They just have to provide a default implementation. However, this implementation can be dynamically changed by callingVmAllocationPolicy.setFindHostForVmFunction(BiFunction)
.- Specified by:
findHostForVm
in interfaceVmAllocationPolicy
- Parameters:
vm
- the vm to find a host for it- Returns:
- an
Optional
containing a suitable Host to place the VM or an emptyOptional
if no suitable Host was found
-
findHostForVm
public Optional<Host> findHostForVm(Vm vm, Set<? extends Host> excludedHosts)
Finds a Host that has enough resources to place a given VM and that will not be overloaded after the placement. The selected Host will be that one with most efficient power usage for the given VM.This method performs the basic filtering and delegates additional ones and the final selection of the Host to other method.
- Parameters:
vm
- the VMexcludedHosts
- the excluded hosts- Returns:
- an
Optional
containing a suitable Host to place the VM or an emptyOptional
if not found - See Also:
findHostForVmInternal(Vm, Stream)
-
findHostForVm
public Optional<Host> findHostForVm(Vm vm, Set<? extends Host> excludedHosts, Predicate<Host> predicate)
Finds a Host that has enough resources to place a given VM and that will not be overloaded after the placement. The selected Host will be that one with most efficient power usage for the given VM.This method performs the basic filtering and delegates additional ones and the final selection of the Host to other method.
- Parameters:
vm
- the VMexcludedHosts
- the excluded hostspredicate
- an additionalPredicate
to be used to filter the Host to place the VM- Returns:
- an
Optional
containing a suitable Host to place the VM or an emptyOptional
if not found - See Also:
findHostForVmInternal(Vm, Stream)
-
findHostForVmInternal
protected Optional<Host> findHostForVmInternal(Vm vm, Stream<Host> hostStream)
Applies additional filters to the Hosts Stream and performs the actual Host selection. This method is a Stream's final operation, that it, it closes the Stream and returns anOptional
value.This method can be overridden by sub-classes to change the method used to select the Host for the given VM.
- Parameters:
vm
- the VM to find a Host to be placed intohostStream
- aStream
containing the Hosts after passing the basic filtering- Returns:
- an
Optional
containing a suitable Host to place the VM or an emptyOptional
if not found - See Also:
findHostForVm(Vm, Set)
,additionalHostFilters(Vm, Stream)
-
getVmsToMigrateFromUnderUtilizedHost
protected List<? extends Vm> getVmsToMigrateFromUnderUtilizedHost(Host host)
Gets the VMs to migrate from under utilized host.- Parameters:
host
- the host- Returns:
- the vms to migrate from under utilized host
-
getSwitchedOffHosts
protected List<Host> getSwitchedOffHosts()
Gets the switched off hosts.- Returns:
- the switched off hosts
-
notAllVmsAreMigratingOut
protected boolean notAllVmsAreMigratingOut(Host host)
Checks if all VMs of a Host are NOT migrating out. In this case, the given Host will not be selected as an underloaded Host at the current moment. That is: not all VMs are migrating out if at least one VM isn't in migration process.- Parameters:
host
- the host to check- Returns:
- true if at least one VM isn't migrating, false if all VMs are migrating
-
getPowerAfterAllocation
protected double getPowerAfterAllocation(Host host, Vm vm)
Gets the power consumption of a host after the supposed placement of a candidate VM. The VM is not in fact placed at the host.- Parameters:
host
- the host to check the power consumptionvm
- the candidate vm- Returns:
- the host power consumption after the supposed VM placement or 0 if the power consumption could not be determined
-
getMaxUtilizationAfterAllocation
protected double getMaxUtilizationAfterAllocation(Host host, Vm vm)
Gets the max power consumption of a host after placement of a candidate VM. The VM is not in fact placed at the host. We assume that load is balanced between PEs. The only restriction is: VM's max MIPS less than PE's MIPS- Parameters:
host
- the hostvm
- the vm- Returns:
- the power after allocation
-
getUtilizationOfCpuMips
protected double getUtilizationOfCpuMips(Host host)
Gets the utilization of the CPU in MIPS for the current potentially allocated VMs.- Parameters:
host
- the host- Returns:
- the utilization of the CPU in MIPS
-
addHistoryEntryIfAbsent
protected void addHistoryEntryIfAbsent(Host host, double metric)
Adds an entry for each history map of a host if it doesn't contain an entry for the current simulation time.- Parameters:
host
- the host to add metric history entriesmetric
- the metric to be added to the metric history map
-
setVmSelectionPolicy
protected final void setVmSelectionPolicy(PowerVmSelectionPolicy vmSelectionPolicy)
Sets the vm selection policy.- Parameters:
vmSelectionPolicy
- the new vm selection policy
-
getVmSelectionPolicy
protected PowerVmSelectionPolicy getVmSelectionPolicy()
Gets the vm selection policy.- Returns:
- the vm selection policy
-
getUtilizationHistory
public Map<Host,List<Double>> getUtilizationHistory()
Description copied from interface:VmAllocationPolicyMigration
Gets a read-only map of the utilization history for each Host.- Specified by:
getUtilizationHistory
in interfaceVmAllocationPolicyMigration
- Returns:
- the utilization history
-
getMetricHistory
public Map<Host,List<Double>> getMetricHistory()
Description copied from interface:VmAllocationPolicyMigration
Gets a read-only map of metric history.- Specified by:
getMetricHistory
in interfaceVmAllocationPolicyMigration
- Returns:
- the metric history
-
getTimeHistory
public Map<Host,List<Double>> getTimeHistory()
Description copied from interface:VmAllocationPolicyMigration
Gets a read-only map of times when entries in each history list was added for each Host. All history lists are updated at the same time.- Specified by:
getTimeHistory
in interfaceVmAllocationPolicyMigration
- Returns:
- the time history
-
getUnderUtilizationThreshold
public double getUnderUtilizationThreshold()
Description copied from interface:VmAllocationPolicyMigration
Gets the percentage of total CPU utilization to indicate that a host is under used and its VMs have to be migrated.- Specified by:
getUnderUtilizationThreshold
in interfaceVmAllocationPolicyMigration
- Returns:
- the under utilization threshold (in scale is from 0 to 1, where 1 is 100%)
-
setUnderUtilizationThreshold
public void setUnderUtilizationThreshold(double underUtilizationThreshold)
Description copied from interface:VmAllocationPolicyMigration
Sets the percentage of total CPU utilization to indicate that a host is under used and its VMs have to be migrated.- Specified by:
setUnderUtilizationThreshold
in interfaceVmAllocationPolicyMigration
- Parameters:
underUtilizationThreshold
- the under utilization threshold (in scale is from 0 to 1, where 1 is 100%)
-
getHostCpuUsageArray
protected double[] getHostCpuUsageArray(Host host)
Gets all CPU utilization values from theHost.getUtilizationHistorySum()
as an array.- Parameters:
host
- the Host to get the CPU utilization values- Returns:
- the utilization values array
-
-