/** * Gets the time delay in seconds, from the current simulation time, * that the next failure will be injected. * Since the values returned by the {@link #faultArrivalHoursGenerator} * are considered to be in <b>hours</b>, such values are converted to seconds. * * @return the next failure injection delay in seconds */ private double getTimeDelayForNextFault() { return faultArrivalHoursGenerator.sample() * 3600; }
/** * Creates a fault injection mechanism for the Hosts of a given {@link Datacenter}. * The Hosts failures are randomly injected according to the given * pseudo random number generator, that indicates the mean of failures to be generated per <b>minute</b>, * (which is also called <b>event rate</b> or <b>rate parameter</b>). * * @param datacenter the Datacenter to which failures will be randomly injected for its Hosts * * @param faultArrivalHoursGenerator a Pseudo Random Number Generator which generates the * times Hosts failures will occur (in hours). * <b>The values returned by the generator will be considered to be hours</b>. * Frequently it is used a * {@link PoissonDistr} to generate failure arrivals, but any {@link ContinuousDistribution} * can be used. */ public HostFaultInjection(final Datacenter datacenter, final ContinuousDistribution faultArrivalHoursGenerator) { super(datacenter.getSimulation()); this.setDatacenter(datacenter); this.lastFailedHost = Host.NULL; this.faultArrivalHoursGenerator = faultArrivalHoursGenerator; this.random = new UniformDistr(faultArrivalHoursGenerator.getSeed()+1); this.vmRecoveryTimeSecsMap = new HashMap<>(); this.hostFaultsTimeSecsMap = new HashMap<>(); this.faultsOfAllVmsByBroker = new HashMap<>(); this.vmClonerMap = new HashMap<>(); this.maxTimeToFailInHours = Double.MAX_VALUE; }
private void runSimulationAndPrintResults() { simulation.start(); broker.getCloudletSubmittedList().sort(Comparator.comparingDouble(Cloudlet::getExecStartTime)); final CloudletsTableBuilder builder = new CloudletsTableBuilder(broker.getCloudletSubmittedList()); builder .column(9, this::formatColumn) .column(10, this::formatColumn) .column(11, this::formatColumn) .build(); final int notFinished = broker.getCloudletCreatedList().size() - broker.getCloudletFinishedList().size(); System.out.println("\nDatacenter Scheduling Interval: " + datacenter.getSchedulingInterval()); System.out.println("Min time between events: " + simulation.getMinTimeBetweenEvents()); System.out.println("Seed for the random Cloudlet's submission delay generator: " + random.getSeed() + "\n"); System.out.println("Cloudlets created: " +cloudletList.size() + " | Cloudlets not finished: " + notFinished); if(notFinished > 0){ System.out.println("\n----------> Try decreasing the value of MIN_TIME_BETWEEN_EVENTS constant in this example! <----------\n"); } System.out.println(getClass().getSimpleName() + " finished!"); }
/** * Gets a Pseudo Random Number used to give a * recovery time (in seconds) for each VM that was failed. * @return */ public double getRandomRecoveryTimeForVmInSecs() { return random.sample()*MAX_VM_RECOVERY_TIME_SECS + 1; }
/** * Get the seek time for a file with the defined size. Given a file size in MB, this method * returns a seek time for the file in seconds. * * @param fileSize the size of a file in MB * @return the seek time in seconds */ private double getSeekTime(int fileSize) { double result = 0; if (gen != null) { result += gen.sample(); } if (fileSize > 0 && capacity != 0) { result += (fileSize / capacity); } return result; }
@Override public Vm getVmToMigrate(Host host) { final List<Vm> migratableVms = host.getMigratableVms(); if (migratableVms.isEmpty()) { return Vm.NULL; } final int index = (int)rand.sample()*migratableVms.size(); return migratableVms.get(index); }
@Override public int getRandomValue(final int maxValue){ final double uniform = getRandom().sample(); /*always get an index between [0 and size[, regardless if the random number generator returns values between [0 and 1[ or >= 1*/ return (int)(uniform >= 1 ? uniform % maxValue : uniform * maxValue); }
/** * Randomly generates a number of PEs which will fail for the datacenter. * The minimum number of PEs to fail is 1. * * @param host the Host to generate a number of PEs to fail * @return the generated number of failed PEs for the datacenter, * between [1 and Number of PEs]. */ private int randomNumberOfFailedPes(final Host host) { /*the random generator return values from [0 to 1] and multiplying by the number of PEs we get a number between 0 and number of PEs*/ return (int) (random.sample() * host.getNumberOfWorkingPes()) + 1; }
/** * Randomly gets a Host that will have some PEs set to failed. * * @return the randomly selected Host; or {@link Host#NULL} if the Datacenter * doesn't have Hosts or the selected one doesn't have more PEs. */ private Host getRandomHost() { if (datacenter.getHostList().isEmpty()) { return Host.NULL; } final int idx = (int) (random.sample() * datacenter.getHostList().size()); return datacenter.getHost(idx); }
/** * Define a specific policy to randomly select a suitable Host to place a given VM. * It implements a {@link Comparator} that randomly sorts the Hosts by returning a value between [-1..1] * (according to comparator requirements). * Hosts' attributes aren't even considered to ensure the randomness. * * @param vmAllocationPolicy the {@link VmAllocationPolicy} containing Host allocation information * @param vm the {@link Vm} to find a host to be placed * @return an {@link Optional} that may contain a Host in which to place a Vm, or an {@link Optional#empty()} * {@link Optional} if not suitable Host was found. */ private Optional<Host> findRandomSuitableHostForVm(VmAllocationPolicy vmAllocationPolicy, Vm vm) { return vmAllocationPolicy .getHostList() .stream() .filter(host -> host.isSuitableForVm(vm)) .sorted(Comparator.comparingDouble(host -> random.sample())) .findAny(); }
@Override public double getUtilization(double time) { if (getHistory().containsKey(time)) { return getHistory().get(time); } final double utilization = getRandomGenerator().sample(); getHistory().put(time, utilization); return utilization; }
/** * Simulates the dynamic arrival of Cloudlets, randomly during simulation runtime. * At any time the simulation clock updates, a new Cloudlet will be * created with a probability of 30%. * * @param evt */ private void createRandomCloudlets(final EventInfo evt) { if(random.sample() <= 0.3){ System.out.printf("\n# Randomly creating 1 Cloudlet at time %.2f\n", evt.getTime()); Cloudlet cloudlet = createCloudlet(); cloudletList.add(cloudlet); broker0.submitCloudlet(cloudlet); } } }
/** * Get the seek time for a file with the defined size. Given a file size in MByte, this method * returns a seek time for the file in seconds. * * @param fileSize the size of a file in MByte * @return the seek time in seconds */ private double getSeekTime(final int fileSize) { double result = 0; if (gen != null) { result += gen.sample(); } if (fileSize > 0 && storage.getCapacity() != 0) { result += fileSize / (double)storage.getCapacity(); } return result; }
/** * Creates an array with the configuration of PEs for each Cloudlet to be * created in each experiment run. Every experiment will use the same * Cloudlets configurations. * * @return the created cloudlet PEs array */ private int[] createCloudletPesArray() { int[] pesArray = new int[CLOUDLETS_TO_CREATE]; int totalNumberOfPes = 0; final ContinuousDistribution random = new NormalDistr(getBaseSeed(), 2, 0.6); for (int i = 0; i < CLOUDLETS_TO_CREATE; i++) { pesArray[i] = (int) random.sample() + 1; totalNumberOfPes += pesArray[i]; } return pesArray; }
@Override protected Vm createVm() { final int id = createsVms++; final int pesId = (int) (randVm.sample() * VM_PES.length); final int mipdsId = (int) (randMipsVm.sample() * MIPS_VM.length); final int pes = VM_PES[pesId]; final int mips = MIPS_VM[mipdsId]; final Vm vm = new VmSimple(id, mips, pes) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerCompletelyFair()); return vm; }
@Override protected Vm createVm() { final int id = createsVms++; final int pesId = (int) (randVm.sample() * VM_PES.length); final int mipsId = (int) (randMip.sample() * VM_MIPS.length); final int pes = VM_PES[pesId]; final int mips = VM_MIPS[mipsId]; final Vm vm = new VmSimple(id, mips, pes) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); return vm; }
private Cloudlet createCloudlet() { final UtilizationModel model = new UtilizationModelDynamic(0.1); final int id = createdCloudlets++; final int i = (int) (randCloudlet.sample() * CLOUDLET_LENGTHS.length); final int p = (int) (randCloudletPes.sample() * CLOUDLET_PES.length); final long length = CLOUDLET_LENGTHS[i]; final long pes = CLOUDLET_PES[p]; return new CloudletSimple(id, length, pes) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModelBw(model) .setUtilizationModelRam(model) .setUtilizationModelCpu(new UtilizationModelFull()); }
private Cloudlet createCloudlet() { final int id = createdCloudlets++; final int i = (int) (randCloudlet.sample() * CLOUDLET_LENGTHS.length); final long length = CLOUDLET_LENGTHS[i]; return new CloudletSimple(id, length, 2) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModel(new UtilizationModelFull()); }
private Cloudlet createCloudlet() { final int id = createdCloudlets++; //randomly selects a length for the cloudlet final long length = CLOUDLET_LENGTHS[(int) rand.sample()]; UtilizationModel utilization = new UtilizationModelFull(); return new CloudletSimple(id, length, 2) .setFileSize(1024) .setOutputSize(1024) .setUtilizationModel(utilization); } }
@Override protected Vm createVm() { final int id = createsVms++; final int pesId = (int) (randVm.sample() * VM_PES.length); final int pes = VM_PES[pesId]; Vm vm = new VmSimple(id, 1000, pes) .setRam(512).setBw(1000).setSize(10000) .setCloudletScheduler(new CloudletSchedulerTimeShared()); return vm; }