cloudsim 学习笔记 实例6.doc_第1页
cloudsim 学习笔记 实例6.doc_第2页
cloudsim 学习笔记 实例6.doc_第3页
cloudsim 学习笔记 实例6.doc_第4页
cloudsim 学习笔记 实例6.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

* 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 */【试验六:怎样创建扩展的仿真】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.VmSchedulerTimeShared;import org.cloudbus.cloudsim.core.CloudSim;import visioners.BwProvisionerSimple;import visioners.PeProvisionerSimple;import visioners.RamProvisionerSimple;/* * An example showing how to create * scalable simulations. */public class CloudSimExample6 /* The cloudlet list. */ 【云任务列表】private static List cloudletList;/* The vmlist. */ 【虚拟机列表】private static List vmlist;private static List createVM(int userId, int vms) 【创建一个容器储存虚拟机,之后提交给代理】/Creates a container to store VMs. This list is passed to the broker laterLinkedList list = new LinkedList();/VM Parameters 【虚拟机参数】long size = 10000; /image size (MB)int ram = 512; /vm memory (MB)int mips = 250;long bw = 1000;int pesNumber = 1; /number of cpusString vmm = Xen; /VMM name/create VMs 【创建虚拟机】Vm vm = new Vmvms;for(int i=0;ivms;i+)vmi = new Vm(i, userId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared(); 【云任务时间共享】/for creating a VM with a space shared scheduling policy for cloudlets:/vmi = Vm(i, userId, mips, pesNumber, ram, bw, size, priority, vmm, new CloudletSchedulerSpaceShared();【云任务空间共享】list.add(vmi);return list;【创建一个容器储存云任务】private static List createCloudlet(int userId, int cloudlets)/ Creates a container to store CloudletsLinkedList list = new LinkedList();/cloudlet parameters 【云任务属性】long length = 4000;long fileSize = 300;long outputSize = 300;int pesNumber = 1;UtilizationModel utilizationModel = new UtilizationModelFull();Cloudlet cloudlet = new Cloudletcloudlets;for(int i=0;icloudlets;i+)cloudleti = new Cloudlet(i, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);/ setting the owner of these Cloudlets 【云任务设置相应的用户】cloudleti.setUserId(userId); list.add(cloudleti);return list;/ STATIC METHODS / 【静态方法】/* * Creates main() to run this example */ 【主函数运行实例】public static void main(String args) Log.printLine(Starting CloudSimExample6.);try / First step: Initialize the CloudSim package. It should be called/ before creating any num_user = 1; / number of grid users 【应该是云用户吧,怎么出来了网格用户!】Calendar calendar = Calendar.getInstance();boolean trace_flag = false; / mean trace events/ Initialize the CloudSim libraryCloudSim.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 simulationDatacenter datacenter0 = createDatacenter(Datacenter_0);Datacenter datacenter1 = createDatacenter(Datacenter_1);/Third step: Create Broker 【创建代理】DatacenterBroker broker = createBroker();int brokerId = broker.getId();/Fourth step: Create VMs and Cloudlets and send them to brokervmlist = createVM(brokerId,20); /creating 20 vms 【创建20个虚拟机】cloudletList = createCloudlet(brokerId,40); / creating 40 cloudlets 【创建40个云任务】broker.submitVmList(vmlist);broker.submitCloudletList(cloudletList);/ Fifth step: Starts the simulation 【开始仿真】CloudSim.startSimulation();/ Final step: Print results when simulation is over 【仿真结束 打印结果】List newList = broker.getCloudletReceivedList();CloudSim.stopSimulation();printCloudletList(newList);/Print the debt of each user to each datacenter 【打印账单】datacenter0.printDebts();datacenter1.printDebts();Log.printLine(CloudSimExample6 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 one or more 【创建列表储存机器】/ MachinesList hostList = new ArrayList();/ 2. A Machine contains one or more PEs or CPUs/Cores. Therefore, should/ create a list to store these PEs before creating/ a Machine.List peList1 = new ArrayList();int mips = 1000;/ 3. Create PEs and add these into the list./for a quad-core machine, a list of 4 PEs is required: 【4个PE】peList1.add(new Pe(0, new PeProvisionerSimple(mips); / need to store Pe id and MIPS RatingpeList1.add(new Pe(1, new PeProvisionerSimple(mips);peList1.add(new Pe(2, new PeProvisionerSimple(mips);peList1.add(new Pe(3, new PeProvisionerSimple(mips);/Another list, for a dual-core machine 【双核 2个PE】List peList2 = new ArrayList();peList2.add(new Pe(0, new PeProvisionerSimple(mips);peList2.add(new Pe(1, new PeProvisionerSimple(mips);/4. Create Hosts 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 storageint bw = 10000;hostList.add( new Host( hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList1, new VmSchedulerTimeShared(peList1) 【虚拟机时间共享】 ) ); / This is our first machinehostId+;hostList.add( new Host( hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList2, new VmSchedulerTimeShared(peList2) 【虚拟机时间共享】 ) ); / Second machine【虚拟机空间共享 采用以下方法】/To create a host with a space-shared allocation policy for PEs to VMs:/hostList.add( /new Host( /hostId, /new CpuProvisionerSimple(peList1), /new RamProvisionerSimple(ram), /new BwProvisionerSimple(bw), /storage, /new VmSchedulerSpaceShared(peList1) /) /);/To create a host with a oportunistic space-shared allocation policy for PEs to VMs:/hostList.add( /new Host( /hostId, /new CpuProvisionerSimple(peList1), /new RamProvisionerSimple(ram), /new BwProvisionerSimple(bw), /storage, /new VmSchedulerOportunisticSpaceShared(peList1) /) /);/ 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 architectureString os = Linux; / operating systemString vmm = Xen;double time_zone = 10.0; / time zone this resource locateddouble cost = 3.0; / the cost of using processing in this resourcedouble costPerMem = 0.05;/ the cost of using memory in this resourcedouble costPerStorage = 0.1;/ the cost of using storage in this resourcedouble costPerBw = 0.1;/ the cost of using bw in this resourceLinkedList storageList = new LinkedList();/we are not adding SAN devices by nowDatacenterCharacteristics 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 scenarioprivate static DatacenterBroker createBroker()DatacenterBroker broker = null;try broker = new DatacenterBroker(Broker); catch (Exception e) e.printStackTrace();return null;return broker;/* * Prints the Cloudlet objects * param list list of Cloudlets */private static void printCloudletList(List list) int size = list.size();Cloudlet cloudlet;String indent = ;Log.printLine();Log.printLine(= OUTPUT =);Log.printLine(Cloudlet ID + indent + STATUS + indent +Data center ID + indent + VM ID + indent + 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 + indent + dft.format(cloudlet.getActualCPUTime() +indent + indent + dft.format(cloudlet.getExecStartTime()+ indent + indent + indent + dft.format(cloudlet.getFinishTime();仿真结果Starting CloudSimExample6.Initialising.Starting CloudSim version 2.0Datacenter_0 is starting.Datacenter_1 is starting.Broker is starting.Entities started.0.0: Broker: Cloud Resource List received with 2 resource(s)【2个数据中心】0.0: Broker: Trying to Create VM #0 in Datacenter_00.0: Broker: Trying to Create VM #1 in Datacenter_00.0: Broker: Trying to Create VM #2 in Datacenter_00.0: Broker: Trying to Create VM #3 in Datacenter_00.0: Broker: Trying to Create VM #4 in Datacenter_00.0: Broker: Trying to Create VM #5 in Datacenter_00.0: Broker: Trying to Create VM #6 in Datacenter_00.0: Broker: Trying to Create VM #7 in Datacenter_00.0: Broker: Trying to Create VM #8 in Datacenter_00.0: Broker: Trying to Create VM #9 in Datacenter_00.0: Broker: Trying to Create VM #10 in Datacenter_00.0: Broker: Trying to Create VM #11 in Datacenter_00.0: Broker: Trying to Create VM #12 in Datacenter_00.0: Broker: Trying to Create VM #13 in Datacenter_00.0: Broker: Trying to Create VM #14 in Datacenter_00.0: Broker: Trying to Create VM #15 in Datacenter_00.0: Broker: Trying to Create VM #16 in Datacenter_00.0: Broker: Trying to Create VM #17 in Datacenter_00.0: Broker: Trying to Create VM #18 in Datacenter_00.0: Broker: Trying to Create VM #19 in Datacenter_0Allocation of VM #6 to Host #0 failed by RAMAllocation of VM #7 to Host #0 failed by RAMAllocation of VM #8 to Host #0 failed by RAMAllocation of VM #8 to Host #1 failed by RAMAllocation of VM #9 to Host #0 failed by RAMAllocation of VM #9 to Host #1 failed by RAMAllocation of VM #10 to Host #0 failed by RAMAllocation of VM #10 to Host #1 failed by RAMAllocation of VM #11 to Host #0 failed by RAMAllocation of VM #11 to Host #1 failed by RAMAllocation of VM #12 to Host #0 failed by RAMAllocation of VM #12 to Host #1 failed by RAMAllocation of VM #13 to Host #0 failed by RAMAllocation of VM #13 to Host #1 failed by RAMAllocation of VM #14 to Host #0 failed by RAMAllocation of VM #14 to Host #1 failed by RAMAllocation of VM #15 to Host #0 failed by RAMAllocation of VM #15 to Host #1 failed by RAMAllocation of VM #16 to Host #0 failed by RAMAllocation of VM #16 to Host #1 failed by RAMAllocation of VM #17 to Host #0 failed by RAMAllocation of VM #17 to Host #1 failed by RAMAllocation of VM #18 to Host #0 failed by RAMAllocation of VM #18 to Host #1 failed by RAMAllocation of VM #19 to Host #0 failed by RAMAllocation of VM #19 to Host #1 failed by RAM0.0: Broker: VM #0 has been created in Datacenter #2, Host #00.0: Broker: VM #1 has been created in Datacenter #2, Host #00.0: Broker: VM #2 has been created in Datacenter #2, Host #00.0: Broker: VM #3 has been created in Datacenter #2, Host #10.0: Broker: VM #4 has been created in Datacenter #2, Host #00.0: Broker: VM #5 has been created in Datacenter #2, Host #10.0: Broker: VM #6 has been created in Datacenter #2, Host #10.0: Broker: VM #7 has been created in Datacenter #2, Host #10.0: Broker: Creation of VM #8 failed in Datacenter #20.0: Broker: Creation of VM #9 failed in Datacenter #20.0: Broker: Creation of VM #10 failed in Datacenter #20.0: Broker: Creation of VM #11 failed in Datacenter #20.0: Broker: Creation of VM #12 failed in Datacenter #20.0: Broker: Creation of VM #13 failed in Datacenter #20.0: Broker: Creation of VM #14 failed in Datacenter #20.0: Broker: Creation of VM #15 failed in Datacenter #20.0: Broker: Creation of VM #16 failed in Datacenter #20.0: Broker: Creation of VM #17 failed in Datacenter #20.0: Broker: Creation of VM #18 failed in Datacenter #20.0: Broker: Creation of VM #19 failed in Datacenter #20.0: Broker: Trying to Create VM #8 in Datacenter_10.0: Broker: Trying to Create VM #9 in Datacenter_10.0: Broker: Trying to Create VM #10 in Datacenter_10.0: Broker: Trying to Create VM #11 in Datacenter_10.0: Broker: Trying to Create VM #12 in Datacenter_10.0: Broker: Trying to Create VM #13 in Datacenter_10.0: Broker: Trying to Create VM #14 in Datacenter_10.0: Broker: Trying to Create VM #15 in Datacenter_10.0: Broker: Trying to Create VM #16 in Datacenter_10.0: Broker: Trying to Create VM #17 in Datacenter_10.0: Broker: Trying to Create VM #18 in Datacenter_10.0: Broker: Trying to Create VM #19 in Datacenter_1Allocation of VM #14 to Host #0 failed by RAMAllocation of VM #15 to Host #0 failed by RAMAllocation of VM #16 to Host #0 failed by RAMAllocation of VM #16 to Host #1 failed by RAMAllocation of VM #17 to Host #0 failed by RAMAllocation of VM #17 to Host #1 failed by RAMAllocation of VM #18 to Host #0 failed by RAMAllocation of VM #18 to Host #1 failed by RAMAllocation of VM #19 to Host #0 failed by RAMAllocation of VM #19 to Host #1 failed by RAM0.0: Broker: VM #8 has been created in Datacenter #3, Host #00.0: Broker: VM #9 has been created in Datacenter #3, Host #00.0: Broker: VM #10 has been created in Datacenter #3, Host #00.0: Broker: VM #11 has been created in Datacenter #3, Host #10.0: Broker: VM #12 has been created in Datacenter #3, Host #00.0: Broker: VM #13 has been created in Datacenter #3, Host #10.0: Broker: VM #14 has been created in Datacenter #3, Host #10.0: Broker: VM #15 has been created in Datacenter #3, Host #10.0: Broker: Creation of VM #16 failed in Datacenter #30.0: Broker: Creation of VM #17 failed in Datacenter #30.0: Broker: Creation of VM #18 failed in Datacenter #30.0: Broker: Creation of VM #19 failed in Datacenter #30.0: Broker: Sending cloudlet 0 to VM #00.0: Broker: Sending cloudlet 1 to VM #10.0: Broker: Sending cloudlet 2 to VM #20.0: Broker: Sending cloudlet 3 to VM #30.0: Broker: Sending cloudlet 4 to VM #40.0: Broker: Sending cloudlet 5 to VM #50.0: Broker: Sending cloudlet 6 to VM #60.0: Broker: Sending cloudlet 7 to VM #70.0: Broker: Sending cloudlet 8 to VM #80.0: Broker: Sending cloudlet 9 to VM #90.0: Broker: Sending cloudlet 10 to VM #100.0: Broker: Sending cloudlet 11 to VM #110.0: Broker: Sending cloudlet 12 to VM #120.0: Broker: Sending cloudlet 13 to VM #130.0: Broker: Sending cloudlet 14 to VM #140.0: Broker: Sending cloudlet 15 to VM #150.0: Broker: Sending cloudlet 16 to VM #00.0: Broker: Sending cloudlet 17 to VM #10.0: Broker: Sending cloudlet 18 to VM #20.0: Broker: Sending cloudlet 19 to VM #30.0: Broker: Sending cloudlet 20 to VM #40.0: Broker: Sending cloudlet 21 to VM #50.0: Broker: Sending cloudlet 22 to VM #60.0: Broker: Sending cloudlet 23 to VM #70.0: Broker: Sending cloudlet 24 to VM #80.0: Broker: Sending cloudlet 25 to VM #90.0: Broker: Sending cloudlet 26 to VM #100.0: Broker: Sending cloudlet 27 to VM #110.0: Broker: Sending cloudlet 28 to VM #120.0: Broker: Sending cloudlet 29 to VM #130.0: Broker: Sending cloudlet 30 to VM #140.0: Broker: Sending cloudlet 31 to VM #150.0: Broker: Sending cloudlet 32 to VM #00.0: Broker: Sending cloudlet 33 to VM #10.0: Broker: Sending cloudlet 34 to VM #20.0: Broker: Sending cloudlet 35 to VM #30.0: Broker: Sending cloudlet 36 to VM #40.0: Broker: Sending cloudlet 37 to VM #50.0: Broker: Sending cloudlet 38 to VM #60.0: Broker: Sending cloudlet 39 to VM #732.0: Broker: Cloudlet 8 received32.0: Broker: Cloudlet 24 received32.0: Broker: Cloudlet 9 received32.0: Broker: Cloudlet 25

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论