CloudSim仿真流程研究(二)[通俗易懂]

CloudSim仿真流程研究(二)[通俗易懂]org.cloudbus.cloudsim.examples.power.random里的例子IqrMc:publicclassIqrMc{ /** *Themainmethod. * *@paramargsthearguments *@throwsIOExceptionSignalsthatanI/Oexceptionhasocc…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

org.cloudbus.cloudsim.examples.power.random里的例子IqrMc

public class IqrMc {

	/**
	 * The main method.
	 * 
	 * @param args the arguments
	 * @throws IOException Signals that an I/O exception has occurred.
	 */
	public static void main(String[] args) throws IOException {
		boolean enableOutput = true;
		boolean outputToFile = true;
		String inputFolder = "";
		String outputFolder = "C:\\Users\\yangdi\\Desktop\\cloudsim_data";
		String workload = "random"; // Random workload
		String vmAllocationPolicy = "iqr"; // Inter Quartile Range (IQR) VM allocation policy
		String vmSelectionPolicy = "mc"; // Maximum Correlation (MC) VM selection policy
		String parameter = "1.5"; // the safety parameter of the IQR policy
		
		new RandomRunner(
				enableOutput,
				outputToFile,
				inputFolder,
				outputFolder,
				workload,
				vmAllocationPolicy,
				vmSelectionPolicy,
				parameter);
	}

}

运行类在类RandomRunner中,该类继承于RunnerAbstract类,并且直重写了一个方法:init()

protected void init(String inputFolder) {
		try {
			CloudSim.init(1, Calendar.getInstance(), false);

			broker = Helper.createBroker();
			int brokerId = broker.getId();

			cloudletList = RandomHelper.createCloudletList(brokerId, RandomConstants.NUMBER_OF_VMS);
			vmList = Helper.createVmList(brokerId, cloudletList.size());
			hostList = Helper.createHostList(RandomConstants.NUMBER_OF_HOSTS);
		} catch (Exception e) {
			e.printStackTrace();
			Log.printLine("The simulation has been terminated due to an unexpected error");
			System.exit(0);
		}
	}

该方法中Cloudlet是随即创建的,使用的是RandomHelper里的createCloudletList()方法,在里面创建Cloudlet:

cloudlet = new Cloudlet(
    i,
    Constants.CLOUDLET_LENGTH,
    Constants.CLOUDLET_PES,
    fileSize,
    outputSize,
    new UtilizationModelStochastic(),
    utilizationModelNull,  
    utilizationModelNull
    // new UtilizationModelStochastic(),
    // new UtilizationModelStochastic()
);

本来自带的Cloudlet中传入的CPU使用率模型,RAM使用率模型,和BW使用率模型,这个暂时不用去管,因为其本身自己就有简单的随机模型。之后的仿真流程跟前一篇一样。之后研究在Planetlab的工作流或者随机cloudlet的工作流之下其CPU利用率,RAM利用率,Bw利用率和Storage利用率。

利用率这一段日志的输出在powerDatacenter类中(节取):

protected double updateCloudetProcessingWithoutSchedulingFutureEventsForce() {
		double currentTime = CloudSim.clock();
		double minTime = Double.MAX_VALUE;
		double timeDiff = currentTime - getLastProcessTime();
		double timeFrameDatacenterEnergy = 0.0;

		Log.printLine("\n\n--------------------------------------------------------------\n\n");
		Log.formatLine("New resource usage for the time frame starting at %.2f:", currentTime);

		for (PowerHost host : this.<PowerHost> getHostList()) {
			Log.printLine();

			double time = host.updateVmsProcessing(currentTime); // inform VMs to update processing
			if (time < minTime) {
				minTime = time;
			}

			Log.formatLine(
					"%.2f: [Host #%d] utilization is %.2f%%",
					currentTime,
					host.getId(),
					host.getUtilizationOfCpu() * 100);

其本身自带的只有CPU的利用率,所以需要去添加其他的利用率输出代码:

Log.formatLine(
    "%.2f: [Host #%d] utilization of RAM is %.2f%%",
    currentTime,
    host.getId(),
    host.getUtilizationOfRam() * 100);
			
Log.formatLine(
    "%.2f: [Host #%d] utilization of bw is %.2f%%",
    currentTime,
    host.getId(),
    host.getUtilizationOfBw() * 100);
			
Log.formatLine(
    "%.2f: [Host #%d] utilization of storge is %.2f%%",
    currentTime,
    host.getId(),
    host.getUtilizationOfStorage() * 100);

这之中的getUtilizationOfRam()和getUtilizationOfBw()方法在类HostDynamicWorkload中。但其本身的代码有点错误,名字是获取Ram的使用率,但是代码却是:

public double getUtilizationOfRam() {
		return getRamProvisioner().getUsedRam();  //这里有点错误,这里返回的是使用的Ram,而不是
	}

之后我稍微改写了一下,改成了利用率:

public double getUtilizationOfRam() {
		// return getRamProvisioner().getUsedRam();  //这里有点错误,这里返回的是使用的Ram,而不是使用率
		double result = (double)getRamProvisioner().getUsedRam() / (double)getRamProvisioner().getRam();
		return result;
	}

Bw的利用率同理,但是这个类里没有storage的利用率,需要自己去写,所以我在这个类的父类Host里去写,因为HostDynamicWorkload类里面没有Host所带的vmlist,vmlist在Host类中是private修饰的成员变量,无法被子类调用,我也不敢把它改成publiic什么的,所以我把storage的利用率写在Host类中:

/**
	 * Gets the utilization of Storage(in absolute values).
	 * @return
	 */
	public double getUtilizationOfStorage() {
		double result = (double)getUsedStorage() / (double)getStorage();
		return result;
	}

	/**
	 * Gets the host Used stroge.
	 */
	public long getUsedStorage() {
		long usedStorage = 0;
		for(Vm vm : vmList) {
			usedStorage += vm.getSize();
		}
		return usedStorage;
	}

之后运行程序,但是发现只有在第一个时钟时间的时候正常显示了利用率,在之后的所有时钟时间内,Ram利用率跟Bw利用率的使用率都是0.0%,这个至今没搞清楚什么原因。之后我将HostDynamicWorkload中的Ram利用率跟Bw利用率注释掉,在Host类中重新写了一下代码,不从ramProvisioner中获取主机的已经使用的usedRam,而是通过Host类中的vmlist成员变量来获取已经被使用的usedRam,Bw同理:

/**
	 * Gets the utilization of ram (in absolute values).
	 * 
	 * @return the utilization of ram
	 */
	public double getUtilizationOfRam() {
		double result = (double)getUsedRam() / (double)getRam();
		return result;
	}
	
	/**
	 * Gets the host Used Bw.
	 */
	public long getUsedRam() {
		long usedRam = 0;
		for(Vm vm : vmList) {
			usedRam += vm.getRam();
		}
		return usedRam;
	}
/**
	 * Gets the utilization of bw (in absolute values).
	 * 
	 * @return the utilization of bw
	 */
	public double getUtilizationOfBw() {
		double result = (double)getUsedBw() / (double)getBw();
		return result;
	}
	
	/**
	 * Gets the host Used Bw.
	 */
	public long getUsedBw() {
		long usedBw = 0;
		for(Vm vm : vmList) {
			usedBw += vm.getBw();
		}
		return usedBw;
	}

之后运行程序,就能在每个时钟时间正确的打印出结果:

CloudSim仿真流程研究(二)[通俗易懂]

不同时钟时刻的例子:

CloudSim仿真流程研究(二)[通俗易懂]

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182478.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 双线性插值(Bilinear Interpol)原理及应用

    双线性插值(Bilinear Interpol)原理及应用在很多神经网络上采样过程中会用到双线性插值,其为基础的图像resize操作。以前一直没时间仔细研究,今天探究并记录一下原理和自己的理解。一、什么是插值插值指两个方面:一是在数学上,在离散数据的基础上补插连续函数,使得这条连续曲线通过全部给定的离散数据点;二是在图像处理上面,是利用已知邻近像素点的灰度值或RGB中的三色值产生未知像素点的灰度值或RGB三色值,目的是由原始图像再生出具有更高分辨率的图像。通俗一点理解就是已知推导未知,从而强化图像,具体效果如图1所示。…

    2022年6月1日
    63
  • cmd批处理命令~%dp0与~%dpn1的解析

    cmd批处理命令~%dp0与~%dpn1的解析1、最简单的做法是在cmd命令输入:for/?,回车,就能看到详细的解析对一组文件中的每一个文件执行某个特定命令。FOR%variableIN(set)DOcommand[command-parameters]%variable指定一个单一字母可替换的参数。(set)指定一个或一组文件。可以使用通配符。command指定对每个文件执行的命令。…

    2022年9月16日
    0
  • Mac下利用Anaconda安装Opencv「建议收藏」

    Mac下利用Anaconda安装Opencv「建议收藏」打开Anaconda,选择Environments,打开需要安装环境的终端输入以下代码sudopipinstallopencv-python-ihttps://pypi.tuna.tsinghua.edu.cn/simple记住命令前加sudo,否则会报错填写密码后即可安装验证安装是否成功方法1importcv2没错报错就表明安装成功方法2condalist找到opencv库则表明安装成功!!Reference添加链接描述添加链接描述…

    2022年8月30日
    0
  • 硕士论文计算机要求,计算机硕士论文格式要求

    硕士论文计算机要求,计算机硕士论文格式要求

    2021年11月27日
    47
  • pycharmimport时找不到指定文件_pycharm系统找不到指定文件

    pycharmimport时找不到指定文件_pycharm系统找不到指定文件1、现象系统提示找不到指定的文件:Errorrunning’hello’:Cannotrunprogram"B:\pystudy\venv\Scripts\python.exe"(indirectory"\python-study"):CreateProcesserror=2,系统找不到指定的文件。2、原因原来的工程目录(B盘)下,保存了python的编…

    2022年8月28日
    13
  • jedis 集群_iis配置api

    jedis 集群_iis配置api项目中会常用到redis,但JedisCluster的使用api还是比较多,经常可能会记不太清楚,故这里将大部分JedisCluster的api贴出来,供大家参考。一、redis在工作是一个常见的工具,这里对redis和springboot形成集群的使用。(1)引入对应redis集群所需要maven文件<dependency><groupId&g…

    2022年10月14日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号