/** * Checks if at the current time, {@link #getK() K} events have happened, * considering the {@link #eventsArrivalProbability() probability of these K events} * to happen in a time interval. * * @return true if the K events have happened at current time, false otherwise */ public boolean eventsHappened(){ return rand.sample() <= eventsArrivalProbability(); }
/** * Gets the probability to arrive {@link #getK() K} events in the current time, * considering the expected average arrival time {@link #getLambda() lambda}. * It computes the Probability Mass Function (PMF) of the Poisson distribution. * @return * @see <a href="https://en.wikipedia.org/wiki/Poisson_distribution">Poisson distribution</a> */ public double eventsArrivalProbability(){ return (Math.pow(getLambda(), k) * Math.exp(-getLambda())) / CombinatoricsUtils.factorial(k); }
/** * Creates a new Poisson random number generator to check * the probability of 1 event ({@link #getK() k}) to happen at each time * interval. * * @param lambda the average number of events that happen at each 1 time unit. * If one considers the unit as minute, this value means the average number of arrivals * at each minute. * @param seed the seed to initialize the uniform random number generator * @see #setK(int) * @see #setLambda(double) */ public PoissonDistr(final double lambda, final long seed){ this.rand = new UniformDistr(seed); this.k = 1; this.setLambda(lambda); }
System.out.printf("%d customers arrived at minute %d\n", poisson.getK(), minute); .filter(time -> poisson.eventsHappened()) .peek(time -> printArrivals.accept(poisson, time)) .map(time -> poisson.getK()) .sum(); "\t%d customers arrived in %d minutes\n", totalArrivedCustomers, SIMULATION_TIME_LENGHT); System.out.printf("\tArrival rate: %.2f customers per minute. Customers interarrival time: %.2f minutes in average\n", poisson.getLambda(), poisson.getInterArrivalMeanTime()); final long seed=System.currentTimeMillis(); for(int i = 0; i < NUMBER_OF_SIMULATIONS; i++){ poisson = new PoissonDistr(MEAN_CUSTOMERS_ARRIVAL_MINUTE, seed+i); System.out.printf("Simulation number %d\n", i); customersInAllSimulations += runSimulation.apply(poisson); System.out.printf( "%.2f customers expected by each %d minutes of simulation with interarrival time of %.2f minutes\n", poisson.getLambda()*SIMULATION_TIME_LENGHT, SIMULATION_TIME_LENGHT, poisson.getInterArrivalMeanTime());
/** * Creates the fault injection for host * * @param datacenter */ private void createFaultInjectionForHosts(final Datacenter datacenter) { PoissonDistr poisson = new PoissonDistr(MEAN_FAILURE_NUMBER_PER_HOUR, getSeed()); faultInjection = new HostFaultInjection(datacenter, poisson); getFaultInjection().setMaxTimeToFailInHours(MAX_TIME_TO_GENERATE_FAILURE_IN_HOURS); for (DatacenterBroker broker : getBrokerList()) { getFaultInjection().addVmCloner (broker, new VmClonerSimple(this::cloneVm, this::cloneCloudlets)); } System.out.printf( "\tFault Injection created for %s.\n\tMean Number of Failures per hour: %.6f (1 failure expected at each %.4f hours).\n", datacenter, MEAN_FAILURE_NUMBER_PER_HOUR, poisson.getInterArrivalMeanTime()); }
/** * Creates the fault injection for host * * @param datacenter */ private void createFaultInjectionForHosts(Datacenter datacenter) { //Use the system time to get random results every time you run the simulation //final long seed = System.currentTimeMillis(); final long seed = 112717613L; this.poisson = new PoissonDistr(MEAN_FAILURE_NUMBER_PER_HOUR, seed); fault = new HostFaultInjection(datacenter, poisson); fault.setMaxTimeToFailInHours(800); fault.addVmCloner(broker, new VmClonerSimple(this::cloneVm, this::cloneCloudlets)); }
public HostFaultInjectionExample1() { /*Enables just some level of log messages. Make sure to import org.cloudsimplus.util.Log;*/ //Log.setLevel(ch.qos.logback.classic.Level.WARN); System.out.println("Starting " + getClass().getSimpleName()); simulation = new CloudSim(); Datacenter datacenter = createDatacenter(); broker = new DatacenterBrokerSimple(simulation); createAndSubmitVms(); createAndSubmitCloudlets(); createFaultInjectionForHosts(datacenter); simulation.start(); new CloudletsTableBuilder(broker.getCloudletFinishedList()).build(); System.out.printf( "\n# Mean Number of Failures per Hour: %.3f (1 failure expected at each %.2f hours).\n", MEAN_FAILURE_NUMBER_PER_HOUR, poisson.getInterArrivalMeanTime()); System.out.printf("# Number of Host faults: %d\n", fault.getNumberOfHostFaults()); System.out.printf("# Number of VM faults (VMs destroyed): %d\n", fault.getNumberOfFaults()); System.out.printf("# Time the simulations finished: %.4f hours\n", simulation.clockInHours()); System.out.printf("# Mean Time To Repair Failures of VMs in minutes (MTTR): %.2f minute\n", fault.meanTimeToRepairVmFaultsInMinutes()); System.out.printf("# Mean Time Between Failures (MTBF) affecting all VMs in minutes: %.2f minutes\n", fault.meanTimeBetweenVmFaultsInMinutes()); System.out.printf("# Hosts MTBF: %.2f minutes\n", fault.meanTimeBetweenHostFaultsInMinutes()); System.out.printf("# Availability: %.2f%%\n\n", fault.availability()*100); System.out.println(getClass().getSimpleName() + " finished!"); }
/** * Gets a random number that represents the next time for an event to happen, * considering the {@link #getLambda() events arrival rate (lambda)}. * @return */ @Override public double sample() { return Math.exp(1.0 - rand.sample()) / getLambda(); }