CloudSim Plus(仿真工具)中虚拟机功耗
Power Consumption of Virtual machine in CloudSim Plus (simulation tool)
我正在为一个项目工作使用 Cloudsim Plus(模拟工具),我需要计算每个虚拟机的功耗,以使用最大功率降低策略实施 VM 选择算法。
下面的代码是我在 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
基于您提到的 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 here。
遗憾的是,没有内置功能来存储 RAM 和 BW 利用率。这样,您必须在模拟中实现,如 VmsRamAndBwUsageExample.java
中所示
我正在为一个项目工作使用 Cloudsim Plus(模拟工具),我需要计算每个虚拟机的功耗,以使用最大功率降低策略实施 VM 选择算法。
下面的代码是我在 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
基于您提到的 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 here。
遗憾的是,没有内置功能来存储 RAM 和 BW 利用率。这样,您必须在模拟中实现,如 VmsRamAndBwUsageExample.java
中所示