/** * Converts a value in bytes to Megabites (Mb) * @param bytes the value in bytes * @return the value in Megabites (Mb) */ public static double bytesToMegaBits(final double bytes){ return bytesToBits(bytesToMegaBytes(bytes)); }
/** * Converts any value in microseconds (μ) to seconds. * <p>The existing {@link java.util.concurrent.TimeUnit} and {@link java.time.Duration} classes * don't provide the double precision required here.</p> * * @param micro the value in microseconds (μ) * @return the value in seconds */ public static double microToSeconds(final double micro) { return microToMilli(micro)/1000.0; } }
/** * Gets the timestamp converted to milliseconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleMachineEventsTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
/** * Converts a value in bytes to the most suitable unit, such as Kilobytes (KB), MegaBytes (MB) or * Gigabytes (GB) * @param bytes the value in bytes * @return the converted value concatenated with the unit converted to (KB, MB or GB) */ public static String bytesToSuitableUnit(final double bytes){ if(bytes < KILO) { return String.format("%.0f bytes", bytes); } if(bytes < MEGA) { return String.format("%.1f KB", bytesToKiloBytes(bytes)); } if(bytes < GIGA) { return String.format("%.1f MB", bytesToMegaBytes(bytes)); } return String.format("%.1f GB", bytesToGigaBytes(bytes)); }
private long getCloudletSizeInMB(final Cloudlet cloudlet) { return (long)Conversion.bytesToMegaBytes(cloudlet.getFileSize()); }
/** * Computes the network delay to send a packet through the network. * * @param netPkt the packet to be sent * @param bwCapacity the total bandwidth capacity (in Megabits/s) * @param netPktList the list of packets waiting to be sent * @return the expected time to transfer the packet through the network (in seconds) */ protected double networkDelayForPacketTransmission(final HostPacket netPkt, final double bwCapacity, final List<HostPacket> netPktList) { return Conversion.bytesToMegaBits(netPkt.getVmPacket().getSize()) / getAvailableBwForEachPacket(bwCapacity, netPktList); }
/** * Gets the time to transfer a file (in MBytes) * according to a given transfer speed (in Mbits/sec). * * @param fileSize the size of the file to compute the transfer time (in MBytes) * @param speed the speed (in MBits/sec) to compute the time to transfer the file * @return the transfer time in seconds */ protected final double getTransferTime(final int fileSize, final double speed){ return Conversion.bytesToBits(fileSize)/speed; }
/** * Instantiates a GoogleMachineEventsTraceReader to read a "machine events" from a given InputStream. * Created Hosts will have 16GB of maximum RAM and the maximum of 8 {@link Pe}s. * * @param filePath the path to the trace file * @param reader a {@link InputStream} object to read the file * @param hostCreationFunction A {@link Function} that will be called for every {@link Host} to be created * from a line inside the trace file. * The {@link Function} will receive a {@link MachineEvent} object containing * the Host data read from the trace and must return the created Host * according to such data. * @throws IllegalArgumentException when the trace file name is null or empty * @see #setMaxRamCapacity(long) * @see #setMaxCpuCores(int) * @see #process() */ private GoogleMachineEventsTraceReader( final String filePath, final InputStream reader, final Function<MachineEvent, Host> hostCreationFunction) { super(filePath, reader); this.setHostCreationFunction(hostCreationFunction); this.setMaxRamCapacity((long) Conversion.gigaToMega(16)); this.setMaxCpuCores(8); this.laterAvailableHosts = new ArrayList<>(); this.hostsForRemoval = new ArrayList<>(); }
/** * Computes the expected time to migrate a VM to a given Host. * It is computed as: VM RAM (MB)/Target Host Bandwidth (Mb/s). * * @param vm the VM to migrate. * @param targetHost the Host where tto migrate the VM * @return the time (in seconds) that is expected to migrate the VM */ private double timeToMigrateVm(final Vm vm, final Host targetHost) { return vm.getRam().getCapacity() / Conversion.bitesToBytes(targetHost.getBw().getCapacity() * getBandwidthPercentForMigration()); }
/** * A method that is used to actually create each Cloudlet defined as a task in the * trace file. * The researcher can write his/her own code inside this method to define * how he/she wants to create the Cloudlet based on the trace data. * * @param event an object containing the trace line read, used to create the Cloudlet. * @return */ private Cloudlet createCloudlet(final TaskEvent event) { /* The trace doesn't define the actual number of CPU cores (PEs) a Cloudlet will require, but just a percentage of the number of cores that is required. This way, we have to compute the actual number of cores. This is different from the CPU UtilizationModel, which is defined in the "task usage" trace files. */ final long pesNumber = event.actualCpuCores(VM_PES) > 0 ? event.actualCpuCores(VM_PES) : VM_PES; final double maxRamUsagePercent = event.getResourceRequestForRam() > 0 ? event.getResourceRequestForRam() : Conversion.HUNDRED_PERCENT; final UtilizationModelDynamic utilizationRam = new UtilizationModelDynamic(Unit.PERCENTAGE, 0, maxRamUsagePercent); final long sizeInBytes = (long) Math.ceil(Conversion.megaBytesToBytes(event.getResourceRequestForLocalDiskSpace()*VM_SIZE + 1)); return new CloudletSimple(CLOUDLET_LENGTH, pesNumber) .setFileSize(sizeInBytes) .setOutputSize(sizeInBytes) .setUtilizationModelBw(new UtilizationModelFull()) .setUtilizationModelCpu(new UtilizationModelFull()) .setUtilizationModelRam(utilizationRam); }
/** * Gets the packets from the local packets buffer and sends them * to VMs outside this host. */ private void sendPacketsToExternalVms() { final double availableBwByPacket = getBandwidthByPacket(pktsToSendForExternalVms.size()); for (final HostPacket hostPkt : pktsToSendForExternalVms) { final double delay = Conversion.bytesToMegaBits(hostPkt.getVmPacket().getSize()) / availableBwByPacket; totalDataTransferBytes += hostPkt.getVmPacket().getSize(); // send to Datacenter with delay getSimulation().send( getDatacenter(), getEdgeSwitch(), delay, CloudSimTags.NETWORK_EVENT_UP, hostPkt); } pktsToSendForExternalVms.clear(); }
/** * Gets the timestamp converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskEventsTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
/** * Gets the start time converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskUsageTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },
/** * Gets the end time converted to seconds. * @param reader the reader for the trace file * @return */ @Override public Double getValue(final GoogleTaskUsageTraceReader reader) { return Conversion.microToSeconds(reader.getFieldDoubleValue(this)); } },