1、Cloudsim和Workflowsim仿真环境下载

1、WorkflowSim的下载和安装

workflowsim下载地址

2、Cloudsim的下载和安装

cloudsim官网
在这里插入图片描述
cloudsim4.0安装包地址
在这里插入图片描述
在这里插入图片描述

3、Cloudsim如何工作

Cloudsim如何工作?原版内容
cloudsim配置
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
下面这是CloudsimExamples1的代码:

package org.cloudbus.cloudsim.examples;

/*
 * Title:        CloudSim Toolkit
 * Description:  CloudSim (Cloud Simulation) Toolkit for Modeling and Simulation
 *               of Clouds
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 *
 * Copyright (c) 2009, The University of Melbourne, Australia
 */

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;

/**
    A simple example showing how to create a data center with one host and run one cloudlet on it.
 	演示如何使用一台主机创建一个数据中心并在其上运行一个cloudlet。
 	ContainerCloudSimExample1模拟了如何使用一台主机、一台VM、一个容器创建一个数据中心,并在其上运行一个云任务
 	ContainerCloudSimExample1为例,可将仿真流程分成三个阶段:初始化仿真环境,执行仿真,结束仿真,从这三个阶段对容器编程进行了解。
 */
public class CloudSimExample1 {
	// 云任务列表
	private static List<Cloudlet> cloudletList;
	// 虚拟机列表
	private static List<Vm> vmlist;

	public static void main(String[] args) {
		Log.printLine("Starting CloudSimExample1...");

		try {
			// 在创建任何实体类之前,必须初始化CloudSim包

			// 云用户数量
			int num_user = 1;
			// 日历的字段已使用当前日期和时间初始化
			Calendar calendar = Calendar.getInstance();
 			// 跟踪事件
			boolean trace_flag = false; // trace events

			// 第一步:初始化CloudSim工具包。num_user(云用户数量),calendar(日历), trace_flag(标志位)。
			CloudSim.init(num_user, calendar, trace_flag);

			// 第二步:创建数据中心。数据中心是cloudSim 的资源提供者、需要列出其中一个来运行CloudSim模拟
			Datacenter datacenter0 = createDatacenter("Datacenter_0");

			// 第三步:创建代理
			DatacenterBroker broker = createBroker();
			int brokerId = broker.getId();

			// 第四步:创建虚拟机列表
			vmlist = new ArrayList<Vm>();

			// 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 cpus
			String vmm = "Xen"; // VMM name

			// 创建虚拟机
			Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());

			// 将创建的虚拟机添加到虚拟机列表
			vmlist.add(vm);

			// 将创建的vm提交给代理
			broker.submitVmList(vmlist);

			// 第四步:创建一个 cloudlet云任务列表
			cloudletList = new ArrayList<Cloudlet>();

			// 云任务资源
			int id = 0;
			long length = 400000;
			long fileSize = 300;
			long outputSize = 300;
			// 为了提供细粒度的控制,需要实现utilzationmodel接口Cloudlet的资源使用情况。
			UtilizationModel utilizationModel = new UtilizationModelFull();

			Cloudlet cloudlet = 
                                new Cloudlet(id, length, pesNumber, fileSize, 
                                        outputSize, utilizationModel, utilizationModel, 
                                        utilizationModel);
			cloudlet.setUserId(brokerId);
			cloudlet.setVmId(vmid);

			// 将云任务添加到列表中
			cloudletList.add(cloudlet);

			// 将云任务列表提交给代理
			broker.submitCloudletList(cloudletList);

			// 第六步:开始模拟、结束模拟
			CloudSim.startSimulation();

			CloudSim.stopSimulation();

			//最后一步:模拟结束时打印结果
			List<Cloudlet> newList = broker.getCloudletReceivedList();
			printCloudletList(newList);

			Log.printLine("CloudSimExample1 finished!");
		} catch (Exception e) {
			e.printStackTrace();
			Log.printLine("Unwanted errors happen");
		}
	}

	// 创建数据中心
	private static Datacenter createDatacenter(String name) {


		// 1. 定义一个主机列表去存储我们的机器
		// our machine
		List<Host> hostList = new ArrayList<Host>();

		// 2. 创建主机包含的PE或者CPU处理器(核数)列表,定义为MIPS速率
		// 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. 创建处理器,并添加到Pe列表中  Create PEs and add these into a list.
		peList.add(new Pe(0, new PeProvisionerSimple(mips))); // 需要Pe id 和 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 = 2048; // 主机内存 (MB)
		long storage = 1000000; // 主机的存储空间
		int bw = 10000;

		hostList.add(
			new Host(
				hostId,
				new RamProvisionerSimple(ram),// 内存提供者,为虚拟机提供内存// 内存分配策略
				new BwProvisionerSimple(bw),// 带宽提供者// 带宽分配策略
				storage,
				peList,
				new VmSchedulerTimeShared(peList)	// 时间共享的VM调度// 虚拟机间共享资源的实时调度策略// VMM对虚拟机间共享处理器资源的策略
			)
		); // This is our machine

		// 5. 创建存储数据中心属性的DatacenterCharacteristics对象:架构,操作系统,机器列表,
		// 分配策略:时间或空间共享,时区及其价格(G $ / Pe时间单位)。
		String arch = "x86"; // 系统架构
		String os = "Linux"; // 操作系统
		String vmm = "Xen";	// 虚拟机监视器
		double time_zone = 10.0; // 此资源所在的时区
		double cost = 3.0; // 处理器花费  the cost of using processing in this resource
		double costPerMem = 0.05; // 内存花费  the cost of using memory in this resource
		double costPerStorage = 0.001; // 存储花费  the cost of using storage in this resource
		double costPerBw = 0.0; // 带宽花费  the cost of using bw in this resource
		LinkedList<Storage> storageList = new LinkedList<Storage>(); // we are not adding SAN
													// devices by now

		DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
				arch, os, vmm, hostList, time_zone, cost, costPerMem,
				costPerStorage, costPerBw);

		// 6. 最后,我们需要创建一个PowerDatacenter对象。 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

	// 创建代理
	private static DatacenterBroker createBroker() {
		DatacenterBroker broker = null;
		try {
			broker = new DatacenterBroker("Broker");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return broker;
	}

	// 打印云任务对象
	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.getStatus() == 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()));
			}
		}
	}
}
开始CloudSimExample1……

初始化…

启动CloudSim 3.0版本

Datacenter_0正在启动…

经纪人开始…

实体开始。

0.0:代理:云资源列表收到1个资源

0.0:代理:试图在Datacenter_0中创建虚拟机#0

0.1:代理:已经在数据中心#2,主机#0中创建了虚拟机#0

0.1: Broker:VM #0发送cloudlet 0

40.1:代理:Cloudlet 0收到

4001: Broker:执行所有cloudlet。完成……

40.1:代理:破坏虚拟机#0

经纪人要关门了…

模拟:没有更多的未来事件

CloudInformationService:通知所有CloudSim实体关闭。

Datacenter_0正在关闭…

经纪人要关门了…

模拟完成。

模拟完成。
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值