Cloudslab / cloudsim

CloudSim: A Framework For Modeling And Simulation Of Cloud Computing Infrastructures And Services
http://www.cloudbus.org/cloudsim/
816 stars 491 forks source link

I discover an error in finHostForVm function #167

Open amrous opened 1 year ago

amrous commented 1 year ago

Dear CloudSim Development Team,

I hope this message finds you well. I have been using CloudSim and recently came across what appears to be a potential issue in the implementation of the Power-aware, Best-Fit (PABFD) Virtual Machine allocation policy through the findHostForVm function.

The issue I've observed pertains to the calculation of powerDiff before and after creating a virtual machine on a given host. It seems that the original algorithm, as implemented in CloudSim, does not take into account the presence of other VMs that may already created on the host during the current vmList placement, before allocating the current VM. To address this, I have made a modification to the code. Instead of using host.getPower(), I suggest using getUtilizationOfCpuMips(host) to obtain the host's utilization. This modification allows for a more accurate calculation of powerDiff while considering existing VMs on the host. Additionally, when allocating a VM on a host that is switched off and has no utilization, I propose that the cost should be based solely on powerAfterAllocation rather than powerAfterAllocation - powerBeforeAllocation. This adjustment accounts for the fact that powerBeforeAllocation is equal to zero when the host is switched off. Here is the modified code snippet that reflects these changes:

`public PowerHost findHostForVm2(Vm vm, Set<? extends Host> excludedHosts) { double minPower = Double.MAX_VALUE; PowerHost allocatedHost = null;

    for (PowerHost host : this.<PowerHost> getHostList()) {

        if (excludedHosts.contains(host)) {
            continue;
        }

        if (host.isSuitableForVm(vm)) {

            if (getUtilizationOfCpuMips(host) != 0 && isHostOverUtilizedAfterAllocation(host, vm)) {

                continue;
            }

            try {
                double powerAfterAllocation = getPowerAfterAllocation(host, vm);
                if (powerAfterAllocation != -1) {

                    double powerDiff;
                    if (getUtilizationOfCpuMips(host) == 0) {
                        powerDiff=powerAfterAllocation;
                    }
                    else {
                        powerDiff= powerAfterAllocation -host.getPowerModel().getPower(getUtilizationOfCpuMips(host)/ (host).getTotalMips());

                        }

                    if (powerDiff < minPower) {

                        minPower = powerDiff;
                        allocatedHost = host;

                    }
                }

            } catch (Exception e) {

            }

        }

    }
    return allocatedHost;
}`

I kindly request your consideration of these suggestions for improving the accuracy of the PABFD algorithm in CloudSim.

Best regards,