/** * Prints the results. * * @param datacenter the datacenter * @param lastClock the last clock * @param experimentName the experiment name * @param outputInCsv the output in csv * @param outputFolder the output folder */ public static void printResults( PowerDatacenter datacenter, List<Vm> vms, double lastClock, String experimentName, boolean outputInCsv, String outputFolder) { Log.enable(); List<Host> hosts = datacenter.getHostList(); int numberOfHosts = hosts.size(); int numberOfVms = vms.size(); double totalSimulationTime = lastClock; double energy = datacenter.getPower() / (3600 * 1000); int numberOfMigrations = datacenter.getMigrationCount(); Map<String, Double> slaMetrics = getSlaMetrics(vms); double slaOverall = slaMetrics.get("overall"); double slaAverage = slaMetrics.get("average"); double slaDegradationDueToMigration = slaMetrics.get("underallocated_migration"); // double slaTimePerVmWithMigration = slaMetrics.get("sla_time_per_vm_with_migration"); // double slaTimePerVmWithoutMigration = // slaMetrics.get("sla_time_per_vm_without_migration"); // double slaTimePerHost = getSlaTimePerHost(hosts); double slaTimePerActiveHost = getSlaTimePerActiveHost(hosts); double sla = slaTimePerActiveHost * slaDegradationDueToMigration; List<Double> timeBeforeHostShutdown = getTimesBeforeHostShutdown(hosts); int numberOfHostShutdowns = timeBeforeHostShutdown.size(); double meanTimeBeforeHostShutdown = Double.NaN; double stDevTimeBeforeHostShutdown = Double.NaN; if (!timeBeforeHostShutdown.isEmpty()) { meanTimeBeforeHostShutdown = MathUtil.mean(timeBeforeHostShutdown); stDevTimeBeforeHostShutdown = MathUtil.stDev(timeBeforeHostShutdown); } List<Double> timeBeforeVmMigration = getTimesBeforeVmMigration(vms); double meanTimeBeforeVmMigration = Double.NaN; double stDevTimeBeforeVmMigration = Double.NaN; if (!timeBeforeVmMigration.isEmpty()) { meanTimeBeforeVmMigration = MathUtil.mean(timeBeforeVmMigration); stDevTimeBeforeVmMigration = MathUtil.stDev(timeBeforeVmMigration); } if (outputInCsv) { File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } File folder1 = new File(outputFolder + "/stats"); if (!folder1.exists()) { folder1.mkdir(); } File folder2 = new File(outputFolder + "/time_before_host_shutdown"); if (!folder2.exists()) { folder2.mkdir(); } File folder3 = new File(outputFolder + "/time_before_vm_migration"); if (!folder3.exists()) { folder3.mkdir(); } File folder4 = new File(outputFolder + "/metrics"); if (!folder4.exists()) { folder4.mkdir(); } StringBuilder data = new StringBuilder(); String delimeter = ","; data.append(experimentName + delimeter); data.append(parseExperimentName(experimentName)); data.append(String.format("%d", numberOfHosts) + delimeter); data.append(String.format("%d", numberOfVms) + delimeter); data.append(String.format("%.2f", totalSimulationTime) + delimeter); data.append(String.format("%.5f", energy) + delimeter); data.append(String.format("%d", numberOfMigrations) + delimeter); data.append(String.format("%.10f", sla) + delimeter); data.append(String.format("%.10f", slaTimePerActiveHost) + delimeter); data.append(String.format("%.10f", slaDegradationDueToMigration) + delimeter); data.append(String.format("%.10f", slaOverall) + delimeter); data.append(String.format("%.10f", slaAverage) + delimeter); // data.append(String.format("%.5f", slaTimePerVmWithMigration) + delimeter); // data.append(String.format("%.5f", slaTimePerVmWithoutMigration) + delimeter); // data.append(String.format("%.5f", slaTimePerHost) + delimeter); data.append(String.format("%d", numberOfHostShutdowns) + delimeter); data.append(String.format("%.2f", meanTimeBeforeHostShutdown) + delimeter); data.append(String.format("%.2f", stDevTimeBeforeHostShutdown) + delimeter); data.append(String.format("%.2f", meanTimeBeforeVmMigration) + delimeter); data.append(String.format("%.2f", stDevTimeBeforeVmMigration) + delimeter); if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) { PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter.getVmAllocationPolicy(); double executionTimeVmSelectionMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryVmSelection()); double executionTimeVmSelectionStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryVmSelection()); double executionTimeHostSelectionMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryHostSelection()); double executionTimeHostSelectionStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryHostSelection()); double executionTimeVmReallocationMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryVmReallocation()); double executionTimeVmReallocationStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryVmReallocation()); double executionTimeTotalMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryTotal()); double executionTimeTotalStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryTotal()); data.append(String.format("%.5f", executionTimeVmSelectionMean) + delimeter); data.append(String.format("%.5f", executionTimeVmSelectionStDev) + delimeter); data.append(String.format("%.5f", executionTimeHostSelectionMean) + delimeter); data.append(String.format("%.5f", executionTimeHostSelectionStDev) + delimeter); data.append(String.format("%.5f", executionTimeVmReallocationMean) + delimeter); data.append(String.format("%.5f", executionTimeVmReallocationStDev) + delimeter); data.append(String.format("%.5f", executionTimeTotalMean) + delimeter); data.append(String.format("%.5f", executionTimeTotalStDev) + delimeter); writeMetricHistory( hosts, vmAllocationPolicy, outputFolder + "/metrics/" + experimentName + "_metric"); } data.append("\n"); writeDataRow(data.toString(), outputFolder + "/stats/" + experimentName + "_stats.csv"); writeDataColumn( timeBeforeHostShutdown, outputFolder + "/time_before_host_shutdown/" + experimentName + "_time_before_host_shutdown.csv"); writeDataColumn( timeBeforeVmMigration, outputFolder + "/time_before_vm_migration/" + experimentName + "_time_before_vm_migration.csv"); } else { Log.setDisabled(false); Log.printLine(); Log.printLine(String.format("Experiment name: " + experimentName)); Log.printLine(String.format("Number of hosts: " + numberOfHosts)); Log.printLine(String.format("Number of VMs: " + numberOfVms)); Log.printLine(String.format("Total simulation time: %.2f sec", totalSimulationTime)); Log.printLine(String.format("Energy consumption: %.2f kWh", energy)); Log.printLine(String.format("Number of VM migrations: %d", numberOfMigrations)); Log.printLine(String.format("SLA: %.5f%%", sla * 100)); Log.printLine( String.format( "SLA perf degradation due to migration: %.2f%%", slaDegradationDueToMigration * 100)); Log.printLine(String.format("SLA time per active host: %.2f%%", slaTimePerActiveHost * 100)); Log.printLine(String.format("Overall SLA violation: %.2f%%", slaOverall * 100)); Log.printLine(String.format("Average SLA violation: %.2f%%", slaAverage * 100)); // Log.printLine(String.format("SLA time per VM with migration: %.2f%%", // slaTimePerVmWithMigration * 100)); // Log.printLine(String.format("SLA time per VM without migration: %.2f%%", // slaTimePerVmWithoutMigration * 100)); // Log.printLine(String.format("SLA time per host: %.2f%%", slaTimePerHost * 100)); Log.printLine(String.format("Number of host shutdowns: %d", numberOfHostShutdowns)); Log.printLine( String.format("Mean time before a host shutdown: %.2f sec", meanTimeBeforeHostShutdown)); Log.printLine( String.format( "StDev time before a host shutdown: %.2f sec", stDevTimeBeforeHostShutdown)); Log.printLine( String.format("Mean time before a VM migration: %.2f sec", meanTimeBeforeVmMigration)); Log.printLine( String.format("StDev time before a VM migration: %.2f sec", stDevTimeBeforeVmMigration)); if (datacenter.getVmAllocationPolicy() instanceof PowerVmAllocationPolicyMigrationAbstract) { PowerVmAllocationPolicyMigrationAbstract vmAllocationPolicy = (PowerVmAllocationPolicyMigrationAbstract) datacenter.getVmAllocationPolicy(); double executionTimeVmSelectionMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryVmSelection()); double executionTimeVmSelectionStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryVmSelection()); double executionTimeHostSelectionMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryHostSelection()); double executionTimeHostSelectionStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryHostSelection()); double executionTimeVmReallocationMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryVmReallocation()); double executionTimeVmReallocationStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryVmReallocation()); double executionTimeTotalMean = MathUtil.mean(vmAllocationPolicy.getExecutionTimeHistoryTotal()); double executionTimeTotalStDev = MathUtil.stDev(vmAllocationPolicy.getExecutionTimeHistoryTotal()); Log.printLine( String.format( "Execution time - VM selection mean: %.5f sec", executionTimeVmSelectionMean)); Log.printLine( String.format( "Execution time - VM selection stDev: %.5f sec", executionTimeVmSelectionStDev)); Log.printLine( String.format( "Execution time - host selection mean: %.5f sec", executionTimeHostSelectionMean)); Log.printLine( String.format( "Execution time - host selection stDev: %.5f sec", executionTimeHostSelectionStDev)); Log.printLine( String.format( "Execution time - VM reallocation mean: %.5f sec", executionTimeVmReallocationMean)); Log.printLine( String.format( "Execution time - VM reallocation stDev: %.5f sec", executionTimeVmReallocationStDev)); Log.printLine( String.format("Execution time - total mean: %.5f sec", executionTimeTotalMean)); Log.printLine( String.format("Execution time - total stDev: %.5f sec", executionTimeTotalStDev)); } Log.printLine(); } Log.setDisabled(true); }
public static void main(String[] args) { try { Log.disable(); // First step: Initialize the WorkflowSim package. /** Should change this based on real physical path */ String daxPath = "E:\\PhD\\ComplexCloudSim\\config\\dax\\Montage_1000.xml"; File daxFile = new File(daxPath); if (!daxFile.exists()) { Log.printLine( "Warning: Please replace daxPath with the physical path in your working environment!"); return; } Parameters.PlanningAlgorithm pln_method = Parameters.PlanningAlgorithm.INVALID; ReplicaCatalog.FileSystem file_system = ReplicaCatalog.FileSystem.SHARED; OverheadParameters op = new OverheadParameters(0, null, null, null, null, 0); ClusteringParameters.ClusteringMethod method = ClusteringParameters.ClusteringMethod.NONE; ClusteringParameters cp = new ClusteringParameters(0, 0, method, null); // For each scheduling algorithm (FCFS,RR,MinMin,MaxMin), run 100 times for (int sche = 0; sche < 4; sche++) { Parameters.SchedulingAlgorithm sch_method; switch (sche) { case 0: sch_method = Parameters.SchedulingAlgorithm.FCFS; break; case 1: sch_method = Parameters.SchedulingAlgorithm.ROUNDROBIN; break; case 2: sch_method = Parameters.SchedulingAlgorithm.MINMIN; break; case 3: sch_method = Parameters.SchedulingAlgorithm.MAXMIN; break; default: sch_method = Parameters.SchedulingAlgorithm.FCFS; } for (int runs = 0; runs < numRuns; runs++) { Parameters.init(numVMs, daxPath, null, null, op, cp, sch_method, pln_method, null, 0); ReplicaCatalog.init(file_system); // before creating any entities. int num_user = 1; // number of grid users Calendar calendar = Calendar.getInstance(); boolean trace_flag = false; // mean trace events // Initialize the CloudSim library CloudSim.init(num_user, calendar, trace_flag); ComplexDatacenter datacenter0 = createDatacenter("Datacenter_0"); /** Create a WorkflowPlanner with one schedulers. */ WorkflowPlanner wfPlanner = new WorkflowPlanner("planner_0", 1); /** Create a WorkflowEngine. */ WorkflowEngine wfEngine = wfPlanner.getWorkflowEngine(); /** * Create a list of VMs.The userId of a vm is basically the id of the scheduler that * controls this vm. */ List<ComplexVM> vmlist0 = createVM(wfEngine.getSchedulerId(0)); /** Submits this list of vms to this WorkflowEngine. */ wfEngine.submitVmList(vmlist0, 0); /** Binds the data centers with the scheduler. */ wfEngine.bindSchedulerDatacenter(datacenter0.getId(), 0); CloudSim.startSimulation(); List<Job> outputList0 = wfEngine.getJobsReceivedList(); CloudSim.stopSimulation(); switch (sche) { case 0: FCFSResult[runs] = wfEngine.getWorkflowFinishTime(); break; case 1: RoundRobinResult[runs] = wfEngine.getWorkflowFinishTime(); break; case 2: MinMinResult[runs] = wfEngine.getWorkflowFinishTime(); break; case 3: MaxMinResult[runs] = wfEngine.getWorkflowFinishTime(); break; default: FCFSResult[runs] = wfEngine.getWorkflowFinishTime(); break; } } Log.enable(); Log.printLine( "------ " + numVMs + " VMs " + numRuns + " Runs with Damage Ratio " + damageRatio + "------"); Log.printLine(">> FCFS"); printResult(FCFSResult); Log.printLine(">> RoundRobin"); printResult(RoundRobinResult); Log.printLine(">> MinMin"); printResult(MinMinResult); Log.printLine(">> MaxMin"); printResult(MaxMinResult); } } catch (Exception e) { Log.printLine("The simulation has been terminated due to an unexpected error"); } }