实例1

以 NetworkExample1 为例,该例子展示了如何创建一个有网络拓扑的数据中心并且在其上运行一个云任务。例子通过读取topology.brite 文件来构造网络拓扑。网络拓扑的信息包括节点的位置,节点间的有向边,边时延,边带宽等信息。能够模拟基于网络位置,时延,带宽等的网络环境,有效地计算网络传输造成的花销。与前面例子不同的是,网络编程需要调用 org.cloudbus.cloudsim.NetworkTopology 构造网络拓扑图,然后把 CloudSim 实体与拓扑图的节点进行映射。

public class NetworkExample1 {private static final String NETWORK_TOPOLOGY_FILE = "topology.brite";private static final int VM_PES = 1;private final Datacenter datacenter0;private final DatacenterBroker broker;private List<Cloudlet> cloudletList;private List<Vm> vmlist;private CloudSim simulation;public static void main(String[] args) {new NetworkExample1();}private NetworkExample1() {System.out.println("Starting " + getClass().getSimpleName());vmlist = new ArrayList<>();cloudletList = new ArrayList<>();simulation = new CloudSim();datacenter0 = createDatacenter();broker = createBroker();configureNetwork();createAndSubmitVms(broker);createAndSubmitCloudlets(broker);simulation.start();List<Cloudlet> newList = broker.getCloudletFinishedList();new CloudletsTableBuilder(newList).build();System.out.println(getClass().getSimpleName() + " finished!");}private void configureNetwork() {// load the network topology fileBriteNetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);simulation.setNetworkTopology(networkTopology);// maps CloudSim entities to BRITE entities// Datacenter will correspond to BRITE node 0int briteNode = 0;networkTopology.mapNode(datacenter0, briteNode);// Broker will correspond to BRITE node 3briteNode = 3;networkTopology.mapNode(broker, briteNode);}private void createAndSubmitCloudlets(DatacenterBroker broker) {final long length = 40000;final long fileSize = 300;final long outputSize = 300;// The RAM, CPU and Bandwidth UtilizationModel.final UtilizationModel utilizationModel = new UtilizationModelFull();Cloudlet cloudlet1 = new CloudletSimple(length, VM_PES).setFileSize(fileSize).setOutputSize(outputSize).setUtilizationModel(utilizationModel);// add the cloudlet to the listcloudletList.add(cloudlet1);// submit cloudlet list to the brokerbroker.submitCloudletList(cloudletList);}private void createAndSubmitVms(DatacenterBroker broker) {final int mips = 250;final long size = 10000; //image size (Megabyte)final int ram = 512; //vm memory (Megabyte)final long bw = 1000; //in Megabits/sVm vm1 = new VmSimple(mips, VM_PES).setRam(ram).setBw(bw).setSize(size).setCloudletScheduler(new CloudletSchedulerTimeShared());vmlist.add(vm1);broker.submitVmList(vmlist);}private Datacenter createDatacenter() {List<Host> hostList = new ArrayList<>();List<Pe> peList = new ArrayList<>();final long mips = 1000;peList.add(new PeSimple(mips, new PeProvisionerSimple()));final long ram = 2048; // in Megabytesfinal long storage = 1000000; // in Megabytesfinal long bw = 10000; //in Megabits/sHost host = new HostSimple(ram, bw, storage, peList);hostList.add(host);return new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());}/*** Creates a DatacenterBroker.*/private DatacenterBroker createBroker() {return new DatacenterBrokerSimple(simulation);}
}

网络拓扑

topology.brite 如下:
Topology: ( 5 Nodes, 8 Edges )
Model (1 - RTWaxman): 5 5 5 1 2 0.15000000596046448 0.20000000298023224 1 1
10.0 1024.0

Nodes: ( 5 )
0 1 3 3 3 -1 RT_NODE
1 0 3 3 3 -1 RT_NODE
2 4 3 3 3 -1 RT_NODE
3 3 1 3 3 -1 RT_NODE
4 3 3 4 4 -1 RT_NODE

Edges: ( 8 )
0 2 0 3.0 1.1 10.0 -1 -1 E_RT U
1 2 1 4.0 2.1 10.0 -1 -1 E_RT U
2 3 0 2.8284271247461903 3.9 10.0 -1 -1 E_RT U
3 3 1 3.605551275463989 4.1 10.0 -1 -1 E_RT U
4 4 3 2.0 5.0 10.0 -1 -1 E_RT U
5 4 2 1.0 4.0 10.0 -1 -1 E_RT U
6 0 4 2.0 3.0 10.0 -1 -1 E_RT U
7 1 4 3.0 4.1 10.0 -1 -1 E_RT U

程序会寻找标记“Nodes:”和“Edges:”

  • “Nodes”是节点信息,其中第一列是节点序号,第二列是节点的横坐标,第三列是纵坐标。
  • “Edges”是边信息,第一列是边序号,第二列是始节点序号,第三列是终节点序号,第四列是边长度,第五列是边时延,第六列是边带宽。CloudSim 中只用到了以上信息。如此,我们就能构造自己需要的网络拓扑了。

仿真结果

运行仿真样例的结果如下:

INFO ================== Starting CloudSim Plus 6.3.7 ==================

INFO 0.00: DatacenterSimple1 is starting…
INFO DatacenterBrokerSimple2 is starting…
INFO Entities started.
INFO 0.00: DatacenterBrokerSimple2: List of 1 datacenters(s) received.
INFO 0.00: DatacenterBrokerSimple2: Trying to create Vm 0 in DatacenterSimple1
INFO 3.90: VmAllocationPolicySimple: Vm 0 has been allocated to Host 0/DC 1
INFO 7.90: DatacenterBrokerSimple2: Sending Cloudlet 0 to Vm 0 in Host 0/DC 1.
INFO 7.90: DatacenterBrokerSimple2: All waiting Cloudlets submitted to some VM.
INFO 171.80: DatacenterBrokerSimple2: Cloudlet 0 finished in Vm 0 and returned to broker.
INFO 171.91: Processing last events before simulation shutdown.
INFO 171.91: DatacenterBrokerSimple2 is shutting down…
INFO 171.91: DatacenterBrokerSimple2: Requesting Vm 0 destruction.
INFO 175.81: DatacenterSimple: Vm 0 destroyed on Host 0/DC 1.
INFO Simulation: No more future events

INFO CloudInformationService0: Notify all CloudSim Plus entities to shutdown.

INFO ================== Simulation finished at time 175.81 ==================

SIMULATION RESULTSCloudlet|Status |DC|Host|Host PEs |VM|VM PEs   |CloudletLen|CloudletPEs|StartTime|FinishTime|ExecTimeID|       |ID|  ID|CPU cores|ID|CPU cores|         MI|  CPU cores|  Seconds|   Seconds| Seconds
-----------------------------------------------------------------------------------------------------0|SUCCESS| 1|   0|        1| 0|        1|      40000|          1|       12|       171|     159
-----------------------------------------------------------------------------------------------------

结果分析

实体之间的通信延迟是如何影响到模拟程序的clock推演的呢?答案是CloudSimEntity.sendsend(final SimEntity dest, double delay, final int cloudSimTag, final Object data)函数中调用了delay += getNetworkDelay(this, dest);。具体而言,所有实体(包括DatacenterSimple1, DatacenterBrokerSimple2)在向其它实体发送事件时,delay参数中包含了通信延迟。即schedule(dest, delay, cloudSimTag, data);

由拓扑图可知,节点0到节点3之间的通信时间为3.9秒。

  • 在3.9秒,Vm 0 has been allocated to Host 0/DC 1。因为在0秒时,DatacenterBrokerSimple2提交了虚拟机创建请求,经过3.9秒的通信才到达DatacenterSimple1
  • minTimeBetweenEvents为0.1,所以在DatacenterBrokerSimple2收到DC列表之后,Sending Cloudlet 0 to Vm 0 in Host 0/DC 1.的时间为:3.9*2+0.1 = 7.9s
  • 任务执行花费(40000/250)=160s, 当DatacenterBrokerSimple2收到执行结果时,时间为:7.9+160+3.9=171.8s
  • 后续的1.1秒暂时未搞清楚

实例2

构造网络拓扑

  • DC1: Node=0
  • DC2: Node = 2
  • Broker: Node=3

实例代码

public class NetworkExample2 {private static final String NETWORK_TOPOLOGY_FILE = "topology.brite";private static final int VM_PES = 1;private final List<Datacenter> datacenterList;private final List<Cloudlet> cloudletList;private final List<Vm> vmlist;private final CloudSim simulation;private final DatacenterBroker broker;public static void main(String[] args) {new NetworkExample2();}private NetworkExample2() {System.out.println("Starting " + getClass().getSimpleName());vmlist = new ArrayList<>();cloudletList = new ArrayList<>();datacenterList = new ArrayList<>();simulation = new CloudSim();for (int i = 0; i < 2; i++) {datacenterList.add(createDatacenter());}broker = createBroker();configureNetwork();createAndSubmitVms();createAndSubmitCloudlets();simulation.start();new CloudletsTableBuilder(broker.getCloudletFinishedList()).build();System.out.println(getClass().getSimpleName() + " finished!");}private void configureNetwork() {// Configures network by loading the network topology fileBriteNetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);simulation.setNetworkTopology(networkTopology);// Maps CloudSim entities to BRITE entities// Datacenter1 will correspond to BRITE node 0int briteNode = 0;networkTopology.mapNode(datacenterList.get(0), briteNode);// Datacenter2 will correspond to BRITE node 2briteNode = 2;networkTopology.mapNode(datacenterList.get(1), briteNode);// Broker will correspond to BRITE node 3briteNode = 3;networkTopology.mapNode(broker, briteNode);}private void createAndSubmitCloudlets() {final long length = 40000;final long fileSize = 300;final long outputSize = 300;final UtilizationModel utilizationModel = new UtilizationModelFull();Cloudlet cloudlet1 =new CloudletSimple(length, VM_PES).setFileSize(fileSize).setOutputSize(outputSize).setUtilizationModel(utilizationModel);Cloudlet cloudlet2 =new CloudletSimple(length, VM_PES).setFileSize(fileSize).setOutputSize(outputSize).setUtilizationModel(utilizationModel);cloudletList.add(cloudlet1);cloudletList.add(cloudlet2);broker.bindCloudletToVm(cloudletList.get(0), vmlist.get(0));broker.bindCloudletToVm(cloudletList.get(0), vmlist.get(1));broker.submitCloudletList(cloudletList);}private void createAndSubmitVms() {final int mips = 250;final long size = 10000; //image size (Megabyte)final int ram = 512; //vm memory (Megabyte)final long bw = 1000;Vm vm1 = new VmSimple(mips, VM_PES).setRam(ram).setBw(bw).setSize(size);Vm vm2 = new VmSimple(mips, VM_PES).setRam(ram).setBw(bw).setSize(size);vmlist.add(vm1);vmlist.add(vm2);broker.submitVmList(vmlist);}private Datacenter createDatacenter() {List<Host> hostList = new ArrayList<>();List<Pe> peList = new ArrayList<>();final long mips = 1000;peList.add(new PeSimple(mips, new PeProvisionerSimple()));final int ram = 2048; //host memory (Megabyte)final long storage = 1000000; //host storagefinal long bw = 10000;Host host = new HostSimple(ram, bw, storage, peList);hostList.add(host);return new DatacenterSimple(simulation, hostList, new VmAllocationPolicySimple());}private DatacenterBroker createBroker() {return new DatacenterBrokerSimple(simulation);}
}

仿真结果

INFO ================== Starting CloudSim Plus 6.3.7 ==================

INFO 0.00: DatacenterSimple1 is starting…
INFO 0.00: DatacenterSimple2 is starting…
INFO DatacenterBrokerSimple3 is starting…
INFO Entities started.
INFO 0.00: DatacenterBrokerSimple3: List of 2 datacenters(s) received.
INFO 0.00: DatacenterBrokerSimple3: Trying to create Vm 0 in DatacenterSimple1
INFO 0.00: DatacenterBrokerSimple3: Trying to create Vm 1 in DatacenterSimple1
INFO 3.90: VmAllocationPolicySimple: Vm 0 has been allocated to Host 0/DC 1
WARN 3.90: VmAllocationPolicySimple: No suitable host found for Vm 1 in Datacenter 1
INFO 7.90: DatacenterBrokerSimple3: Trying to create Vm 1 in DatacenterSimple2 (due to lack of a suitable Host in previous one)
INFO 12.90: VmAllocationPolicySimple: Vm 1 has been allocated to Host 0/DC 2
INFO 18.00: DatacenterBrokerSimple3: Sending Cloudlet 0 to Vm 0 in Host 0/DC 1.
INFO 18.00: DatacenterBrokerSimple3: Sending Cloudlet 1 to Vm 1 in Host 0/DC 2.
INFO 18.00: DatacenterBrokerSimple3: All waiting Cloudlets submitted to some VM.
INFO 181.90: DatacenterBrokerSimple3: Cloudlet 0 finished in Vm 0 and returned to broker.
INFO 183.00: DatacenterBrokerSimple3: Cloudlet 1 finished in Vm 1 and returned to broker.
INFO 183.11: Processing last events before simulation shutdown.
INFO 183.11: DatacenterBrokerSimple3 is shutting down…
INFO 183.11: DatacenterBrokerSimple3: Requesting Vm 1 destruction.
INFO 183.11: DatacenterBrokerSimple3: Requesting Vm 0 destruction.
INFO 187.01: DatacenterSimple: Vm 0 destroyed on Host 0/DC 1.
INFO 188.11: DatacenterSimple: Vm 1 destroyed on Host 0/DC 2.
INFO Simulation: No more future events

INFO CloudInformationService0: Notify all CloudSim Plus entities to shutdown.

INFO 188.11: DatacenterSimple2 is shutting down…

INFO  ================== Simulation finished at time 188.11 ==================SIMULATION RESULTSCloudlet|Status |DC|Host|Host PEs |VM|VM PEs   |CloudletLen|CloudletPEs|StartTime|FinishTime|ExecTimeID|       |ID|  ID|CPU cores|ID|CPU cores|         MI|  CPU cores|  Seconds|   Seconds| Seconds
-----------------------------------------------------------------------------------------------------0|SUCCESS| 1|   0|        1| 0|        1|      40000|          1|       22|       181|     1591|SUCCESS| 2|   0|        1| 1|        1|      40000|          1|       23|       183|     160
-----------------------------------------------------------------------------------------------------

CloudSim Plus仿真(四)相关推荐

  1. CloudSim云仿真的使用及论文阅读

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言:CloudSim介绍 CloudSim来源背景 CloudSim版本演变 一.CloudSim安装过程 运行环境配置 ...

  2. 部署CloudSim云计算仿真平台

    CloudSim是一个由Java语言编写的云计算仿真平台软件,提供给研究人员做仿真实验,由于本文主要介绍如何从0开始部署该平台软件,故此处不对CloudSim做详细介绍,如需对该平台进一步了解,请访问 ...

  3. CloudSim Plus仿真(一)

    简单例子 步骤 一个简单的仿真案例包括一下基本步骤: 初始化CloudSim 创建数据中心代理 创建数据中心.创建主机列表 在主机中放置虚拟机 创建云任务Cloudlet 提交划分的虚拟机列表给代理 ...

  4. CloudSim Plus仿真(二)

    简单案例 一个简单的仿真案例包括一下基本步骤: 初始化CloudSim 创建数据中心代理 创建数据中心.创建主机列表 在主机中放置虚拟机 创建云任务Cloudlet 提交划分的虚拟机列表给代理 提交云 ...

  5. CloudSim云计算仿真平台软件

    目录 1.1Eclipse的安装 1.2Eclipse的汉化 2.1CloudSim的下载 1.1 Eclipse的安装: 安装选择Eclipse IDE for Java Developers 1. ...

  6. CloudSim介绍与使用 云计算的建模与仿真

    本文主要介绍一下我在使用CloudSim时翻译.整理和理解的一些信息,以及我的使用经验,希望能对有需要的朋友们有所帮助~ 1.我翻译和理解的一些信息:     2009年4月8日,澳大利亚墨尔本大学的 ...

  7. 云计算仿真框架CloudSim介绍

    幻灯片1 云计算仿真框架CloudSim介绍 jiangzw#ihep.ac.cn (以下为本人某次报告做的调研的PPT及其它一些实践记录,为保证清晰度,一些插入的图片较大,可在新标签页中打开) (  ...

  8. 四足机器人|机器狗|仿生机器人|多足机器人|MATLAB动画仿真|Simulink动画仿真

    四足机器人|机器狗|仿生机器人|多足机器人|MATLAB动画仿真|Simulink动画仿真 四足机器人的连杆模型,利用机器人工具箱,行走规划是用的CPG,详情见 https://blog.csdn.n ...

  9. [四旋翼无人机PID仿真(一)

    @四旋翼无人机串级PID仿真 四旋翼无人机的数学模型的建立:在建立模型的过程中,采用了欧拉角来进行数学模型的建立.首先进行无人机结构以及飞行原理的分析,然后进行系统建模,在建模的过程中,首先对四旋翼无 ...

最新文章

  1. Splay ---- 2018牛客多校第三场 区间翻转搞区间位移 或者 rope可持久化块状链表
  2. 安装php出现php-cgi error 1
  3. 德语语言文学考研c1,2015-2016同济大学德语语言文学初试考研经验(下)
  4. HTML/CSS——PC端QQ飞车官网首页
  5. vijos 1067 Warcraft III 守望者的烦恼 矩阵
  6. 14行代码AC_Zero Array(思维)
  7. 《朝花夕拾》金句摘抄(二)
  8. java web开发学习手册_Java 人必备学习手册开发下载!
  9. ECMAScript 6学习总结(1)——ECMAScript 6入门简介
  10. 领域驱动设计DDD之读书笔记
  11. Flink 在众安保险金融业务的应用
  12. 解决——完美解决Anaconda打开Spyder5报错:link image0 hasn’t been detected!
  13. PS模仿欢乐颂电视剧海报的水彩效果
  14. 草根创业,我劝你抓住网络培训的机会!
  15. 【历史上的今天】11 月 26 日:中国移动的第1亿个用户;Microsoft 确立名字;控制论鼻祖出生
  16. 游戏开发20课 tilemap 绘制
  17. 穿普拉达的女王 观后感
  18. 应用在触摸面板中的电容式触摸芯片
  19. 外部表不是预期的格式错误
  20. 二进制表示负数的方法:“ 补数 ”

热门文章

  1. 基于matlab的梯度下降法实现线性回归
  2. access 数据分组
  3. 设计模式 -- 工厂模式
  4. google产品大全
  5. GitHub创建一个项目
  6. 6大行数字人民币推送子钱包扩大使用范围
  7. 基于ASP.NET的企业人事管理系统
  8. 交大计算机专硕 学费,上海交大这个专业学费大幅上涨,从4万涨到12万,家长:还上吗?...
  9. UltraEdit编码设置
  10. 中富金石诊股 稀土开采配额下发 来看看都有谁