云计算仿真工具CloudSim介绍和使用

合集下载

CloudSim学习

CloudSim学习
CloudSim 学习
2009年4月8日,澳大利亚墨尔本大学的网格实验室和Gridbus项目宣布推出 云计算仿真软件,称为CloudSim。它是在离散事件模拟包SimJava上开发的函 数库,可在Windows和Linux系统上跨平台运行,CloudSim继承了GridSim的编 程模型,支持云计算的研究和开发,并提供了以下新的特点:
⑴支持大规模的云计算环境的模拟与仿真,包括数据中心,单一物理计算节 点;
⑵为模拟云、服务代理、供应、分配策略提供独立的平台; ⑶支持在模拟系统元素间仿真网络连接; ⑷具有在联合的云环境下仿真的功能,私有和公共领域的混合网络资源,对 有关 Cloud-Bursts 和自动应用伸缩的关键功能的研究。 CloudSim 是在 GridSim 模型基础上发展而来,提供了云计算的特性,支持 云计算的资源管理和调度模拟。云计算与网格计算的一个显著区别是云计算采用 了成熟的虚拟化技术,将数据中心的资源虚拟化为资源池,打包对外向用户提供 服务,CloudSim 体现了此特点,扩展部分实现了一系列接口,提供基于数据中 心的虚拟化技术、虚拟化云的建模和仿真功能。通常,数据中心的一台主机的资 源可以根据用户的需求映射到多台虚拟机上,因此,虚拟机之间存在对主机资源 的竞争关系。CloudSim 提供了资源的监测、主机到虚拟机的映射功能。CloudSim 的 CIS(Cloud Information Service)和 DataCenterBroker 实现资源发现和信息 交互,是模拟调度的核心。用户自行开发的调度算法可在 DataCenterBroker 的 方法中实现,从而实现调度算法的模拟。
(7) 在仿真结束后统计结果 List<Cloudlet> newList = broker.getCloudletReceivedList(); CloudSim.stopSimulation(); printCloudletList(newList); datacenter0.printDebts();

CloudSim 云计算模拟环境使用说明

CloudSim 云计算模拟环境使用说明

CloudSim:一个模拟与仿真云计算环境和评估资源调度算法的工具集Rodrigo N. Calheiros1, 3, Rajiv Ranjan2, Anton Beloglazov1, César A. F. DeRose3,andRajkumar Buyya11 Cloud Computing and D istributed S ystems (CLOUDS) LaboratoryDepartment of Computer Science and Software EngineeringThe University of Melbourne, Australia2 School of Computer Science and EngineeringThe University of New South Wales, Sydney, Australia3Department of Computer SciencePontifical Catholic University of Rio Grande do SulPorto Alegre, BrazilEmail:rncalheiros@,rajiv@.au,cesar.derose@pucrs.br,{abe,raj}@csse.unime.au摘要:近两年来,云计算技术取得很大进步,它是一种基于使用付款模式将计算机基础设施和应用作为服务提供给终端用户。

云计算可以根据时间变化权衡虚拟服务即使处于多条件需求(工作负载模式和QoS)。

云计算模式下的应用服务有复杂的供应、组成、配置和部署条件。

当系统和用户配置和需求处于动态变化的条件下,评估云供应政策、应用工作负载模式和资源性能模式的性能是很难实现的。

为了克服这一挑战,我们提出了云仿真平台cloudsim:一个可伸缩的仿真工具集可实现云计算系统和应用供应环境的模拟与仿真。

Cloudsim都支持云计算系统组件的系统和行为建模,例如数据中心,虚拟机和资源调度策略等。

云计算仿真工具CloudSim的研究与应用

云计算仿真工具CloudSim的研究与应用

云计算仿真工具CloudSim的研究与应用摘要云计算仿真工具CloudSim是一种用于模拟云计算环境的工具,它可以帮助研究人员和开发者预测云计算的性能和行为,从而评估不同的云计算策略。

本文首先介绍了CloudSim的基本原理与结构,然后探讨了CloudSim的主要应用场景、常见模拟实验和评估指标。

接着,本文进行了对CloudSim进行实验仿真的案例分析,进一步阐述了CloudSim的使用方法和实验效果。

最后,本文讨论了CloudSim的未来发展方向,包括针对新型云计算场景的改进和拓展以及与其他仿真工具的结合。

关键词:云计算,仿真工具,CloudSim,应用场景,实验仿真,性能评估AbstractCloudSim is a simulation tool used to model cloud computing environments. It enables researchers and developers to predict the performance and behavior of cloud computing systems, and evaluate different cloud computing strategies. This paper first introduces the basic principles andstructure of CloudSim, and then explores its main application scenarios, common simulation experiments, and evaluation metrics. Next, this paper analyzes a case study of CloudSim simulation experiments, further elaborating on the usage and performance of CloudSim. Finally, this paper discusses the future development direction of CloudSim, including improvements and extensions for new cloud computing scenarios, and integration with other simulation tools.Keywords: cloud computing, simulation tool, CloudSim, application scenario, simulation experiment, performanceevaluation引言随着云计算技术的逐步成熟,云计算已经越来越成为企业和组织的首选技术之一。

云计算仿真平台CloudSim在资源分配研究中的应用

云计算仿真平台CloudSim在资源分配研究中的应用

云计算仿真平台CloudSim在资源分配研究中的应用摘要:针对云计算环境的复杂性和资源分配的不确定性,评价云资源的调度分配策略、应用的工作负载都很难实现,墨尔本大学的学者提出的云计算仿真平台CloudSim,可以实现云计算系统的模拟和实验。

对ClouSim的体系结构、开发流程进行了研究,在ClouSim平台下实现了云计算资源分配MinMin算法的仿真,并将仿真结果与Round Robin算法进行比较。

结果表明,MinMin算法的任务最短执行时间和负载平衡性能均优于Round Robin算法。

关键词:云计算;Cloudsim;资源分配;MinMin算法云计算作为下一代数据中心,其目的是将有效的、可扩展的基础设施(Infrastructure as a Service,简称IaaS)、应用平台(Platform as a Service,简称PaaS)和应用软件(Software as a Service,简称SaaS)作为服务以按需付费的方式提供给用户,实现资源的动态、灵活应用。

云计算模式下的应用服务都有复杂的组件、配置和部署条件,当系统配置和用户需求处于动态变化的情况下,评价云资源的调度分配策略、应用的工作负载模式和资源性能模式的性能是很难实现的。

为解决此问题,墨尔本大学Rajkumar Buyya等学者提出了云仿真平台CloudSim,用以实现云计算系统和应用资源调度的模拟与仿真。

1 云计算1.1 云计算的概念2009年伯克利的M. Armbrust等学者在一份报告中指出:“云计算,计算作为工具的长期战略很有可能改变大多数的IT产业,使得软件成为更具吸引力的服务”。

云计算的目的是通过架构下一代数据中心作为虚拟服务的硬件和软件设施,使用户能从世界的任何地方获得和部署应用程序。

云计算是由分布式处理(Distributed Computing)、并行处理(Parallel Computing)和网格计算(Grid Computing)演进发展,并在商业上实现的计算机概念,其本质是数据共享计算模式与服务共享计算模式的结合体,是下一代计算模式的发展方向。

云计算仿真工具CloudSim的研究与应用

云计算仿真工具CloudSim的研究与应用

云计算仿真工具CloudSim的研究与应用作者:何婧媛来源:《科技资讯》2016年第02期摘要:分析云计算仿真工具CloudSim的体系结构、核心类库和仿真流程,通过在扩展后的CloudSim平台上对云任务调度算法进行仿真实验,验证了CloudSim进行云计算仿真实验的可行性。

关键词:云计算仿真工具 CloudSim中图分类号:TP302 文献标识码:A 文章编号:1672-3791(2016)01(b)-0000-00随着云计算技术和云服务的迅猛发展,急需寻求一种云计算环境下分布式系统模拟器实现云计算试验的模拟。

本文在分析云计算仿真工具CloudSim体系结构、核心类和仿真流程的基础上,对扩展和重编译的CloudSim进行了云任务调度算法的测试,并对结果进行了记录和分析,验证了CloudSim进行云计算仿真实验的可行性[1]。

1 CloudSim简介CloudSim是云计算技术出现后推出的一种通用性和可扩展性较好的云计算仿真软件,主要是对云环境下的资源分配以及服务调度来进行性能的测试和优化等研究,它的出现对云计算算法、方法和服务的发展都是十分有利的。

CloudSim体现了云计算中虚拟化技术,在扩展部分通过一系列接口来提供基于数据中心的虚拟化技术和虚拟化云的建模及仿真,同时还提供了资源的监测以及主机到虚拟机的映射 [2]。

CloudSim是一款开源软件,可运行在Windows系统和Linux系统上,还可以根据需要进行扩展,以满足不同用户的不同需求。

1.1 CloudSim体系结构CloudSim采用的是分层体系结构,CloudSim发展到今天的版本,主要由CloudSim核心模拟引擎、CloudSim和UserCode三层组成。

(1) CloudSim核心模拟引擎CloudSim模拟引擎包含以下一些类:CloudSim类、FutureQueueq类、DeferredQueue类、SimEvent类、SimEntity类、CloudSimTags类、CloudInformationService(CIS)类、CloudSimShutdown类.。

CloudSim云仿真器

CloudSim云仿真器

CloudSim云仿真器CloudSim云仿真器1.简介 CloudSim:通用的和可扩展的模拟框架,支持模拟新兴的云计算基础设施和管理服务。

有如下功能:支持建模和安装大规模云计算基础设施,包括在单一物理计算节点和java虚拟机上的数据中心。

可对数据中心,服务代理,调度和分配策略进行建模。

提供虚拟引擎,有助于在一个数据中心节点上创建和管理多个,独立和协同的虚拟服务。

可以灵活地在共享空间和共享时间分配的处理核心之间切换。

1.简介优点:基于模拟的方法允许用户反复测试他们的服务,而不需要大量资金耗费,并能够在部署之前调节性能瓶颈。

仿真器能够帮助服务提供者优化资源访问耗费以便提高收益。

利用现有的模拟库GridSim和SimJava来解决系统的底层需求。

比如,通过使用SimJa va,我们避免重新执行事件处理和组件之间的消息传送,这节省了许多软件工程和测试的时间。

2. CloudSim体系结构在体系结构上,CloudSim仿真器采用分层的结构,自底向上由SimJava,GridSim,CloudSim,用户代码四个层次组成SimJava最底层的是离散事件模拟引擎SimJava,它负责执行高层模拟框架的核心功能,比如:查询和处理事件,系统组件的创建(服务、客户端、数据中心、代理和虚拟机),在不同组件之间的通信,模拟时钟的管理。

GridSim在SimJava上面是GridSim,支持高层软件组件,建模多个网格基础设施,包括网络和网络流量文件,基础的网格组件诸如资源,数据集,负载测量和信息服务。

CloudSimCloudSim在下一层执行,它扩展由GridSim提供的核心功能。

CloudSim层提供对虚拟基于云的数据中心诸如VM,内存,存储和带宽等管理接口。

CloudSim层在模拟阶段管理核心实体(比如VM,客户端,数据中心,应用)的实例和执行。

这一层能够并发地实例化和透明地管理大规模云基础设施包括数以千计的系统组件。

CloudSim学习笔记

CloudSim学习笔记

CloudSim首要目标:在云计算基础设施上(软件、硬件、服务)上,对不同应用和服务模型的调度和分配策略的性能进行量化和比较。

Example oneA simple example showing how to create a datacenter with one host and run one cloudlet on it.静态数据:/** The cloudlet list.小云朵集合 */private static List<Cloudlet> cloudletList;/** The vmlist. 虚拟机集合*/private static List<Vm> vmlist;一、初始化云库: Initialize the CloudSim package. It should be called before creating any entities.int num_user = 1; // number of cloud users Calendar calendar = Calendar.getInstance(); boolean trace_flag = false; // mean trace events// Initialize the CloudSim libraryCloudSim.init(num_user,calendar,trace_flag) ;二、创建数据中心: Create Datacenters ,Datacenters are the resource providers in CloudSim. We need at list one of them to run a CloudSim simulation。

Datacenter datacenter0 =createDatacenter(“datacenter0”);三、创建中间代理:Create Broker ,同时获得代理ID DatacenterBroker broker = createBroker();int brokerId = broker.getId();四、// 创建一个虚拟机,并将虚拟机列表注册到中间代理上: Create one virtual machinevmlist = new ArrayList<Vm>();// VM descriptionint 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 VMVm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());// add the VM to the vmListvmlist.add(vm);// submit vm list to the brokerbroker.submitVmList(vmlist);五、创建一片云朵并将云列表注册到中间代理者上:Create one Cloudlet// Cloudlet propertiesint id = 0;long length = 400000;long fileSize = 300;long outputSize = 300;UtilizationModel utilizationModel = new UtilizationModelFull(); //使用模型Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, outputSize,utilizationModel, utilizationModel, utilizationModel);cloudlet.setUserId(brokerId);cloudlet.setVmId(vmid);// add the cloudlet to the listcloudletList.add(cloudlet);// submit cloudlet list to the broker broker.submitCloudletList(cloudletList);六、开始和停止仿真仿真: Starts the simulationCloudSim.startSimulation();CloudSim.stopSimulation();七、打印结果:Print results when simulation is overList<Cloudlet> newList =broker.getCloudletReceivedList(); printCloudletList(newList);关于如何创建数据中心private static DatacentercreateDatacenter(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 = newArrayList<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>();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 Host 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 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<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN devices by nowDatacenterCharacteristicscharacteristics = newDatacenterCharacteristics(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, newVmAllocationPolicySimple(hostList), storageList, 0);} catch (Exception e) {e.printStackTrace();}return datacenter; }。

CloudSim的学习和使用1

CloudSim的学习和使用1

CloudSim的学习和使⽤1⼀、认识CloudSim1.1 什么是CloudSimCloudSim: A Framework For Modeling And Simulation Of Cloud Computing Infrastructures And Services⼀个建模与仿真云计算基础设计和服务的框架。

1.2 去哪找CloudSim的资料序号类别备注1英⽂2英⽂3英⽂⼆、运⾏CloudSim样例2.1 下载CloudSim包去Github⽹站上下载。

2.2 运⾏⽰例代码解压CloudSim.zip包,并进⼊jars⽬录,打开cmd,执⾏:java -classpath jars\cloudsim-4.0.jar;examples org.cloudbus.cloudsim.examples.CloudSimExample1可以运⾏CloudSimExample1,运⾏结果如下图。

CloudSimExample1中的1可以改成1-8中任意数字即可运⾏对应⽰例程序,⽐如如下图运⾏⽰例代码4,下载的zip包中有⼀个examples.txt讲述了详细的使⽤⽅法,具体内容如下:Running the CloudSim examples-----------------------------To run the CloudSim examples you need to do the following steps.In Windows:1. cd <PATH TO CLOUDSIM PACKAGE>\jars2. java -classpath cloudsim-<VERSION>.jar;cloudsim-examples-<VERSION>.jar org.cloudbus.cloudsim.examples.CloudSimExample<EXAMPLE NUMBER> In Unix/Linux:1. cd <PATH TO CLOUDSIM PACKAGE>/jars2. java -classpath cloudsim-<VERSION>.jar:cloudsim-examples-<VERSION>.jar org.cloudbus.cloudsim.examples.CloudSimExample<EXAMPLE NUMBER> Where you need to replace:<PATH TO CLOUDSIM PACKAGE> - by the path to a directory where you have unpacked the CloudSim package<VERSION> - by the version of the downloaded CloudSim package<EXAMPLE NUMBER> - by the of number of the example you want to runCloudSim examples source code-----------------------------You can find the source code of the examples in <PATH TO CLOUDSIM PACKAGE>/examples/org/cloudbus/cloudsim/examples/Compiling and running examples------------------------------To compile and run an example (let's say org.cloudbus.cloudsim.examples.CloudSimExample1) you need to do the following steps:In Windows:1. cd <PATH TO CLOUDSIM PACKAGE>2. javac -classpath jars\cloudsim-<VERSION>.jar;examples examples\org\cloudbus\cloudsim\examples\CloudSimExample1.java3. java -classpath jars\cloudsim-<VERSION>.jar;examples org.cloudbus.cloudsim.examples.CloudSimExample1In Unix/Linux:1. cd <PATH TO CLOUDSIM PACKAGE>2. javac -classpath jars/cloudsim-<VERSION>.jar:examples examples/org/cloudbus/cloudsim/examples/CloudSimExample1.java3. java -classpath jars/cloudsim-<VERSION>.jar:examples org.cloudbus.cloudsim.examples.CloudSimExample1Compiling and running examples from the power package-----------------------------------------------------To compile and run an example (let's say org.cloudbus.cloudsim.examples.power.planetlab.LrMc) you need to do the following steps:In Windows:1. Download Michael Thomas Flanagan's Java Scientific Library from /~mflanaga/java/2. Copy flanagan.jar to <PATH TO CLOUDSIM PACKAGE>/jars/3. cd <PATH TO CLOUDSIM PACKAGE>4. javac -classpath jars\cloudsim-<VERSION>.jar;jars\flanagan.jar;examples examples\org\cloudbus\cloudsim\examples\power\planetlab\LrMc.java5. java -classpath jars\cloudsim-<VERSION>.jar;jars\flanagan.jar;examples org.cloudbus.cloudsim.examples.power.planetlab.LrMcIn Unix/Linux:1. cd <PATH TO CLOUDSIM PACKAGE>2. chmod +x ./install-flanagan.sh3. ./install-flanagan.jar4. javac -classpath jars/cloudsim-<VERSION>.jar:jars/flanagan.jar:examples examples/org/cloudbus/cloudsim/examples/power/planetlab/LrMc.java5. java -classpath jars/cloudsim-<VERSION>.jar:jars/flanagan.jar:examples org.cloudbus.cloudsim.examples.power.planetlab.LrMcDescription of the CloudSim examples------------------------------------Here is the description of what each example does:CloudSimExample1.java : shows how to create a datacenter with one host and run one cloudlet on it.CloudSimExample2.java : shows how to create a datacenter with one host and run two cloudlets on it.The cloudlets run in VMs with the same MIPS requirements. The cloudlets will take the sametime to complete the execution.CloudSimExample3.java : shows 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 differenttime to complete the execution depending on the requested VM performance.CloudSimExample4.java : shows how to create two datacenters with one host each and run two cloudlets on them.CloudSimExample5.java : shows how to create two datacenters with one host each and run cloudlets of two users on them. CloudSimExample6.java : shows how to create scalable simulations.CloudSimExample7.java : shows how to pause simulations.CloudSimExample8.java : shows how to add entities in run time.network: this package contains examples on how to run simulation with network simulation.power: this package contains examples on how to use CloudSim's power-aware features.三、修改⽰例代码测试3.1 下载带有源代码的zip包3.2 在eclipse中新建项⽬并导⼊cloudsim3.2 修改代码使其创建10个虚拟机并仿真具体代码如下: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 org.cloudbus.cloudsim.provisioners.BwProvisionerSimple; import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple; /*** 创建⼀个数据中⼼,10个虚拟主机,10个云任务在上⾯运⾏**/public class MyExample1 {/** 云任务列表. */private static List<Cloudlet> cloudletList;/** 虚拟机列表 */private static List<Vm> vmlist;/*** Creates main() to run this example.** @param args the args*/@SuppressWarnings("unused")public static void main(String[] args) {Log.printLine("开始仿真...");try {// First step: Initialize the CloudSim package. It should be called // before creating any entities.// 第⼀步,在创建任务实体之前实例化CloudSim包int num_user = 1; // 云⽤户的数量Calendar calendar = Calendar.getInstance();boolean trace_flag = false; // 是否跟踪事件// Initialize the CloudSim library// 实例化CloudSim库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 simulation// 第⼆部,创建数据中⼼,在CloudSim中数据中⼼是资源提供者, // 我们需要在他们之中运⾏仿真Datacenter 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>();// VM description// 虚拟机描述信息int vmid = 0; // 虚拟机IDint mips = 100; // 速率long size = 10000; // image size (MB) 镜像⼤⼩int ram = 512; // vm memory (MB) 虚拟机内存⼤⼩long bw = 1000; // 虚拟机带宽int pesNumber = 1; // number of cpus cpu数量String vmm = "Xen"; // VMM name 架构// Fifth step: Create one Cloudlet// 第五步,创建⼀个云任务列表cloudletList = new ArrayList<Cloudlet>();int CloudletId = 0;// FOR循环创建10个虚拟机for (int i = 0; i < 10; i++) {// VM descriptionvmid += 1;mips += 100;size = 1000; // image size (MB)ram = 512; // vm memory (MB)bw = 1000;pesNumber = 1; // number of cpusvmm = "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);// Cloudlet propertiesCloudletId += 1;long length = 400000;long fileSize = 300;long outputSize = 300;UtilizationModel utilizationModel = new UtilizationModelFull();// 实例化云任务Cloudlet cloudlet = new Cloudlet(CloudletId, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel); cloudlet.setUserId(brokerId);cloudlet.setVmId(vmid);// add the cloudlet to the list// 将云任务添加进列表cloudletList.add(cloudlet);}// submit vm list to the brokerbroker.submitVmList(vmlist);// submit cloudlet list to the brokerbroker.submitCloudletList(cloudletList);// Sixth step: Starts the simulationCloudSim.startSimulation();CloudSim.stopSimulation();//Final step: Print results when simulation is overList<Cloudlet> newList = broker.getCloudletReceivedList();printCloudletList(newList);Log.printLine("MAIN函数结束");} catch (Exception e) {e.printStackTrace();Log.printLine("不知道啥玩意错了");}}/*** 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<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>();int mips = 100000;// 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// 4. Create Host with its id and list of PEs and add them to the list// of machines// 实例化⼀个物理机器并放置进机器列表int hostId = 0;int ram = 20480; // 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 = 8.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<Storage> storageList = new LinkedList<Storage>(); // 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<Cloudlet> 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("成功");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()));}}}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

云计算仿真工具CloudSim介绍和使用
CloudSim介绍和使用
2009年4月8日,澳大利亚墨尔本大学的网格实验室和Gridbus项目宣布推出云计算仿真软件,称为CloudSim。

它是在离散事件模拟包SimJava上开发的函数库,可在Windows和Linux系统上跨平台运行,CloudSim继承了GridSim的编程模型,支持云计算的研究和开发,并提供了以下新的特点: (1)支持大型云计算的基础设施的建模与仿真;(2)一个自足的支持数据中心、服务代理人、调度和分配策略的平台。

其中CloudSim 独特功能有:一是提供虚拟化引擎,旨在数据中心节点上帮助建立和管理多重的、独立的、协同的的虚拟化服务;二是在对虚拟化服务分配处理核心时能够在时间共享和空间共享之间灵活切换。

CloudSim平台有助于加快云计算的算法、方法和规范的发展。

CloudSim的组件工具均为开源的。

CloudSim的软件结构框架和体系结构组件包括SimJava、GridSim、CloudSim、UserCode四个层次。

CloudSim是在GridSim模型基础上发展而来,提供了云计算的特性,支持云计算的资源管理和调度模拟。

云计算与网格计算的一个显著区别是云计算采用了成熟的虚拟化技术,将数据中心的资源虚拟化为资源池,打包对外向用户提供服务,CloudSim体现了此特点,扩展部分实现了一系列接口,提供基于数据中心的虚拟化技术、虚拟化云的建模和仿真功能。

通常,数据中心的一台主机的资源可以根据用户的需求映射到多台虚拟机上,因此,虚拟机之间存在对主机资源的竞争关系。

CloudSim提供了资源的监测、主机到虚拟机的映射功能。

CloudSim的CIS(Cloud Information Service)和DataCenterBroker实现资源发现和信息交互,是模拟调度的核心。

用户自行开发的调度算法可在DataCenterBroker的方法中实现,从而实现调度算法的模拟。

依据CloudSim源代码介绍几个核心类:
(1)Cloudlet类:构建云环境下的任务。

(2)DataCenter类:数据中心,提供虚拟化的网格资源,处理虚拟机信息的查询,包含虚拟机对资源的分配策略,云计算采用VMProvisioner处理虚拟机。

(3)DataCenterBroker类:隐藏了虚拟机的管理,如创建、任务提交、虚拟机的销毁等。

(4)Host类:扩展了机器对虚拟机除处理单元(PE)之外的参数分配策略,如带宽、存储空间、内存等,一台Host可对应多台虚拟机。

(5)VirtualMachine类:虚拟机类,运行在Host上,与其它虚拟机共享资源,每台虚拟机由一个拥有者所有,可提交任务,并由VMScheduler类定制该虚拟机的调度策略。

(6)VMScheduler类:虚拟机的调度策略,用来管理执行任务,实现了任务接口。

(7)VMCharacteristics类:提供虚拟机描述。

(8)VMMAllocationPolicy类:虚拟机监视器策略类,描述同一Host上的多台虚拟机共享资源的策略。

(9)VMProvisioner类:实现数据中心的主机到虚拟机的映射。

2、CloudSim环境配置
(1)JDK安装和配置
从/下载JDK最新版本jdk1.6.0_13,CloudSim需要运行在JDK1.6版本以上。

安装下载的JDK,设置环境变量。

在Path中加入路径:C:\Program
Files\Java\jdk1.6.0_13\bin; ClassPath中加入路径:C:\Program
Files\Java\jdk1.6.0_13\lib\dt.jar; C:\Program Files\Java\jdk1.6.0_13\lib\tools.jar; 。

(2)CloudSim配置
从/cloudsim/下载CloudSim 1.0 beta版,下载的是一个Zip包,解
压压缩包即可。

设置环境变量,在ClassPath中加入路径:C:\CLOUDSIM\jars\cloudsim.jar; C:\CLOUDSIM\jars\gridsim.jar; C:\CLOUDSIM\jars\simjava2.jar; 。

3、CloudSim的扩展
CloudSim是开源的,可以在windows Xp和linux上运行,用户可以根据自己的研究内容自行扩展CloudSim,加入自己的代码后,需要重新编译并发布平台。

下面给出编译和生成平台的方法:
从/下载Ant工具,解压到目录C:\apache-ant-1.7.1,设置环境变量,在PATH中加入:C:\apache-ant-1.7.1\bin;。

将命令行切换到扩展的CloudSim路径(build.xml 所在目录),在命令行下键入命令C:\CloudSim>ant,批量编译CloudSim源文件,生成的文件按照build.xml的设置存储到指定位置,编译成功后在命令行下键入D:\CloudSim>ant makejar命令打包生成new_cloudsim.jar。

扩展的CloudSim平台生成成功。

重设环境变量,在ClassPath 中增加路径:
C:\CloudSim\jars\new_cloudsim.jar;C:\CloudSim\jars\cloudsim.jar;C:\CloudSim\jars\g-r idsim.jar; C:\CloudSim\jars\simjava2.jar;,下一步在新的平台下编写自己的仿真验证程序。

4、使用CloudSim仿真的一般步骤
(1) 初始化GridSim 库
GridSim.init(num_user, calendar, trace_flag,
exclude_from_file,exclude_from_processing, report_name);
(2) 创建数据中心,在CloudSim仿真平台中,一个数据中心由一个或多个Machine组成,一个Machine是由一个或多个PEs或CPUs组成。

DataCenter datacenter0 = createDatacenter("Datacenter_0");
(3) 创建代理Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.get_id();
(4) 创建虚拟机
vmlist = new VirtualMachineList();
//创建时为虚拟机指定Broker
VirtualMachine vm1 = new VirtualMachine(
new VMCharacteristics(vmid,brokerId,size,memory,bw,vcpus,priority,vmm,
new TimeSharedVMScheduler()));
//将虚拟机加入虚拟机列表
vmlist.add(vm1);
//向相应代理Broker提交虚拟机列表
broker.submitVMList(vmlist);
(5) 创建云任务
cloudletList = new CloudletList();
//创建时指定任务的用户ID,BrokerID
Cloudlet cloudlet1 = new Cloudlet(id, length, file_size, output_size);
cloudlet1.setUserID(brokerId);
……
//将任务加入任务列表
cloudletList.add(cloudlet1);
……
//向代理Broker提交任务列表
broker.submitCloudletList(cloudletList);
(6) 启动仿真
GridSim.startGridSimulation();
(7) 在仿真结束后统计结果
CloudletList newList = broker.getCloudletList();
GridSim.stopGridSimulation();
printCloudletList(newList);
datacenter0.printDebts();
若是根据自己研究对平台进行了扩展,平台重生成后,就可以在仿真程序中调用自己编写的类、方法、成员变量等。

相关文档
最新文档