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

下载本文档

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

文档简介

package org.cloudbus.cloudsim.examples;/* * 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 */【试验一:怎样创建一个含一台主机的数据中心,并在其上运行一个云任务】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;/* * A simple example showing how to create a datacenter with one host and run one * cloudlet on it. */public class CloudSimExample1 /* The cloudlet list. */ 【云任务列表】private static List cloudletList;/* The vmlist. */ 【虚拟机列表】private static List vmlist;/* * Creates main() to run this example. * * param args the args */ 【主函数运行实例】public static void main(String args) Log.printLine(Starting CloudSimExample1.); 【实验结果输出】try / First step: Initialize the CloudSim package. It should be called 【初始化工具包】/ before creating any entities. int num_user = 1; / number of cloud usersCalendar 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 【创建数据中心】/ Datacenters are the resource providers in CloudSim. We need at/ list one of them to run a CloudSim simulationDatacenter datacenter0 = createDatacenter(Datacenter_0);/ Third step: Create Broker 【创建代理】DatacenterBroker broker = createBroker();int brokerId = broker.getId();/ Fourth step: Create one virtual machine 【创建一个虚拟机】vmlist = new ArrayList();/ VM description 【虚拟机参数】int vmid = 0;int mips = 1000;long size = 10000; / image size (MB)int ram = 512; / vm memory (MB)long bw = 1000;int pesNumber = 1; / number of cpusString vmm = Xen; / VMM name/ create VM 【虚拟机创建】Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared();/ add the VM to the vmList 【加入虚拟机列表】vmlist.add(vm);/ submit vm list to the broker 【虚拟机列表提交给代理】broker.submitVmList(vmlist);/ Fifth step: Create one Cloudlet 【创建一个云任务】cloudletList = new ArrayList();/ Cloudlet properties 【云任务参数】int id = 0;long length = 400000;long fileSize = 300;long outputSize = 300;UtilizationModel utilizationModel = new UtilizationModelFull();【getUtilization()函数 :输入具体时间参数 返回类型是计算资源的利用百分比】Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);cloudlet.setUserId(brokerId);cloudlet.setVmId(vmid);/ add the cloudlet to the list 【云任务加入列表】cloudletList.add(cloudlet);/ submit cloudlet list to the broker 【云任务列表提交给代理】broker.submitCloudletList(cloudletList);/ Sixth step: Starts the simulation 【开始仿真】CloudSim.startSimulation();CloudSim.stopSimulation();/Final step: Print results when simulation is over 【仿真结束 打印结果】List newList = broker.getCloudletReceivedList();printCloudletList(newList);/ Print the debt of each user to each datacenter 【打印账单】datacenter0.printDebts();Log.printLine(CloudSimExample1 finished!); catch (Exception e) 【Java Exception 异常处理机制】e.printStackTrace();Log.printLine(Unwanted errors happen);/* * Creates the datacenter. * * param name the name * * return the datacenter */ 【创建数据中心】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 hostList = new ArrayList();/ 2. A Machine contains one or more PEs or CPUs/Cores. 【一个机器含有的处理器】/ In this example, it will have only one core.List peList = new ArrayList();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 storageint bw = 10000;hostList.add(new Host(hostId,new RamProvisionerSimple(ram),new BwProvisionerSimple(bw),storage,peList,new VmSchedulerTimeShared(peList) 【虚拟机时间共享】); / This is our 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 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.001; / the cost of using storage in this/ resourcedouble costPerBw = 0.0; / 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 scenario/* * Creates the broker. * * return the datacenter broker */private 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 + 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 CloudSimExample1.Initialising.Starting CloudSim version 2.0Datacenter_0 is starting.Broker is starting.

温馨提示

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

评论

0/150

提交评论