|
| 1 | +/* |
| 2 | + * CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for |
| 3 | + * Modeling and Simulation of Cloud Computing Infrastructures and Services. |
| 4 | + * http://cloudsimplus.org |
| 5 | + * |
| 6 | + * Copyright (C) 2015-2021 Universidade da Beira Interior (UBI, Portugal) and |
| 7 | + * the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil). |
| 8 | + * |
| 9 | + * This file is part of CloudSim Plus. |
| 10 | + * |
| 11 | + * CloudSim Plus is free software: you can redistribute it and/or modify |
| 12 | + * it under the terms of the GNU General Public License as published by |
| 13 | + * the Free Software Foundation, either version 3 of the License, or |
| 14 | + * (at your option) any later version. |
| 15 | + * |
| 16 | + * CloudSim Plus is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU General Public License |
| 22 | + * along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>. |
| 23 | + */ |
| 24 | +package org.cloudsimplus.examples; |
| 25 | + |
| 26 | +import org.cloudsimplus.brokers.DatacenterBroker; |
| 27 | +import org.cloudsimplus.brokers.DatacenterBrokerSimple; |
| 28 | +import org.cloudsimplus.builders.tables.CloudletsTableBuilder; |
| 29 | +import org.cloudsimplus.cloudlets.Cloudlet; |
| 30 | +import org.cloudsimplus.cloudlets.CloudletSimple; |
| 31 | +import org.cloudsimplus.core.CloudSimPlus; |
| 32 | +import org.cloudsimplus.datacenters.Datacenter; |
| 33 | +import org.cloudsimplus.datacenters.DatacenterSimple; |
| 34 | +import org.cloudsimplus.hosts.Host; |
| 35 | +import org.cloudsimplus.hosts.HostSimple; |
| 36 | +import org.cloudsimplus.listeners.VmHostEventInfo; |
| 37 | +import org.cloudsimplus.resources.Pe; |
| 38 | +import org.cloudsimplus.resources.PeSimple; |
| 39 | +import org.cloudsimplus.utilizationmodels.BootModel; |
| 40 | +import org.cloudsimplus.utilizationmodels.UtilizationModel; |
| 41 | +import org.cloudsimplus.utilizationmodels.UtilizationModelDynamic; |
| 42 | +import org.cloudsimplus.vms.Vm; |
| 43 | +import org.cloudsimplus.vms.VmSimple; |
| 44 | + |
| 45 | +import java.util.ArrayList; |
| 46 | +import java.util.List; |
| 47 | + |
| 48 | +/** |
| 49 | + * An example showing how to define the time for VMs to boot up |
| 50 | + * and how the boot process will use resources. |
| 51 | + * |
| 52 | + * @author Manoel Campos da Silva Filho |
| 53 | + * @since CloudSim Plus 8.3.0 |
| 54 | + */ |
| 55 | +public class VmBootTimeAndOverheadExample { |
| 56 | + private static final int HOSTS = 1; |
| 57 | + private static final int HOST_PES = 8; |
| 58 | + private static final int HOST_MIPS = 1000; // Milion Instructions per Second (MIPS) |
| 59 | + private static final int HOST_RAM = 2048; //in Megabytes |
| 60 | + private static final long HOST_BW = 10_000; //in Megabits/s |
| 61 | + private static final long HOST_STORAGE = 1_000_000; //in Megabytes |
| 62 | + |
| 63 | + private static final int VMS = 2; |
| 64 | + private static final int VM_PES = 4; |
| 65 | + |
| 66 | + private static final int CLOUDLETS = 2; |
| 67 | + private static final int CLOUDLET_PES = 2; |
| 68 | + private static final int CLOUDLET_LENGTH = 10_000; // Milion Instructions (MI) |
| 69 | + |
| 70 | + /** |
| 71 | + * Defines the time (in seconds) each VM will take to boot up. |
| 72 | + */ |
| 73 | + private static final double VM_BOOT_DELAY = 5; |
| 74 | + |
| 75 | + /** |
| 76 | + * Defines the time (in seconds) each VM will take to shut down. |
| 77 | + */ |
| 78 | + private static final double VM_SHUTDOWN_DELAY = 2; |
| 79 | + private static final double SCHEDULING_INTERVAL = 1; |
| 80 | + |
| 81 | + private final CloudSimPlus simulation; |
| 82 | + private final DatacenterBroker broker0; |
| 83 | + private List<Vm> vmList; |
| 84 | + private List<Cloudlet> cloudletList; |
| 85 | + private Datacenter datacenter0; |
| 86 | + |
| 87 | + public static void main(String[] args) { |
| 88 | + new VmBootTimeAndOverheadExample(); |
| 89 | + } |
| 90 | + |
| 91 | + private VmBootTimeAndOverheadExample() { |
| 92 | + /*Enables just some level of log messages. |
| 93 | + Make sure to import org.cloudsimplus.util.Log;*/ |
| 94 | + //Log.setLevel(ch.qos.logback.classic.Level.WARN); |
| 95 | + |
| 96 | + simulation = new CloudSimPlus(); |
| 97 | + datacenter0 = createDatacenter(); |
| 98 | + |
| 99 | + //Creates a broker that is a software acting on behalf of a cloud customer to manage his/her VMs and Cloudlets |
| 100 | + broker0 = new DatacenterBrokerSimple(simulation); |
| 101 | + |
| 102 | + vmList = createVms(); |
| 103 | + cloudletList = createCloudlets(); |
| 104 | + broker0.submitVmList(vmList); |
| 105 | + vmList.get(0).addOnUpdateProcessingListener(this::updateVmProcessingListener); |
| 106 | + broker0.submitCloudletList(cloudletList); |
| 107 | + |
| 108 | + simulation.start(); |
| 109 | + |
| 110 | + final var cloudletFinishedList = broker0.getCloudletFinishedList(); |
| 111 | + new CloudletsTableBuilder(cloudletFinishedList).build(); |
| 112 | + } |
| 113 | + |
| 114 | + private void updateVmProcessingListener(final VmHostEventInfo info) { |
| 115 | + final var vm = info.getVm(); |
| 116 | + final String status = vm.isStartingUp() ? "(booting)" : "(running)"; |
| 117 | + System.out.printf("%6.2f: %s %s CPU %5.1f%% RAM %5.1f%%%n", info.getTime(), vm, status, getVmCpuUsage(vm), getVmRamUsage(vm)); |
| 118 | + |
| 119 | + } |
| 120 | + |
| 121 | + private static double getVmCpuUsage(Vm vm) { |
| 122 | + return vm.getCpuPercentUtilization() * 100.0; |
| 123 | + } |
| 124 | + |
| 125 | + |
| 126 | + private static double getVmRamUsage(final Vm vm) { |
| 127 | + return vm.getRam().getPercentUtilization() * 100.0; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Creates a Datacenter and its Hosts. |
| 132 | + */ |
| 133 | + private Datacenter createDatacenter() { |
| 134 | + final var hostList = new ArrayList<Host>(HOSTS); |
| 135 | + for(int i = 0; i < HOSTS; i++) { |
| 136 | + final var host = createHost(); |
| 137 | + hostList.add(host); |
| 138 | + } |
| 139 | + |
| 140 | + //Uses a VmAllocationPolicySimple by default to allocate VMs |
| 141 | + return new DatacenterSimple(simulation, hostList).setSchedulingInterval(SCHEDULING_INTERVAL); |
| 142 | + } |
| 143 | + |
| 144 | + private Host createHost() { |
| 145 | + final var peList = new ArrayList<Pe>(HOST_PES); |
| 146 | + //List of Host's CPUs (Processing Elements, PEs) |
| 147 | + for (int i = 0; i < HOST_PES; i++) { |
| 148 | + //Uses a PeProvisionerSimple by default to provision PEs for VMs |
| 149 | + peList.add(new PeSimple(HOST_MIPS)); |
| 150 | + } |
| 151 | + |
| 152 | + /* |
| 153 | + Uses ResourceProvisionerSimple by default for RAM and BW provisioning |
| 154 | + and VmSchedulerSpaceShared for VM scheduling. |
| 155 | + */ |
| 156 | + return new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList); |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Creates a list of VMs setting a {@link BootModel} |
| 161 | + * to indicate how the VM will use CPU and RAM during the boot process. |
| 162 | + * @see BootModel#BootModel(UtilizationModel, UtilizationModel) |
| 163 | + */ |
| 164 | + private List<Vm> createVms() { |
| 165 | + final var vmList = new ArrayList<Vm>(VMS); |
| 166 | + final var bootModelCpu = new UtilizationModelDynamic(0.5); |
| 167 | + final var bootModelRam = new UtilizationModelDynamic(0.3); |
| 168 | + for (int i = 0; i < VMS; i++) { |
| 169 | + //Uses a CloudletSchedulerTimeShared by default to schedule Cloudlets |
| 170 | + final var vm = new VmSimple(HOST_MIPS, VM_PES); |
| 171 | + vm.setRam(512) |
| 172 | + .setBw(1000) |
| 173 | + .setSize(10_000) |
| 174 | + .setBootModel(new BootModel(bootModelCpu, bootModelRam)) |
| 175 | + .setStartupDelay(VM_BOOT_DELAY) |
| 176 | + .setShutDownDelay(VM_SHUTDOWN_DELAY); |
| 177 | + vmList.add(vm); |
| 178 | + } |
| 179 | + |
| 180 | + return vmList; |
| 181 | + } |
| 182 | + |
| 183 | + /** |
| 184 | + * Creates a list of Cloudlets. |
| 185 | + */ |
| 186 | + private List<Cloudlet> createCloudlets() { |
| 187 | + final var cloudletList = new ArrayList<Cloudlet>(CLOUDLETS); |
| 188 | + |
| 189 | + //UtilizationModel defining the Cloudlets use only 50% of any resource all the time |
| 190 | + final var utilizationModel = new UtilizationModelDynamic(0.5); |
| 191 | + |
| 192 | + for (int i = 0; i < CLOUDLETS; i++) { |
| 193 | + final var cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES, utilizationModel); |
| 194 | + cloudlet.setSizes(1024); |
| 195 | + cloudletList.add(cloudlet); |
| 196 | + } |
| 197 | + |
| 198 | + return cloudletList; |
| 199 | + } |
| 200 | +} |
0 commit comments