private void printResults() { for (DatacenterBroker broker : brokers) { new CloudletsTableBuilder(broker.getCloudletFinishedList()) .setTitle(broker.getName()) .build(); } System.out.println(); for (Vm vm : vmList) { System.out.printf("Vm %d Broker %d -> Start Time: %.0f Stop Time: %.0f Total Execution Time: %.0f\n", vm.getId(), vm.getBroker().getId(), vm.getStartTime(), vm.getStopTime(), vm.getTotalExecutionTime()); } System.out.println(); }
/** * Clones a VM by creating another one with the same configurations of a * given VM. * * @param vm the VM to be cloned * @return the cloned (new) VM. * * @see #createFaultInjectionForHosts(org.cloudbus.cloudsim.datacenters.Datacenter) */ private Vm cloneVm(Vm vm) { Vm clone = new VmSimple((long) vm.getMips(), (int) vm.getNumberOfPes()); /*It' not required to set an ID for the clone. It is being set here just to make it easy to relate the ID of the vm to its clone, since the clone ID will be 10 times the id of its source VM.*/ clone.setId(vm.getId() * 10); clone.setDescription("Clone of VM " + vm.getId()); clone .setSize(vm.getStorage().getCapacity()) .setBw(vm.getBw().getCapacity()) .setRam(vm.getBw().getCapacity()) .setCloudletScheduler(new CloudletSchedulerTimeShared()); System.out.printf("\n\n# Cloning %s - MIPS %.2f Number of Pes: %d\n", vm, clone.getMips(), clone.getNumberOfPes()); return clone; }
/** * Shows updates every time the simulation clock advances. * @param evt information about the event happened (that for this Listener is just the simulation time) */ private void onClockTickListener(EventInfo evt) { vmList.forEach(vm -> { System.out.printf( "\t\tTime %6.1f: Vm %d CPU Usage: %6.2f%% (%2d vCPUs. Running Cloudlets: #%02d) Upper Threshold: %.2f History Entries: %d\n", evt.getTime(), vm.getId(), vm.getCpuPercentUsage()*100.0, vm.getNumberOfPes(), vm.getCloudletScheduler().getCloudletExecList().size(), vm.getPeVerticalScaling().getUpperThresholdFunction().apply(vm), vm.getUtilizationHistory().getHistory().size()); }); }
public Vm createVm(int pes) { Vm vm = new VmSimple(VM_MIPS, pes); vm .setRam(VM_RAM).setBw((long)VM_BW).setSize(VM_SIZE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); return vm; }
/** * Shows updates every time the simulation clock advances. * @param evt information about the event happened (that for this Listener is just the simulation time) */ private void onClockTickListener(EventInfo evt) { vmList.forEach(vm -> System.out.printf( "\t\tTime %6.1f: Vm %d CPU Usage: %6.2f%% (%2d vCPUs. Running Cloudlets: #%d). RAM usage: %.2f%% (%d MB)\n", evt.getTime(), vm.getId(), vm.getCpuPercentUsage()*100.0, vm.getNumberOfPes(), vm.getCloudletScheduler().getCloudletExecList().size(), vm.getRam().getPercentUtilization()*100, vm.getRam().getAllocatedResource()) ); }
@Override protected Vm createVm(DatacenterBroker broker) { return new VmSimple(VM_MIPS, VM_PES) .setRam(VM_RAM).setBw(VM_BW).setSize(VM_STORAGE) .setCloudletScheduler(new CloudletSchedulerTimeShared()); } }
private void onClockTickListener(EventInfo eventInfo) { for (Vm vm : vmList) { System.out.printf("\t\tTime %6.1f: Vm %d Ram Usage: %6.2f%% (%4d of %4d MB)", eventInfo.getTime(), vm.getId(), vm.getRam().getPercentUtilization() * 100.0, vm.getRam().getAllocatedResource(), vm.getRam().getCapacity()); System.out.printf(" | Host Ram Allocation: %6.2f%% (%5d of %5d MB). Running Cloudlets: %d", vm.getHost().getRam().getPercentUtilization() * 100, vm.getHost().getRam().getAllocatedResource(), vm.getHost().getRam().getCapacity(), vm.getCloudletScheduler().getCloudletExecList().size()); } }
/** * Try to allocate all resources that a VM requires (Storage, RAM, BW and MIPS) to be placed at this Host. * * @param vm the VM to try allocating resources to * @param inMigration If the VM is migrating into the Host or it is being just created for the first time * @return true if the Vm was placed into the host, false if the Host doesn't have enough resources to allocate the Vm */ private boolean allocateResourcesForVm(final Vm vm, final boolean inMigration){ if (!storage.isAmountAvailable(vm.getStorage())) { logAllocationError(vm, inMigration, "MB", this.getStorage(), vm.getStorage()); return false; } if (!ramProvisioner.isSuitableForVm(vm, vm.getCurrentRequestedRam())) { logAllocationError(vm, inMigration, "MB", this.getRam(), vm.getRam()); return false; } if (!bwProvisioner.isSuitableForVm(vm, vm.getCurrentRequestedBw())) { logAllocationError(vm, inMigration, "Mbps", this.getBw(), vm.getBw()); return false; } if (!vmScheduler.isSuitableForVm(vm, true)) { return false; } vm.setInMigration(inMigration); allocateResourcesForVm(vm); return true; }
/** * Process the event for a Broker which wants to create a VM in this * Datacenter. This Datacenter will then send the status back to * the Broker. * * @param evt information about the event just happened * @param ackRequested indicates if the event's sender expects to receive an * acknowledge message when the event finishes to be processed * @return true if a host was allocated to the VM; false otherwise */ protected boolean processVmCreate(final SimEvent evt, final boolean ackRequested) { final Vm vm = (Vm) evt.getData(); final boolean hostAllocatedForVm = vmAllocationPolicy.allocateHostForVm(vm); if (ackRequested) { send(vm.getBroker(), getSimulation().getMinTimeBetweenEvents(), CloudSimTags.VM_CREATE_ACK, vm); } if (hostAllocatedForVm) { if (!vm.isCreated()) { vm.setCreated(true); } final List<Double> mipsList = vm.getHost().getVmScheduler().getAllocatedMips(vm); vm.updateProcessing(getSimulation().clock(), mipsList); } return hostAllocatedForVm; }
/** * Gets the total monetary cost of processing power allocated from the PM hosting the VM. * * @return */ public double getProcessingCost() { final double hostMips = vm.getHost().getPeList().stream() .findFirst() .map(Pe::getCapacity) .orElse(0L); final double costPerMI = hostMips > 0 ? getDcCharacteristics().getCostPerSecond()/hostMips : 0.0; return costPerMI * getVm().getMips() * getVm().getNumberOfPes(); }
private void printSolution(String title, CloudletToVmMappingSolution solution, boolean showIndividualCloudletFitness) { System.out.printf("%s (cost %.2f fitness %.6f)\n", title, solution.getCost(), solution.getFitness()); if(!showIndividualCloudletFitness) return; for(Map.Entry<Cloudlet, Vm> e: solution.getResult().entrySet()){ System.out.printf( "Cloudlet %3d (%d PEs, %6d MI) mapped to Vm %3d (%d PEs, %6.0f MIPS)\n", e.getKey().getId(), e.getKey().getNumberOfPes(), e.getKey().getLength(), e.getValue().getId(), e.getValue().getNumberOfPes(), e.getValue().getMips()); } System.out.println(); }
/** * Adds number used PEs for a Vm to the map between each VM and the number of PEs used. * @param vm the VM to add the number of used PEs to the map */ protected void addUsedPes(final Vm vm) { usedPes.put(vm, vm.getNumberOfPes()); }
@Override protected boolean requestUpScaling(final double time) { if(!haveNewCloudletsArrived()){ return false; } final double vmCpuUsagePercent = getVm().getCpuPercentUsage() * 100; final Vm newVm = getVmSupplier().get(); LOGGER.info( "{}: {}{}: Requesting creation of {} to receive new Cloudlets in order to balance load of {}. {} CPU usage is {}%", time, getClass().getSimpleName(), getVm(), newVm, getVm(), getVm().getId(), vmCpuUsagePercent); getVm().getBroker().submitVm(newVm); cloudletCreationRequests = getVm().getBroker().getCloudletCreatedList().size(); return true; }
private void checkCloudletsCompletionForGivenVm(final Vm vm) { final List<Cloudlet> nonReturnedCloudlets = vm.getCloudletScheduler().getCloudletFinishedList().stream() .map(CloudletExecution::getCloudlet) .filter(cloudlet -> !vm.getCloudletScheduler().isCloudletReturned(cloudlet)) .collect(toList()); nonReturnedCloudlets.forEach(this::returnFinishedCloudletToBroker); }
private void appendVmMigrationMsgToStringBuilder(final StringBuilder builder, final Vm vm, final Host targetHost) { if(LOGGER.isInfoEnabled()) { builder.append(" ").append(vm).append(" will be migrated from ") .append(vm.getHost()).append(" to ").append(targetHost) .append(System.lineSeparator()); } }
/** * Tracks the update of execution for a VM. * If that VM is overloaded then destroys it. * In this example, this {@link EventListener} is just * attached for VM 1, therefore, just such a VM will be destroyed * if overloaded. * * @param info event information, including the VM that was updated */ private void vmProcessingUpdateListener(VmHostEventInfo info) { final Vm vm = info.getVm(); //Destroys VM 1 when its CPU usage reaches 90% if(vm.getCpuPercentUsage() > 0.9 && vm.isCreated()){ System.out.printf( "\n# %.2f: Intentionally destroying %s due to CPU overload. Current VM CPU usage is %.2f%%\n", info.getTime(), vm, vm.getCpuPercentUsage()*100); vm.getHost().destroyVm(vm); } datacenter0.getHostList().forEach(h -> System.out.printf("# %.2f: %s CPU Utilization %.2f%%\n", info.getTime(), h, h.getUtilizationOfCpu()*100)); }
public Vm getVmById(final int id) { return broker.getVmWaitingList().stream() .filter(vm -> vm.getId() == id) .findFirst().orElse(Vm.NULL); }
@Override public void addUtilizationHistory(double time) { if (!enabled || isNotTimeToAddHistory(time)) { return; } final double utilization = vm.getCpuPercentUsage(vm.getCloudletScheduler().getPreviousTime()); time = vm.isIdle() ? time : (int)time; addUtilizationHistoryValue(time, utilization); this.previousTime = time; }
private void allocateResourcesForVm(Vm vm) { ramProvisioner.allocateResourceForVm(vm, vm.getCurrentRequestedRam()); bwProvisioner.allocateResourceForVm(vm, vm.getCurrentRequestedBw()); vmScheduler.allocatePesForVm(vm, vm.getCurrentRequestedMips()); storage.allocateResource(vm.getStorage()); }