cloudsim 学习笔记 实例5
更新时间:2023-05-12 03:51:01 阅读量: 实用文档 文档下载
- cloudsim推荐度:
- 相关推荐
cloudsim 学习笔记 实例
* Title: CloudSim Toolkit
* Description: CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
* of Clouds
* Licence: GPL - /copyleft/gpl.html
*
* Copyright (c) 2009, The University of Melbourne, Australia
*/
【试验五:怎样创建2个数据中心,各含1台主机,并在其上运行二个用户的云任务】 package org.cloudbus.cloudsim.examples;
import java.text.DecimalFormat; 【处理文本、日期、数字和消息的类和接口】【十进制格式】 import java.util.ArrayList; 【Java的实用工具类库java.util包】
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerSpaceShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
/**
* A simple example showing how to create
* two datacenters with one host each and
* run cloudlets of two users on them.
*/
public class CloudSimExample5 {
/** The cloudlet lists. */ 【云任务列表】
cloudsim 学习笔记 实例
private static List<Cloudlet> cloudletList1; 【两个用户的云任务,所以两个云任务列表】 private static List<Cloudlet> cloudletList2;
/** The vmlists. */ 【虚拟机列表,创建了两个】
private static List<Vm> vmlist1;
private static List<Vm> vmlist2;
/**
* Creates main() to run this example
*/ 【主函数运行实例】
public static void main(String[] args) {
Log.printLine("Starting CloudSimExample5...");
try {
// First step: Initialize the CloudSim package. It should be called 【初始化工具包】 // before creating any entities.
int num_user = 2; // number of cloud users 【2个用户】
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; // mean trace events
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);
// Second step: Create Datacenters 【创建数据中心 2个数据中心】
//Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation
Datacenter datacenter0 = createDatacenter("Datacenter_0");
Datacenter datacenter1 = createDatacenter("Datacenter_1");
//Third step: Create Brokers 【创建2个代理】
DatacenterBroker broker1 = createBroker(1);
int brokerId1 = broker1.getId();
DatacenterBroker broker2 = createBroker(2);
int brokerId2 = broker2.getId();
//Fourth step: Create one virtual machine for each broker/user 【为每个 代理/用户 创建一个虚拟机器】
vmlist1 = new ArrayList<Vm>();
vmlist2 = new ArrayList<Vm>();
//VM description 【虚拟机参数】
int vmid = 0;
cloudsim 学习笔记 实例
int mips = 250;
long size = 10000; //image size (MB)
int ram = 512; //vm memory (MB)
long bw = 1000;
int pesNumber = 1; //number of cpus
String vmm = "Xen"; //VMM name
//create two VMs: the first one belongs to user1 【第一个虚拟机属于用户1】 Vm vm1 = new Vm(vmid, brokerId1, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); 【代理1 brokerId1】
//the second VM: this one belongs to user2 【第二个虚拟机属于用户2】
Vm vm2 = new Vm(vmid, brokerId2, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());【代理2 brokerId2】
//add the VMs to the vmlists 【加入虚拟机列表】
vmlist1.add(vm1); 【加入虚拟机列表1】
vmlist2.add(vm2); 【加入虚拟机列表2】
//submit vm list to the broker 【虚拟机列表提交给代理】
broker1.submitVmList(vmlist1);
broker2.submitVmList(vmlist2);
//Fifth step: Create two Cloudlets 【创建二个云任务】
cloudletList1 = new ArrayList<Cloudlet>();
cloudletList2 = new ArrayList<Cloudlet>();
//Cloudlet properties 【云任务参数】
int id = 0;
long length = 40000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet1.setUserId(brokerId1); 【设置任务1给代理1】
Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
cloudlet2.setUserId(brokerId2); 【设置任务2给代理2】
//add the cloudlets to the lists: each cloudlet belongs to one user 【云任务加入列表,每个云任务属于一个用户】
cloudsim 学习笔记 实例
cloudletList2.add(cloudlet2); //submit cloudlet list to the brokers 【云任务列表提交给代理】 broker1.submitCloudletList(cloudletList1); broker2.submitCloudletList(cloudletList2);
【比较例子4 没有了bind the cloudlets to the vms !!!】
// Sixth step: Starts the simulation 【开始仿真】
CloudSim.startSimulation();
// Final step: Print results when simulation is over 【仿真结束 打印结果】 List<Cloudlet> newList1 = broker1.getCloudletReceivedList();
List<Cloudlet> newList2 = broker2.getCloudletReceivedList();
CloudSim.stopSimulation();
Log.print("=============> User "+brokerId1+" ");
printCloudletList(newList1);
Log.print("=============> User "+brokerId2+" ");
printCloudletList(newList2);
//Print the debt of each user to each datacenter 【打印账单】
datacenter0.printDebts();
datacenter1.printDebts();
Log.printLine("CloudSimExample5 finished!");
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}
private static Datacenter createDatacenter(String name){
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store 【创建列表储存机器】
// our machine
List<Host> hostList = new ArrayList<Host>();
// 2. A Machine contains one or more PEs or CPUs/Cores.
// In this example, it will have only one core.
List<Pe> peList = new ArrayList<Pe>();
cloudsim 学习笔记 实例
int mips=1000;
// 3. Create PEs and add these into a list. 【创建处理器 并添加到Pe列表】
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating 【Pe编号 和 处理速度】
//4. Create Host with its id and list of PEs and add them to the list of machines 【创建主机】
int hostId=0;
int ram = 2048; //host memory (MB)
long storage = 1000000; //host storage
int bw = 10000;
hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerSpaceShared(peList) 【虚拟机空间共享】 )
); // This is our first machine
// 5. Create a DatacenterCharacteristics object that stores the 【创建数据中心特征对象】
// properties of a data center: architecture, OS, list of
// Machines, allocation policy: time- or space-shared, time zone
// and its price (G$/Pe time unit).
String arch = "x86"; // system architecture
String os = "Linux"; // operating system
String vmm = "Xen";
double time_zone = 10.0; // time zone this resource located
double cost = 3.0; // the cost of using processing in this resource double costPerMem = 0.05; // the cost of using memory in this resource double costPerStorage = 0.001; // the cost of using storage in this resource double costPerBw = 0.0; // the cost of using bw in this resource
LinkedList<Storage> storageList = new LinkedList<Storage>(); //we are not adding
cloudsim 学习笔记 实例
SAN devices by now
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem, costPerStorage, costPerBw);
// 6. Finally, we need to create a PowerDatacenter object. 【创建数据中心对象】 Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}
return datacenter;
}
【创建代理,可以根据特定需求发展自己的代理协议来提交虚拟机和云任务】
//We strongly encourage users to develop their own broker policies, to submit vms and cloudlets according
//to the specific rules of the simulated scenario
private static DatacenterBroker createBroker(int id){ 【int id 相比例子四多出来的】
DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker"+id);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return broker;
}
/**
* Prints the Cloudlet objects
* @param list list of Cloudlets
*/ 【打印云任务对象】
private static void printCloudletList(List<Cloudlet> list) {
int size = list.size();
Cloudlet cloudlet;
String indent = " ";
Log.printLine();
cloudsim 学习笔记 实例
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent +
"Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + indent);
if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS){
Log.print("SUCCESS");
Log.printLine( indent + indent + cloudlet.getResourceId() + indent + indent + indent + cloudlet.getVmId() +
indent + indent + dft.format(cloudlet.getActualCPUTime()) + indent + indent + dft.format(cloudlet.getExecStartTime())+
indent + indent + dft.format(cloudlet.getFinishTime()));
}
}
}
}
Starting CloudSimExample5...
Initialising...
Starting CloudSim version 2.0
Datacenter_0 is starting...
Datacenter_1 is starting...
Broker1 is starting...
Broker2 is starting...
Entities started.
0.0: Broker1: Cloud Resource List received with 2 resource(s) 2个数据中心 0.0: Broker2: Cloud Resource List received with 2 resource(s) 0.0: Broker1: Trying to Create VM #0 in Datacenter_0
0.0: Broker2: Trying to Create VM #0 in Datacenter_0
[VmScheduler.vmCreate] Allocation of VM #0 to Host #0 failed by MIPS 0.0: Broker1: VM #0 has been created in Datacenter #2, Host #0 0.0: Broker1: Sending cloudlet 0 to VM #0
0.0: Broker2: Creation of VM #0 failed in Datacenter #2
0.0: Broker2: Trying to Create VM #0 in Datacenter_1
cloudsim 学习笔记 实例
0.0: Broker2: VM #0 has been created in Datacenter #3, Host #0 0.0: Broker2: Sending cloudlet 0 to VM #0
160.0: Broker1: Cloudlet 0 received
160.0: Broker1: All Cloudlets executed. Finishing...
160.0: Broker1: Destroying VM #0
160.0: Broker2: Cloudlet 0 received
160.0: Broker2: All Cloudlets executed. Finishing...
160.0: Broker2: Destroying VM #0
Broker1 is shutting down...
Broker2 is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down. Datacenter_0 is shutting down...
Datacenter_1 is shutting down...
Broker1 is shutting down...
Broker2 is shutting down...
Simulation completed.
Simulation completed.
=============> User 4
========== OUTPUT ==========
Cloudlet ID STATUS Data center ID VM ID Time Start Time Finish Time
0 SUCCESS 2 0 160 0 160 =============> User 5
========== OUTPUT ==========
Cloudlet ID STATUS Data center ID VM ID Time Start Time Finish Time
0 SUCCESS 3 0 160 0 160 *****PowerDatacenter: Datacenter_0*****
User id
4 Debt 35.6
**********************************
*****PowerDatacenter: Datacenter_1*****
User id
5 Debt 35.6
**********************************
CloudSimExample5 finished!
【疑问】
1. Data center ID是怎么来的?
2. User id 怎么是4 和 5?
正在阅读:
cloudsim 学习笔记 实例505-12
2015江幼测试题一10-20
汽轮机原理(热工机械)课后习题及答案05-03
长江水质评价与预测的数学模型03-04
画方圆游戏作文200字06-14
成大事者应拘小节 辩论材料06-26
电气施工方案06-12
- 教学能力大赛决赛获奖-教学实施报告-(完整图文版)
- 互联网+数据中心行业分析报告
- 2017上海杨浦区高三一模数学试题及答案
- 招商部差旅接待管理制度(4-25)
- 学生游玩安全注意事项
- 学生信息管理系统(文档模板供参考)
- 叉车门架有限元分析及系统设计
- 2014帮助残疾人志愿者服务情况记录
- 叶绿体中色素的提取和分离实验
- 中国食物成分表2020年最新权威完整改进版
- 推动国土资源领域生态文明建设
- 给水管道冲洗和消毒记录
- 计算机软件专业自我评价
- 高中数学必修1-5知识点归纳
- 2018-2022年中国第五代移动通信技术(5G)产业深度分析及发展前景研究报告发展趋势(目录)
- 生产车间巡查制度
- 2018版中国光热发电行业深度研究报告目录
- (通用)2019年中考数学总复习 第一章 第四节 数的开方与二次根式课件
- 2017_2018学年高中语文第二单元第4课说数课件粤教版
- 上市新药Lumateperone(卢美哌隆)合成检索总结报告
- 实例
- cloudsim
- 笔记
- 学习
- 预分解窑操作的体会(二)
- “电场强度”教学设计
- 2017考研英语备考冲刺建议
- 2014-2015(1)国际贸易实务模拟大作业
- 专四备考:过关全攻略之阅读
- 人教版地理七年级下册复习提纲
- 2014年《初中毕业升学复习指导》(化学)
- 资本市场分析专员岗位说明书-范本
- 成本估算的几种方式
- 吉林一中2010---2011学年度下学期期末测试 高一生物试题
- 北师大版数学八年级上学期第二章:实数 综合检测题(无答案)
- 别拦着我我要去悬崖上住世界最危险的村庄~
- 本科毕业论文(设计)写作规范
- 《“挑战杯”竞赛申报书填写及作品提交意事项》
- 永丰余电气监理细则
- 小学常用单位换算练习题
- 新型儿童蹬被提醒器-论文
- 仪器分析发展现状及其在农林科学中的应用
- 卡罗拉使用手册(1-30)
- 怎样去除桌面图标下文字的底色