国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Cloudsim入門

這篇具有很好參考價值的文章主要介紹了Cloudsim入門。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

如何使用cloudsim?

直接上github搜索cloudsim

Release cloudsim-3.0 · Cloudslab/cloudsim · GitHub

首先來個源代碼,這個是cloudsimexample1

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 datacenter with one host and run one
 * cloudlet on it.
 */
public class CloudSimExample1 {

	/** The cloudlet list. */
	private static List<Cloudlet> cloudletList;

	/** The vmlist. */
	private static List<Vm> 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 users
			Calendar 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 simulation
			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;
			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

			// 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();

			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<Cloudlet> newList = broker.getCloudletReceivedList();
			printCloudletList(newList);

			// Print the debt of each user to each datacenter
			datacenter0.printDebts();

			Log.printLine("CloudSimExample1 finished!");
		} catch (Exception e) {
			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<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 = 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 machines
		int hostId = 0;
		int ram = 2048; // host memory (MB)
		long storage = 1000000; // host storage
		int 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 architecture
		String os = "Linux"; // operating system
		String vmm = "Xen";
		double time_zone = 10.0; // time zone this resource located
		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. 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("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()));
			}
		}
	}

}

這個代碼的目的是創(chuàng)造一個主機,一個任務的數(shù)據(jù)中心

但是第一次看到這個肯定看的云里霧里的,下面就來先分析一下這些玩意是干什么的。

  • Datacenter,顧名思義就是數(shù)據(jù)中心

  • DatacenterBroker,這個是數(shù)據(jù)中心代理,負責云計算中根據(jù)用戶的qos要求協(xié)調(diào)用戶以及服務供應商,以后vm綁定數(shù)據(jù)中心,還有cloudlet綁定數(shù)據(jù)中心,以及vm綁定cloudlet都和這個broker有關(guān)

  • Cloudlet,這個是指令,有四個屬性

    int id = 0;就是指令的id
    long length = 40000;指令的長度
    long fileSize = 300;文件的大小
    long outputSize = 300;輸出的大小
    
  • UtilizationModel,在構(gòu)造cloudlet的時候,這個是必須的,是一個應用的模型

流程分析

Cloudsim入門

  1. 首先是cloudsim的初始化,需要三個參數(shù)CloudSim.init(num_user, calendar, trace_flag),分別是云用戶的數(shù)量,日期,還有是否跟蹤事件。

  2. 第二部開始構(gòu)建數(shù)據(jù)中心,這里的實例有一個代碼

    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來存放我們的主機
    		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>();
    //一個主機有多個pes或者是cpu
    //mips就是單位時間處理命令的量
    		int mips = 1000;
    
    		// 3. Create PEs and add these into a list.
    //創(chuàng)建pes并且加入到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 machines
    		int hostId = 0;
    		int ram = 2048; // host memory (MB)主機內(nèi)存
    		long storage = 1000000; // host storage應該是外存
    		int 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 architecture
    		String os = "Linux"; // operating system
    		String vmm = "Xen";
    		double time_zone = 10.0; // time zone this resource located
    		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. 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;
    	}
    
  3. 創(chuàng)建虛擬中心代理

  4. 創(chuàng)建虛擬機

  5. 創(chuàng)建云任務,設定任務數(shù)量

  6. 分配任務到虛擬機上

  7. 啟動仿真文章來源地址http://www.zghlxwxcb.cn/news/detail-452995.html

到了這里,關(guān)于Cloudsim入門的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務器費用

相關(guān)文章

  • GitHub必會小技巧,教你如何快速找到好項目,學編程必備_github搜索項目技巧

    GitHub必會小技巧,教你如何快速找到好項目,學編程必備_github搜索項目技巧

    學編程跟代碼打交道,如果你不會使用GitHub,你可能需要回爐重造了。很多新手還沒有認識到GitHub的強大,不管是學習、畢設和工作,都能在上面找到很多好用的項目資源。 但是找項目一直都是新手的最頭疼的問題,尤其是盲搜項目,那就更難了。那么今天, 教大家?guī)讉€G

    2024年04月17日
    瀏覽(17)
  • 如何從github拉取代碼(入門篇)

    一、安裝 Git: Git 可以在多種操作系統(tǒng)上使用,包括 Windows、macOS 和 Linux。以下是在 Windows 上安裝 Git 的步驟: 訪問 Git 的官方網(wǎng)站 https://git-scm.com/downloads。 在網(wǎng)站上選擇適合你的操作系統(tǒng)版本的 Git 安裝程序。 下載安裝程序并運行。 在安裝程序的向?qū)е羞x擇默認選項,直到

    2024年02月13日
    瀏覽(19)
  • github注冊,入門及如何提交代碼(圖形化界面方式)

    github注冊,入門及如何提交代碼(圖形化界面方式)

    GitHub是一個代碼托管網(wǎng)站 全球最大的同性交友網(wǎng)站 ,你可以在網(wǎng)站上創(chuàng)建代碼倉庫。當你寫代碼時,你可以把你的代碼托管到各個代碼倉庫里去,可以設置私有/公有屬性。 GitHub上有成千上萬開源項目,他們愿意將代碼公開,其他人可以去改造代碼,并將改造的成果貢獻出來

    2024年02月08日
    瀏覽(21)
  • GitHub的使用(入門)

    GitHub的使用(入門)

    本文參考和部分圖片來源如何上傳代碼到github?,但本地操作與其不同 Git Bash的復制快捷鍵為ctrl+insert,粘貼快捷鍵為:shift+insert 官網(wǎng)下載地址:Git - Downloads ,選擇windows版本,默認的版本是windows 64;也點擊“Older releases”選擇與系統(tǒng)匹配的版本進行下載(32bit/64bit) 安裝步驟可

    2023年04月08日
    瀏覽(12)
  • GitHub入門指南:一步一步教你使用GitHub

    GitHub入門指南:一步一步教你使用GitHub

    引言: GitHub是一個流行的代碼托管平臺,它提供了強大的版本控制和協(xié)作功能,對于開發(fā)者來說是一個不可或缺的工具。本文將一步一步地教你如何使用GitHub,從注冊賬號到代碼同步,讓你能夠快速上手并充分利用這個平臺。 打開GitHub官網(wǎng)(github.com)。 點擊右上角的\\\"Sign

    2024年02月15日
    瀏覽(22)
  • Github基礎入門(2):github打不開?保姆級教程教你流暢使用GIthub

    Github基礎入門(2):github打不開?保姆級教程教你流暢使用GIthub

    ?上篇帖子簡單介紹了git,github及其注冊,今天想寫如何解決github打不開的問題。 在網(wǎng)址github后面加一個fast即可 例, 原網(wǎng)址:https://github.com/... 現(xiàn)在:https://github fast .com/... watt toolkit可以加速github的訪問服務。 可以去官網(wǎng),可以直接去微軟商店搜索:watt toolkit 打開后,選擇下

    2024年01月19日
    瀏覽(28)
  • 全文搜索引擎 Elasticsearch 入門使用

    目錄 1、安裝 2、基本概念 2.1 Node 與 Cluster 2.2 Index 2.3 Document? 2.4 Type 3、新建和刪除 Index 4、中文分詞設置? 5、數(shù)據(jù)操作? 5.1 新增記錄? 5.2 查看記錄? ?5.3 刪除記錄 5.4 更新記錄? 6、數(shù)據(jù)查詢 6.1 返回所有記錄 6.2 全文搜索 ?6.3 邏輯運算 7、參考鏈接 本文從零開始,講解如何

    2024年02月09日
    瀏覽(20)
  • 【超簡單】一文入門在Ubuntu系統(tǒng)使用GitHub

    【超簡單】一文入門在Ubuntu系統(tǒng)使用GitHub

    【大家好,我是編程的賽賽,專注于保姆級代碼教程】 總覽 ?????? Github是基于git的代碼倉庫,對于開發(fā)項目的科研者或者工程師,代碼倉庫都是不可多得的版本控制與多端編程工具,今天這篇文章帶你輕松Github入門,簡單的項目本文的操作足矣。 ??????? 當然,國內(nèi)用

    2024年02月08日
    瀏覽(15)
  • 快速入門:使用 Gemini Embeddings 和 Elasticsearch 進行向量搜索

    快速入門:使用 Gemini Embeddings 和 Elasticsearch 進行向量搜索

    Gemini 是 Google DeepMind 開發(fā)的多模態(tài)大語言模型家族,作為 LaMDA 和 PaLM 2 的后繼者。由 Gemini Ultra、Gemini Pro 和 Gemini Nano 組成,于 2023 年 12 月 6 日發(fā)布,定位為 OpenAI 的競爭者 GPT-4。 本教程演示如何使用 Gemini API 創(chuàng)建嵌入并將其存儲在 Elasticsearch 中。 Elasticsearch 將使我們能夠執(zhí)

    2024年01月21日
    瀏覽(25)
  • Github Desktop 下載、安裝、漢化和卸載(新手入門使用教程)

    Github Desktop 下載、安裝、漢化和卸載(新手入門使用教程)

    打開GitHub Desktop官網(wǎng)https://desktop.github.com/ 點擊 download for Windows(64bit),下載 GitHub Desktop 啟動安裝 雙擊下載好的安裝包,啟動安裝 安裝進度 顯示安裝進度頁面,稍微耐心等等,頁面消失即安裝完成 GithubDesktopZhTool為GitHubDesktop漢化工具。 注:遇到漢化失敗,重試一下子。 意

    2024年04月17日
    瀏覽(23)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包