Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -704,22 +704,16 @@ public void updateCapacityForHost(final Host host) {
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
}
if (so.isDynamic()) {
usedMemory +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
clusterRamOvercommitRatio;
usedMemory += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be some intentional logic behind the old code:

ramOvercommitRatio is saved in VM settings (which is set equal to the clusterOvercommitRatio whenever the VM is started)
clusterRamOvercommitRatio is the current ratio set on the cluster.

The idea behind the old code seems to be that for running VMs the used stats are kept at the same ratio to the total capacity.

For example, let's say total capacity is 64G and a VM is using 32G (Half of the total capacity)
Now, the clusterOvercommitRatio is changed from 1 to 2.
The VM's used will change to 64G (32/1 * 2). This means the running VM is still using half of the total capacity of the host.

The logic seems to be a safeguard against a running VM not getting affected by sudden capacity jumps using the overCommit ratio of the cluster.

Think of a little extreme case when clusterOvercommitRatio is changed from 1 to 5. Without this change, it is bound to affect the running VM which might not be intended.

When the VM restarts, its ramOvercommitRatio will change to 2. The VM used will then become 32G (32/2 * 2).

Basically the logic seems to be that running VMs should not be affected by sudden jumps in the clusterOvercommitRatio.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are asking if this change is functionaly sane @abh1sar?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes @DaanHoogland , I think the behaviour is by design and this change will affect functionality

if(vmDetails.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
usedCpu +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()))) / cpuOvercommitRatio) *
clusterCpuOvercommitRatio;
usedCpu += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()));
} else {
usedCpu +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * so.getSpeed()) / cpuOvercommitRatio) *
clusterCpuOvercommitRatio;
usedCpu += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * so.getSpeed();
}
usedCpuCore += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()));
} else {
usedMemory += ((so.getRamSize() * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
usedCpu += ((so.getCpu() * so.getSpeed()) / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
usedMemory += so.getRamSize() * 1024L * 1024L;
usedCpu += so.getCpu() * so.getSpeed();
usedCpuCore += so.getCpu();
}
}
Expand Down Expand Up @@ -748,22 +742,16 @@ public void updateCapacityForHost(final Host host) {
so = _offeringsDao.findByIdIncludingRemoved(vm.getServiceOfferingId());
}
if (so.isDynamic()) {
reservedMemory +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L) / ramOvercommitRatio) *
clusterRamOvercommitRatio;
reservedMemory += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.memory.name())) * 1024L * 1024L;
if(vmDetails.containsKey(UsageEventVO.DynamicParameters.cpuSpeed.name())) {
reservedCpu +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()))) / cpuOvercommitRatio) *
clusterCpuOvercommitRatio;
reservedCpu += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuSpeed.name()));
} else {
reservedCpu +=
((Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * so.getSpeed()) / cpuOvercommitRatio) *
clusterCpuOvercommitRatio;
reservedCpu += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name())) * so.getSpeed();
}
reservedCpuCore += Integer.parseInt(vmDetails.get(UsageEventVO.DynamicParameters.cpuNumber.name()));
} else {
reservedMemory += ((so.getRamSize() * 1024L * 1024L) / ramOvercommitRatio) * clusterRamOvercommitRatio;
reservedCpu += (so.getCpu() * so.getSpeed() / cpuOvercommitRatio) * clusterCpuOvercommitRatio;
reservedMemory += so.getRamSize() * 1024L * 1024L;
reservedCpu += so.getCpu() * so.getSpeed();
reservedCpuCore += so.getCpu();
}
} else {
Expand Down
Loading