0

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



Manoel Campos
  • 933
  • 9
  • 12
mike
  • 13
  • 5
  • Welcome to Stack Overflow! Please review [writing the perfect question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question) to help you to ask a good question, and thus get a good answer. – Jeroen Heier Feb 05 '19 at 04:52
  • I think that whatever I wanted to ask, it's pretty clear. Cloudsim Plus is a simulation tool, which I am using for implementation of maximum power reduction algorithm. For that I want the value of power consumption of each Virtual machines. I am unable to figure out the retrieval of power consumption values. – mike Feb 05 '19 at 07:19

1 Answers1

1

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

Manoel Campos
  • 933
  • 9
  • 12
  • Thank you for this code. I was literally frustrated and was not able to calculate the power consumption. Can you also please suggest a solution of how to get the history of RAM Utilization and Bandwidth Utilization. It would be a great help. – mike Mar 23 '19 at 07:08
  • Unfortunately, there is no built-in feature to store RAM and BW utilization. Update your CloudSim Plus fork and check the complete example [VmsRamAndBwUsageExample.java](https://github.com/manoelcampos/cloudsim-plus/blob/master/cloudsim-plus-examples/src/main/java/org/cloudsimplus/examples/resourceusage/VmsRamAndBwUsageExample.java) – Manoel Campos Mar 30 '19 at 01:14