Search in sources :

Example 1 with VdsCpuUsageComparator

use of org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator in project ovirt-engine by oVirt.

the class CpuAndMemoryBalancingPolicyUnit method getUnderUtilizedCPUHosts.

/**
 * Get hosts where the CPU is currently loaded to less than lowUtilization percents,
 * and which were over-utilized (in average) for more than cpuOverCommitDurationMinutes.
 *
 * Also filter out hosts with less than minVmCount VMs.
 *
 * minVmCount is useful for using this method to find a source of VMs for migration
 * (we do not care about hosts that have no VMs in that case). If you are looking
 * for a destination candidates, pass 0 there.
 *
 * @param relevantHosts - candidate hosts
 * @param lowUtilization - load threshold in percent
 * @param minVmCount - minimal number of VMs on a host
 * @param cpuOverCommitDurationMinutes - time limit in minutes
 */
protected List<VDS> getUnderUtilizedCPUHosts(Collection<VDS> relevantHosts, final int lowUtilization, final int minVmCount, final int cpuOverCommitDurationMinutes) {
    List<VDS> underUtilizedHosts = relevantHosts.stream().filter(p -> (p.getUsageCpuPercent() + calcSpmCpuConsumption(p)) < lowUtilization && p.getVmCount() >= minVmCount && (p.getCpuOverCommitTimestamp() == null || (getTime().getTime() - p.getCpuOverCommitTimestamp().getTime()) >= TimeUnit.MINUTES.toMillis(cpuOverCommitDurationMinutes))).collect(Collectors.toList());
    if (underUtilizedHosts.size() > 1) {
        // Assume all hosts belong to the same cluster
        Cluster cluster = clusterDao.get(underUtilizedHosts.get(0).getClusterId());
        Collections.sort(underUtilizedHosts, new VdsCpuUsageComparator(cluster != null && cluster.getCountThreadsAsCores(), slaValidator));
    }
    return underUtilizedHosts;
}
Also used : VmStatisticsDao(org.ovirt.engine.core.dao.VmStatisticsDao) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) FindVmAndDestinations(org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations) PolicyUnitImpl(org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl) Date(java.util.Date) VdsCpuUsageComparator(org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) VdsDao(org.ovirt.engine.core.dao.VdsDao) Map(java.util.Map) PolicyUnitParameter(org.ovirt.engine.core.bll.scheduling.PolicyUnitParameter) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Collectors(java.util.stream.Collectors) VdsSpmStatus(org.ovirt.engine.core.common.businessentities.VdsSpmStatus) VmDao(org.ovirt.engine.core.dao.VmDao) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) PendingResourceManager(org.ovirt.engine.core.bll.scheduling.pending.PendingResourceManager) Optional(java.util.Optional) BalanceResult(org.ovirt.engine.core.bll.scheduling.external.BalanceResult) SlaValidator(org.ovirt.engine.core.bll.scheduling.SlaValidator) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsCpuUsageComparator(org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

Example 2 with VdsCpuUsageComparator

use of org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator in project ovirt-engine by oVirt.

the class CpuAndMemoryBalancingPolicyUnit method getOverUtilizedCPUHosts.

/**
 * Get hosts where the CPU has been utilized to more than highUtilization percentage for
 * more than cpuOverCommitDurationMinutes minutes.
 *
 * @param relevantHosts - candidate hosts
 * @param highUtilization - threshold cpu usage in percents
 * @param cpuOverCommitDurationMinutes - time limit in minutes
 * @return - over utilized hosts
 */
protected List<VDS> getOverUtilizedCPUHosts(Collection<VDS> relevantHosts, final int highUtilization, final int cpuOverCommitDurationMinutes) {
    List<VDS> overUtilizedHosts = relevantHosts.stream().filter(p -> (p.getUsageCpuPercent() + calcSpmCpuConsumption(p)) >= highUtilization && p.getCpuOverCommitTimestamp() != null && (getTime().getTime() - p.getCpuOverCommitTimestamp().getTime()) >= TimeUnit.MINUTES.toMillis(cpuOverCommitDurationMinutes) && p.getVmCount() > 0).collect(Collectors.toList());
    if (overUtilizedHosts.size() > 1) {
        // Assume all hosts belong to the same cluster
        Cluster cluster = clusterDao.get(overUtilizedHosts.get(0).getClusterId());
        Collections.sort(overUtilizedHosts, new VdsCpuUsageComparator(cluster != null && cluster.getCountThreadsAsCores(), slaValidator).reversed());
    }
    return overUtilizedHosts;
}
Also used : VmStatisticsDao(org.ovirt.engine.core.dao.VmStatisticsDao) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) FindVmAndDestinations(org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations) PolicyUnitImpl(org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl) Date(java.util.Date) VdsCpuUsageComparator(org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) VdsDao(org.ovirt.engine.core.dao.VdsDao) Map(java.util.Map) PolicyUnitParameter(org.ovirt.engine.core.bll.scheduling.PolicyUnitParameter) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Collectors(java.util.stream.Collectors) VdsSpmStatus(org.ovirt.engine.core.common.businessentities.VdsSpmStatus) VmDao(org.ovirt.engine.core.dao.VmDao) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) PendingResourceManager(org.ovirt.engine.core.bll.scheduling.pending.PendingResourceManager) Optional(java.util.Optional) BalanceResult(org.ovirt.engine.core.bll.scheduling.external.BalanceResult) SlaValidator(org.ovirt.engine.core.bll.scheduling.SlaValidator) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsCpuUsageComparator(org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

Aggregations

ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 PolicyUnitImpl (org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl)2 PolicyUnitParameter (org.ovirt.engine.core.bll.scheduling.PolicyUnitParameter)2 SlaValidator (org.ovirt.engine.core.bll.scheduling.SlaValidator)2 BalanceResult (org.ovirt.engine.core.bll.scheduling.external.BalanceResult)2 PendingResourceManager (org.ovirt.engine.core.bll.scheduling.pending.PendingResourceManager)2 FindVmAndDestinations (org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations)2 VdsCpuUsageComparator (org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator)2