首页 > 解决方案 > CloudSim Plus中虚拟机的功耗(模拟工具)

问题描述

我正在为项目工作使用 Cloudsim Plus(模拟工具),我需要计算每个虚拟机的功耗,以使用 MAXIMUM POWER REDUCTION POLICY 实现 VM SELECTION ALGORITHM。

下面的代码是我在 PowerExample.java 中编写的大代码的一小部分,它已经在 clousimPlus 示例文件夹中可用。我创建了四个虚拟机、两个主机和八个小云。

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

解决方案


根据您提到的 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();
    }
}

更新 fork 后,您可以在此处获取完整的 PowerExample 。

不幸的是,没有内置功能来存储 RAM 和 BW 利用率。这样,您必须在模拟中实现,如VmsRamAndBwUsageExample.java中所示


推荐阅读