Power Consumption of Virtual machine in CloudSim P

2020-05-09 14:58发布

I'm working on Cloudsim Plus(simulation Tool) for a project work and I need to calculate the power consumption of each Virtual machine for implementing VM SELECTION ALGORITHM using MAXIMUM POWER REDUCTION POLICY.

The below code is a small portion of large code, written by me in PowerExample.java which is already available in clousimPlus examples folder. I have created four Virtual machines, two host and eight cloudlets.

Map<Double, Double> percent = v.getUtilizationHistory().getHistory();
     System.out.println("Vm Id " + v.getId());
     System.out.println("----------------------------------------");
    for (Map.Entry<Double, Double> entry : percent.entrySet()) {
        System.out.println(entry.getKey() + " " + entry.getValue());
    }
}

Output of the above code :-

Vm Id 0
----------------------------------------
10.0 1.0
20.0 1.0
30.0 1.0
40.0 1.0
50.0 1.0
60.0 0.5
70.0 0.5
80.0 0.5
90.0 0.5
99.0 0.5
100.0 0.5
100.21 0.0
Vm Id 1
----------------------------------------
10.0 1.0
20.0 1.0
30.0 1.0
40.0 1.0
50.0 1.0
60.0 0.5
70.0 0.5
80.0 0.5
90.0 0.5
99.0 0.5
100.0 0.5
100.21 0.0
Vm Id 2
----------------------------------------
10.0 1.0
20.0 1.0
30.0 1.0
40.0 1.0
50.0 1.0
60.0 0.5
70.0 0.5
80.0 0.5
90.0 0.5
99.0 0.5
100.0 0.5
100.21 0.0
Vm Id 3
----------------------------------------
10.0 1.0
20.0 1.0
30.0 1.0
40.0 1.0
50.0 1.0
60.0 0.5
70.0 0.5
80.0 0.5
90.0 0.5
99.0 0.5
100.0 0.5
100.21 0.0



标签: cloudsim
1条回答
可以哭但决不认输i
2楼-- · 2020-05-09 15:36

Based on the PowerExample you mentioned, you can add the following method in your simulation to print VM utilization history (make sure you update your CloudSim Plus to the latest version):

private void printVmsCpuUtilizationAndPowerConsumption() {
    for (Vm vm : vmList) {
        System.out.println("Vm " + vm.getId() + " at Host " + vm.getHost().getId() + " CPU Usage and Power Consumption");
        double vmPower; //watt-sec
        double utilizationHistoryTimeInterval, prevTime = 0;
        final UtilizationHistory history = vm.getUtilizationHistory();
        for (final double time : history.getHistory().keySet()) {
            utilizationHistoryTimeInterval = time - prevTime;
            vmPower = history.vmPowerConsumption(time);
            final double wattsPerInterval = vmPower*utilizationHistoryTimeInterval;
            System.out.printf(
                "\tTime %8.1f | Host CPU Usage: %6.1f%% | Power Consumption: %8.0f Watt-Sec * %6.0f Secs = %10.2f Watt-Sec\n",
                time, history.vmCpuUsageFromHostCapacity(time) *100, vmPower, utilizationHistoryTimeInterval, wattsPerInterval);
            prevTime = time;
        }
        System.out.println();
    }
}

After updating your fork, you can get the complete PowerExample here.

Unfortunately, there is no built-in feature to store RAM and BW utilization. This way, you have to implement inside your simulation, as demonstrated in VmsRamAndBwUsageExample.java

查看更多
登录 后发表回答