/** * A {@link Predicate} that checks if a given VM is overloaded or not, * based on upper CPU utilization threshold. * A reference to this method is assigned to each {@link HorizontalVmScaling} created. * * @param vm the VM to check if it is overloaded * @return true if the VM is overloaded, false otherwise * @see #createHorizontalVmScaling(Vm) */ private boolean isVmOverloaded(Vm vm) { return vm.getCpuPercentUsage() > 0.7; }
@Override public Vm getVmToMigrate(Host host) { final List<? extends Vm> migratableVms = host.getMigratableVms(); if (migratableVms.isEmpty()) { return Vm.NULL; } final Predicate<Vm> inMigration = Vm::isInMigration; final Comparator<? super Vm> cpuUsageComparator = Comparator.comparingDouble(vm -> vm.getCpuPercentUsage(vm.getSimulation().clock())); final Optional<? extends Vm> optional = migratableVms.stream() .filter(inMigration.negate()) .min(cpuUsageComparator); return optional.isPresent() ? optional.get() : Vm.NULL; }
private void printVmsCpuUsage(EventInfo eventInfo) { DatacenterBroker broker0 = getFirstBroker(); broker0.getVmExecList().sort(Comparator.comparingLong(Vm::getId)); broker0.getVmExecList().forEach(vm -> System.out.printf("#### Time %.0f: Vm %d CPU usage: %.2f. SLA: %.2f.\n", eventInfo.getTime(), vm.getId(), vm.getCpuPercentUsage(), getCustomerMaxCpuUtilization()) ); }
/** * 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)); }
/** * 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()); }); }
/** * 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 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; }
@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; }