Cloudsim Plus中的虚拟机功耗(模拟工具)

时间:2019-02-05 02:56:26

标签: cloudsim

我正在为项目工作使用Cloudsim Plus(模拟工具),我需要计算每个虚拟机的功耗,以使用最大功耗减少策略来实施VM选择算法。

以下代码是我在PowerExample.java中编写的大型代码的一小部分,它已在clousimPlus examples文件夹中提供。我已经创建了四个虚拟机,两个主机和八个cloudlet。

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



1 个答案:

答案 0 :(得分:0)

基于您提到的PowerExample,您可以在模拟中添加以下方法以打印VM利用率历史记录(确保将CloudSim Plus更新为最新版本):

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();
    }
}

更新叉子后,您可以获得完整的PowerExample here