cloudsim - 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
解决方案
根据您提到的 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中所示
推荐阅读
- python - 如何从 python selenium 数据构建动态表?
- php - 升级到 1.32 后 rev_timestamp 无效
- regex - 打印标签的内容
- r - 如何修复此错误“rep 中的错误(是,length.out = len):尝试复制类型为 'S4' 的对象”
- bash - 如何编写脚本以使用特定的 AWS-Cli 配置文件将日常备份从本地系统上传到 AWS S3(权限:仅放入 AWS S3)
- swift - SwiftUI:如何遍历可绑定对象数组?
- ssh - 我想创建 ssh 隧道来访问 API
- java - ExecutorService 每次都给一个新的线程池有什么问题吗?
- python - 在熊猫中计算和添加列的最快方法是什么?
- kubernetes - Kubernetes 控制器 - ReplicaSet 与复制控制器等