Skip to content

Commit b84a747

Browse files
author
prachi
committed
Bug 9539 - cpu.overprovisioning.factor does not work
Changes: - Changed host allocators/planner to use cpu.overprovisioning.factor - Removed following: while adding a new host, we were setting the total_cpu in op_host_capacity to be actual_cpu * cpu.overprovisioning.factor. Now we set it to actual_cpu. - ListCapacities response now calculates the total CPU as actual * cpu.overprovisioning.factor (This change does not add anything new - listCapacities was pulling total CPU from op_host_capacity DB earlier which had the cpu.overprovisioning.factor applied already. Now we need to apply it over the DB entry.) - HostResponse has a new field: 'cpuWithOverprovisioning' that returns the cpu after applying the cpu.overprovisioning.factor - Db Upgrade 222 to 224 now updates the total_cpu in op_host_capacity to be the actual_cpu for each Routing host.
1 parent e6194b6 commit b84a747

13 files changed

Lines changed: 4933 additions & 4803 deletions

File tree

‎api/src/com/cloud/api/response/HostResponse.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public class HostResponse extends BaseResponse {
8080

8181
@SerializedName("cpuused") @Param(description="the amount of the host's CPU currently used")
8282
private String cpuUsed;
83+
84+
@SerializedName("cpuwithoverprovisioning") @Param(description="the amount of the host's CPU after applying the cpu.overprovisioning.factor ")
85+
private String cpuWithOverprovisioning;
8386

8487
@SerializedName("averageload") @Param(description="the cpu average load on the host")
8588
private Long averageLoad;
@@ -486,5 +489,13 @@ public String getAllocationState() {
486489

487490
public void setAllocationState(String allocationState) {
488491
this.allocationState = allocationState;
489-
}
492+
}
493+
494+
public String getCpuWithOverprovisioning() {
495+
return cpuWithOverprovisioning;
496+
}
497+
498+
public void setCpuWithOverprovisioning(String cpuWithOverprovisioning) {
499+
this.cpuWithOverprovisioning = cpuWithOverprovisioning;
500+
}
490501
}

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,7 +2723,7 @@ private void createCapacityEntry(final StartupCommand startup, HostVO server) {
27232723

27242724
if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
27252725
CapacityVO CapacityVOCpu = capacityVOCpus.get(0);
2726-
long newTotalCpu = (long) (server.getCpus().longValue() * server.getSpeed().longValue() * _cpuOverProvisioningFactor);
2726+
long newTotalCpu = (long) (server.getCpus().longValue() * server.getSpeed().longValue());
27272727
if ((CapacityVOCpu.getTotalCapacity() <= newTotalCpu) || ((CapacityVOCpu.getUsedCapacity() + CapacityVOCpu.getReservedCapacity()) <= newTotalCpu)) {
27282728
CapacityVOCpu.setTotalCapacity(newTotalCpu);
27292729
} else if ((CapacityVOCpu.getUsedCapacity() + CapacityVOCpu.getReservedCapacity() > newTotalCpu) && (CapacityVOCpu.getUsedCapacity() < newTotalCpu)) {
@@ -2736,7 +2736,7 @@ private void createCapacityEntry(final StartupCommand startup, HostVO server) {
27362736
_capacityDao.update(CapacityVOCpu.getId(), CapacityVOCpu);
27372737
} else {
27382738
CapacityVO capacity = new CapacityVO(server.getId(), server.getDataCenterId(), server.getPodId(), server.getClusterId(), 0L, (long) (server.getCpus().longValue()
2739-
* server.getSpeed().longValue() * _cpuOverProvisioningFactor), CapacityVO.CAPACITY_TYPE_CPU);
2739+
* server.getSpeed().longValue()), CapacityVO.CAPACITY_TYPE_CPU);
27402740
_capacityDao.persist(capacity);
27412741
}
27422742

‎server/src/com/cloud/agent/manager/allocator/impl/FirstFitAllocator.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected List<Host> allocateTo(ServiceOffering offering, VMTemplateVO template,
162162
boolean numCpusGood = host.getCpus().intValue() >= offering.getCpu();
163163
int cpu_requested = offering.getCpu() * offering.getSpeed();
164164
long ram_requested = offering.getRamSize() * 1024L * 1024L;
165-
boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false);
165+
boolean hostHasCapacity = _capacityMgr.checkIfHostHasCapacity(host.getId(), cpu_requested, ram_requested, false, _factor);
166166

167167
if (numCpusGood && hostHasCapacity) {
168168
if (s_logger.isDebugEnabled()) {
@@ -304,10 +304,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
304304
Map<String, String> configs = _configDao.getConfiguration(params);
305305
String opFactor = configs.get("cpu.overprovisioning.factor");
306306
_factor = NumbersUtil.parseFloat(opFactor, 1);
307-
//Over provisioning factor cannot be < 1. Reset to 1 in such cases
308-
if (_factor < 1){
309-
_factor = 1;
310-
}
311307

312308
String allocationAlgorithm = configs.get("vm.allocation.algorithm");
313309
if (allocationAlgorithm != null && (allocationAlgorithm.equals("random") || allocationAlgorithm.equals("firstfit"))) {

‎server/src/com/cloud/api/ApiDBUtils.java‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import com.cloud.agent.AgentManager;
2626
import com.cloud.async.AsyncJobManager;
2727
import com.cloud.async.AsyncJobVO;
28+
import com.cloud.configuration.Config;
2829
import com.cloud.configuration.ConfigurationService;
2930
import com.cloud.configuration.ResourceCount.ResourceType;
31+
import com.cloud.configuration.dao.ConfigurationDao;
3032
import com.cloud.dc.AccountVlanMapVO;
3133
import com.cloud.dc.ClusterVO;
3234
import com.cloud.dc.DataCenterVO;
@@ -103,6 +105,7 @@
103105
import com.cloud.user.dao.UserDao;
104106
import com.cloud.user.dao.UserStatisticsDao;
105107
import com.cloud.uservm.UserVm;
108+
import com.cloud.utils.NumbersUtil;
106109
import com.cloud.utils.component.ComponentLocator;
107110
import com.cloud.vm.DomainRouterVO;
108111
import com.cloud.vm.InstanceGroupVO;
@@ -156,6 +159,7 @@ public class ApiDBUtils {
156159
private static NetworkOfferingDao _networkOfferingDao;
157160
private static NetworkDao _networkDao;
158161
private static ConfigurationService _configMgr;
162+
private static ConfigurationDao _configDao;
159163

160164
static {
161165
_ms = (ManagementServer) ComponentLocator.getComponent(ManagementServer.Name);
@@ -199,6 +203,7 @@ public class ApiDBUtils {
199203
_securityGroupDao = locator.getDao(SecurityGroupDao.class);
200204
_networkOfferingDao = locator.getDao(NetworkOfferingDao.class);
201205
_networkDao = locator.getDao(NetworkDao.class);
206+
_configDao = locator.getDao(ConfigurationDao.class);
202207

203208
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
204209
_statsCollector = StatsCollector.getInstance();
@@ -569,5 +574,11 @@ public static boolean isSecurityGroupEnabledInZone(long zoneId) {
569574
public static Long getDedicatedNetworkDomain(long networkId) {
570575
return _networkMgr.getDedicatedNetworkDomain(networkId);
571576
}
577+
578+
public static float getCpuOverprovisioningFactor(){
579+
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
580+
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
581+
return cpuOverprovisioningFactor;
582+
}
572583

573584
}

‎server/src/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ public HostResponse createHostResponse(Host host) {
522522
}
523523
cpuAlloc = decimalFormat.format(((float) cpu / (float) (host.getCpus() * host.getSpeed())) * 100f) + "%";
524524
hostResponse.setCpuAllocated(cpuAlloc);
525+
526+
String cpuWithOverprovisioning = new Float(host.getCpus() * host.getSpeed() * ApiDBUtils.getCpuOverprovisioningFactor()).toString();
527+
hostResponse.setCpuWithOverprovisioning(cpuWithOverprovisioning);
525528
}
526529

527530
// calculate cpu utilized
@@ -2093,6 +2096,8 @@ private List<CapacityVO> sumCapacities(List<? extends Capacity> hostCapacities)
20932096
}
20942097
}
20952098

2099+
float cpuOverprovisioningFactor = ApiDBUtils.getCpuOverprovisioningFactor();
2100+
20962101
// collect all the capacity types, sum allocated/used and sum total...get one capacity number for each
20972102
for (Capacity capacity : hostCapacities) {
20982103
if (poolIdsToIgnore.contains(capacity.getHostOrPoolId())) {
@@ -2110,11 +2115,17 @@ private List<CapacityVO> sumCapacities(List<? extends Capacity> hostCapacities)
21102115

21112116
Long totalCapacity = totalCapacityMap.get(key);
21122117
Long usedCapacity = usedCapacityMap.get(key);
2118+
2119+
//reset overprovisioning factor to 1
2120+
float overprovisioningFactor = 1;
2121+
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
2122+
overprovisioningFactor = cpuOverprovisioningFactor;
2123+
}
21132124

21142125
if (totalCapacity == null) {
2115-
totalCapacity = new Long(capacity.getTotalCapacity());
2126+
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor));
21162127
} else {
2117-
totalCapacity = new Long(capacity.getTotalCapacity() + totalCapacity);
2128+
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
21182129
}
21192130

21202131
if (usedCapacity == null) {
@@ -2140,10 +2151,15 @@ private List<CapacityVO> sumCapacities(List<? extends Capacity> hostCapacities)
21402151
totalCapacity = totalCapacityMap.get(keyForPodTotal);
21412152
usedCapacity = usedCapacityMap.get(keyForPodTotal);
21422153

2154+
overprovisioningFactor = 1;
2155+
if (capacityType == Capacity.CAPACITY_TYPE_CPU){
2156+
overprovisioningFactor = cpuOverprovisioningFactor;
2157+
}
2158+
21432159
if (totalCapacity == null) {
2144-
totalCapacity = new Long(capacity.getTotalCapacity());
2160+
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor));
21452161
} else {
2146-
totalCapacity = new Long(capacity.getTotalCapacity() + totalCapacity);
2162+
totalCapacity = new Long((long)(capacity.getTotalCapacity() * overprovisioningFactor)) + totalCapacity;
21472163
}
21482164

21492165
if (usedCapacity == null) {

‎server/src/com/cloud/capacity/CapacityManager.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ public interface CapacityManager extends Manager {
3131

3232
void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost);
3333

34-
boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity);
34+
boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor);
3535
}

‎server/src/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, bo
124124
long usedMem = capacityMemory.getUsedCapacity();
125125
long reservedCpu = capacityCpu.getReservedCapacity();
126126
long reservedMem = capacityMemory.getReservedCapacity();
127-
long totalCpu = capacityCpu.getTotalCapacity();
127+
long actualTotalCpu = capacityCpu.getTotalCapacity();
128+
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
129+
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
130+
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
131+
if (s_logger.isDebugEnabled()) {
132+
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
133+
}
128134
long totalMem = capacityMemory.getTotalCapacity();
129135

130136
if (!moveFromReserved) {
@@ -153,12 +159,12 @@ public boolean releaseVmCapacity(VirtualMachine vm, boolean moveFromReserved, bo
153159
}
154160
}
155161

156-
s_logger.debug("release cpu from host: " + hostId + ", old used: " + usedCpu + ",reserved: " + reservedCpu + ", total: " + totalCpu +
157-
"; new used: " + capacityCpu.getUsedCapacity() + ",reserved:" + capacityCpu.getReservedCapacity() + ",total: " + capacityCpu.getTotalCapacity() +
162+
s_logger.debug("release cpu from host: " + hostId + ", old used: " + usedCpu + ",reserved: " + reservedCpu + ", actual total: " + actualTotalCpu + ", total with overprovisioning: " + totalCpu +
163+
"; new used: " + capacityCpu.getUsedCapacity() + ",reserved:" + capacityCpu.getReservedCapacity() +
158164
"; movedfromreserved: " + moveFromReserved + ",moveToReservered" + moveToReservered);
159165

160166
s_logger.debug("release mem from host: " + hostId + ", old used: " + usedMem + ",reserved: " + reservedMem + ", total: " + totalMem +
161-
"; new used: " + capacityMemory.getUsedCapacity() + ",reserved:" + capacityMemory.getReservedCapacity() + ",total: " + capacityMemory.getTotalCapacity() +
167+
"; new used: " + capacityMemory.getUsedCapacity() + ",reserved:" + capacityMemory.getReservedCapacity() +
162168
"; movedfromreserved: " + moveFromReserved + ",moveToReservered" + moveToReservered);
163169

164170
_capacityDao.update(capacityCpu.getId(), capacityCpu);
@@ -188,7 +194,10 @@ public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
188194
}
189195

190196
int cpu = svo.getCpu() * svo.getSpeed();
191-
long ram = svo.getRamSize() * 1024L * 1024L;
197+
long ram = svo.getRamSize() * 1024L * 1024L;
198+
199+
String opFactor = _configDao.getValue(Config.CPUOverprovisioningFactor.key());
200+
float cpuOverprovisioningFactor = NumbersUtil.parseFloat(opFactor, 1);
192201

193202
Transaction txn = Transaction.currentTxn();
194203

@@ -201,7 +210,11 @@ public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
201210
long usedMem = capacityMem.getUsedCapacity();
202211
long reservedCpu = capacityCpu.getReservedCapacity();
203212
long reservedMem = capacityMem.getReservedCapacity();
204-
long totalCpu = capacityCpu.getTotalCapacity();
213+
long actualTotalCpu = capacityCpu.getTotalCapacity();
214+
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
215+
if (s_logger.isDebugEnabled()) {
216+
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
217+
}
205218
long totalMem = capacityMem.getTotalCapacity();
206219

207220
long freeCpu = totalCpu - (reservedCpu + usedCpu);
@@ -236,13 +249,13 @@ public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
236249
}
237250

238251
s_logger.debug("CPU STATS after allocation: for host: " + hostId + ", old used: " + usedCpu + ", old reserved: " +
239-
reservedCpu + ", old total: " + totalCpu +
240-
"; new used:" + capacityCpu.getUsedCapacity() + ", reserved:" + capacityCpu.getReservedCapacity() + ", total: " + capacityCpu.getTotalCapacity() +
252+
reservedCpu + ", actual total: " + actualTotalCpu + ", total with overprovisioning: " + totalCpu +
253+
"; new used:" + capacityCpu.getUsedCapacity() + ", reserved:" + capacityCpu.getReservedCapacity() +
241254
"; requested cpu:" + cpu + ",alloc_from_last:" + fromLastHost);
242255

243256
s_logger.debug("RAM STATS after allocation: for host: " + hostId + ", old used: " + usedMem + ", old reserved: " +
244-
reservedMem + ", old total: " + totalMem + "; new used: " + capacityMem.getUsedCapacity() + ", reserved: " +
245-
capacityMem.getReservedCapacity() + ", total: " + capacityMem.getTotalCapacity() + "; requested mem: " + ram + ",alloc_from_last:" + fromLastHost);
257+
reservedMem + ", total: " + totalMem + "; new used: " + capacityMem.getUsedCapacity() + ", reserved: " +
258+
capacityMem.getReservedCapacity() + "; requested mem: " + ram + ",alloc_from_last:" + fromLastHost);
246259

247260
_capacityDao.update(capacityCpu.getId(), capacityCpu);
248261
_capacityDao.update(capacityMem.getId(), capacityMem);
@@ -254,11 +267,11 @@ public void allocateVmCapacity(VirtualMachine vm, boolean fromLastHost) {
254267
}
255268

256269
@Override
257-
public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity){
270+
public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolean checkFromReservedCapacity, float cpuOverprovisioningFactor){
258271
boolean hasCapacity = false;
259272

260273
if (s_logger.isDebugEnabled()) {
261-
s_logger.debug("Checking if host: " + hostId + " has enough capacity for requested CPU: "+ cpu + " and requested RAM: "+ ram);
274+
s_logger.debug("Checking if host: " + hostId + " has enough capacity for requested CPU: "+ cpu + " and requested RAM: "+ ram + " , cpuOverprovisioningFactor: "+cpuOverprovisioningFactor);
262275
}
263276

264277
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
@@ -268,7 +281,12 @@ public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolea
268281
long usedMem = capacityMem.getUsedCapacity();
269282
long reservedCpu = capacityCpu.getReservedCapacity();
270283
long reservedMem = capacityMem.getReservedCapacity();
271-
long totalCpu = capacityCpu.getTotalCapacity();
284+
long actualTotalCpu = capacityCpu.getTotalCapacity();
285+
long totalCpu = (long)(actualTotalCpu * cpuOverprovisioningFactor);
286+
if (s_logger.isDebugEnabled()) {
287+
s_logger.debug("Hosts's actual total CPU: " + actualTotalCpu + " and CPU after applying overprovisioning: " + totalCpu);
288+
}
289+
272290
long totalMem = capacityMem.getTotalCapacity();
273291

274292

@@ -318,7 +336,7 @@ public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolea
318336
}
319337

320338
s_logger.debug("STATS: Can alloc CPU from host: " + hostId + ", used: " + usedCpu + ", reserved: " +
321-
reservedCpu + ", total: " + totalCpu +
339+
reservedCpu + ", actual total: "+actualTotalCpu + ", total with overprovisioning: " + totalCpu +
322340
"; requested cpu:" + cpu + ",alloc_from_last_host?:" + checkFromReservedCapacity);
323341

324342
s_logger.debug("STATS: Can alloc MEM from host: " + hostId + ", used: " + usedMem + ", reserved: " +
@@ -330,7 +348,7 @@ public boolean checkIfHostHasCapacity(long hostId, Integer cpu, long ram, boolea
330348
", reservedMem: " + reservedMem + ", requested mem: " + ram);
331349
} else {
332350
s_logger.debug("STATS: Failed to alloc resource from host: " + hostId + " reservedCpu: " + reservedCpu + ", used cpu: " + usedCpu + ", requested cpu: " + cpu +
333-
", total cpu: " + totalCpu +
351+
", actual total cpu: "+actualTotalCpu + ", total cpu with overprovisioning: " + totalCpu +
334352
", reservedMem: " + reservedMem + ", used Mem: " + usedMem + ", requested mem: " + ram + ", total Mem:" + totalMem);
335353
}
336354

‎server/src/com/cloud/capacity/dao/CapacityDao.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ public interface CapacityDao extends GenericDao<CapacityVO, Long> {
2828
void clearStorageCapacities();
2929
CapacityVO findByHostIdType(Long hostId, short capacityType);
3030
void clearNonStorageCapacities2();
31-
List<Long> orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone);
32-
List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType);
31+
List<Long> orderClustersInZoneOrPodByHostCapacities(long id, int requiredCpu, long requiredRam, short capacityTypeForOrdering, boolean isZone, float cpuOverprovisioningFactor);
32+
List<Long> listHostsWithEnoughCapacity(int requiredCpu, long requiredRam, Long clusterId, String hostType, float cpuOverprovisioningFactor);
3333
}

0 commit comments

Comments
 (0)