已阅读5页,还剩4页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * 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;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 two hosts and run two * cloudlets on it. The cloudlets run in * VMs with different MIPS requirements. * The cloudlets will take different time * to complete the execution depending on * the requested VM performance. */public class CloudSimExample3 /* The cloudlet list. */private static List cloudletList;/* The vmlist. */private static List vmlist;/* * Creates main() to run this example */public static void main(String args) Log.printLine(Starting CloudSimExample3.);try / First step: Initialize the CloudSim package. It should be called/ before creating any num_user = 1; / number of cloud usersCalendar calendar = Calendar.getInstance();boolean trace_flag = false; / mean trace events/ Initialize the CloudSim libraryCloudSim.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 BrokerDatacenterBroker broker = createBroker();int brokerId = broker.getId();/Fourth step: Create one virtual machinevmlist = new ArrayList();/VM descriptionint vmid = 0;int mips = 250;long size = 10000; /image size (MB)int ram = 2048; /vm memory (MB)long bw = 1000;int pesNumber = 1; /number of cpusString vmm = Xen; /VMM name/create two VMsVm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared();/the second VM will have twice the priority of VM1 and so will receive twice CPU timevmid+;Vm vm2 = new Vm(vmid, brokerId, mips * 2, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared();/add the VMs to the vmListvmlist.add(vm1);vmlist.add(vm2);/submit vm list to the brokerbroker.submitVmList(vmlist);/Fifth step: Create two CloudletscloudletList = new ArrayList();/Cloudlet propertiesint 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(brokerId);id+;Cloudlet cloudlet2 = new Cloudlet(id, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);cloudlet2.setUserId(brokerId);/add the cloudlets to the listcloudletList.add(cloudlet1);cloudletList.add(cloudlet2);/submit cloudlet list to the brokerbroker.submitCloudletList(cloudletList);/bind the cloudlets to the vms. This way, the broker/ will submit the bound cloudlets only to the specific VMbroker.bindCloudletToVm(cloudlet1.getCloudletId(),vm1.getId();broker.bindCloudletToVm(cloudlet2.getCloudletId(),vm2.getId();/ Sixth step: Starts the simulationCloudSim.startSimulation();/ Final step: Print results when simulation is overList newList = broker.getCloudletReceivedList();CloudSim.stopSimulation(); printCloudletList(newList);/Print the debt of each user to each datacenterdatacenter0.printDebts();Log.printLine(CloudSimExample3 finished!);catch (Exception e) e.printStackTrace();Log.printLine(The simulation has been terminated due to an unexpected error);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 machineList 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.peList.add(new Pe(0, new PeProvisionerSimple(mips); / need to store Pe id and MIPS Rating/4. Create Hosts with its id and list of PEs and add them to the list of machinesint 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 first machine/create another machine in the Data centerList peList2 = new ArrayList();peList2.add(new Pe(0, new PeProvisionerSimple(mips);hostId+;hostList.add( new Host( hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw), storage, peList2, new VmSchedulerTimeShared(peList2) ) ); / This is our second 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 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 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 st
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 13630-2026核电厂控制室设计
- GB/T 25446-2026油浸式非晶合金铁芯电力变压器技术参数和要求
- 校园健康课堂:传染病预防与控制课件详述
- 2026及未来5年中国三联塑料表箱市场现状数据分析及前景预测报告
- 2026及未来5年中国“至尊财神”发光雕塑市场现状数据分析及前景预测报告
- 2026及未来5年中国PE网纹膜市场现状数据分析及前景预测报告
- 秸秆颗粒加工基地可研报告
- 2026年高铁防护员模拟试题(含答案)
- 2026年国际税收模拟试卷(含答案)
- 2026年课堂讲座模拟题及答案详解
- 《半导体制备装置用超高纯净不锈钢管》
- 深基坑安全管理培训课件
- 学院 升本 实施方案
- 超声波探伤培训教材
- 2026年《三级物业管理师》考试模拟试题含答案
- T∕CPCPA 0017-2026 托育机构婴幼儿回应性照护服务规范
- 2026春季学期国开机电专科《可编程控制器应用实训》一平台在线形考形成任务1至6答案
- 人事考评课件
- 上海市上海中学2025-2026学年高一上学期期中考试语文试卷(含答案)
- 警营文化建设投标方案
- 重庆市2025年高考真题化学试卷(含答案)
评论
0/150
提交评论