From cc3078a4e84d2678da0f57ad260818ff72192397 Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Sat, 22 Jun 2013 13:48:29 +0200 Subject: [PATCH] Adding debug count for started / stopped --- .../lsdc/management/MachineManager.java | 11 +++++ .../tuwien/lsdc/sched/AbstractScheduler.java | 12 ++++- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 44 +++++-------------- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 4 +- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 4 +- src/at/ac/tuwien/lsdc/types/ScenarioData.java | 11 ++--- .../ac/tuwien/lsdc/types/SchedulerData.java | 38 ++++++++-------- src/at/ac/tuwien/lsdc/util/CSVLogger.java | 5 ++- src/at/ac/tuwien/lsdc/util/NumberUtils.java | 6 +++ 9 files changed, 69 insertions(+), 66 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index 4a5c8fa..a120034 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -178,6 +178,17 @@ public class MachineManager { Collections.sort(sortedPMs); return sortedPMs; } + + /** + * sorting physical machines by resource utilization + * + * @return List of PMs sorted by resource utilization + */ + public List getRevSortedPMs() { + List revSortedPMs = getSortedPMs(); + Collections.reverse(revSortedPMs); + return revSortedPMs; + } public int getTotalPMs() { return totalPMs; diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 9cb795a..4e286a2 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -37,6 +37,8 @@ public abstract class AbstractScheduler { protected int numTotalOutSourced; protected int numCurrInSourced; protected int numCurrOutSourced; + protected int numStarted; + protected int numStopped; protected double totalConsumption; protected MachineManager manager; @@ -47,6 +49,7 @@ public abstract class AbstractScheduler { // List of Apps that were delayed due to not enough free resources. protected ArrayList delayedApps; + private int totalDelayedApps; /** * this map saves the following Type of Events: start of an Application, end of an * Application(start outSourced, end outSourced, start inSourced, end inSourced) @@ -216,6 +219,9 @@ public abstract class AbstractScheduler { * @param events the events to be read and used by the scheduler */ protected void handleEvents(HashMap> events) { + numStarted = 0; + numStopped = 0; + if (events.containsKey(EventType.endApplication)) handleEndEvents(events.get(EventType.endApplication)); if (events.containsKey(EventType.endOutsourcedApplication)) @@ -236,6 +242,7 @@ public abstract class AbstractScheduler { for (Application app : delayedApps) { SchedulerEvent evt = new SchedulerEvent(currTime, EventType.startApplication, app); delayedStartEvents.add(evt); + totalDelayedApps ++; } delayedApps.clear(); handleStartEvents(delayedStartEvents); @@ -309,7 +316,8 @@ public abstract class AbstractScheduler { SchedulerData data = new SchedulerData(currTime, manager.getTotalRam(), manager.getTotalCpu(), manager.getTotalSize(), manager.countCurrentlyRunningPMs(), manager.countCurrentlyRunningVMs(), manager.getCurrentConsumption(), - numCurrInSourced, numCurrOutSourced, MachineManager.getTotalResizeCalls(), delayedApps.size()); + numCurrInSourced, numCurrOutSourced, MachineManager.getTotalResizeCalls(), delayedApps.size(), + numStarted, numStopped); totalConsumption += manager.getCurrentConsumption(); try { logger.logSchedulerData(data); @@ -326,7 +334,7 @@ public abstract class AbstractScheduler { protected ScenarioData doEndLogging() { return new ScenarioData(getSchedulerType(), scenario.toString(), manager.getTotalPMs(), manager.getTotalVMs(), endTime, NumberUtils.roundDouble(totalConsumption), - numTotalInSourced, numTotalOutSourced, MachineManager.getTotalResizeCalls(), delayedApps.size()); + numTotalInSourced, numTotalOutSourced, MachineManager.getTotalResizeCalls(), totalDelayedApps); } protected abstract String getSchedulerType(); diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index cd9ad86..45afeb3 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -46,8 +46,9 @@ public class SchedulerA extends AbstractScheduler { log.warn("PM " + pm.getId() + " could not be stopped, " + e.getMessage()); } } - log.info("application stopped at timestamp " + currTime + ", " + "vm " - + vm.getPositionOnPM() + ", pm " + pm.getId()); + numStopped ++; +// log.info("application stopped at timestamp " + currTime + ", " + "vm " +// + vm.getPositionOnPM() + ", pm " + pm.getId()); } catch (ActiveApplicationsException e) { log.warn("VM " + vm.getId() + "could not be stopped, " + e.getMessage()); } @@ -65,45 +66,24 @@ public class SchedulerA extends AbstractScheduler { if (manager.getPMs().size() == 0) { PhysicalMachine pm = manager.startPhysicalMachine(); - boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); - if (enoughResources) { + if (pm.checkVM(app.getSize(), app.getRam(), app.getCpu())) appDeployed = startApp(pm, app); -// log.info("Application " + app.toString() + " started on new pm " + pm.getId()); - } else { -// log.info("Application " + app.toString() + " cannot be run on pm " -// + pm.getId() + ", too little space"); - } + } else { - // sorting physical machines by resource utilization - // (descending) - List sortedPMs = manager.getSortedPMs(); - Collections.reverse(sortedPMs); - - for (PhysicalMachine pm : sortedPMs) { + // sorting physical machines by resource utilization (descending) + List revSortedPMs = manager.getRevSortedPMs(); - boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); - - if (enoughResources) { + for (PhysicalMachine pm : revSortedPMs) { + if (pm.checkVM(app.getSize(), app.getRam(), app.getCpu())) { appDeployed = startApp(pm, app); -// log.info("Application " + app.toString() + " started new vm " -// + pm.getLatestVMID() + " on pm " + pm.getId()); break; } } if (!appDeployed && (manager.getPMs().size() < manager.getMaxPMs())) { - PhysicalMachine pm = manager.startPhysicalMachine(); - boolean enoughResources = pm.checkVM(app.getSize(), app.getRam(), app.getCpu()); - - if (enoughResources) { + if (pm.checkVM(app.getSize(), app.getRam(), app.getCpu())) appDeployed = startApp(pm, app); -// log.info("Application " + app.toString() + " started on new pm " -// + pm.getId()); - } else { -// log.warn("Application " + app.toString() + " cannot be run on pm " -// + pm.getId() + ", too little space"); - } } } if (!appDeployed) { @@ -114,6 +94,7 @@ public class SchedulerA extends AbstractScheduler { delayedApps.add(app); } if(appDeployed) { + numStarted ++; if(manager.countCurrentlyRunningPMs() < manager.getMaxPMs()) { Application application = federation.askToInsource(); if(application != null) { @@ -121,10 +102,7 @@ public class SchedulerA extends AbstractScheduler { } } } -// else -// log.warn("Application " + app.toString() + " could not be deployed on any pm"); } - } private boolean startApp(PhysicalMachine pm, Application app) { diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index db30b3f..b445c6c 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -101,8 +101,8 @@ public class SchedulerB extends AbstractSchedulerWithMigration { for (SchedulerEvent evt : events) { deployed = false; VirtualMachine vm = null; - List sortedPMs = manager.getSortedPMs(); - Collections.reverse(sortedPMs); + List sortedPMs = manager.getRevSortedPMs(); + for (PhysicalMachine pm : sortedPMs) { if (pm.isRunning() && (pm.countCurrentlyRunningVMs() > 0)) { vm = pm.getVirtualMachines().values().iterator().next(); diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index c4d7729..0932ec2 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -76,8 +76,8 @@ public class SchedulerC extends AbstractSchedulerWithMigration { for (SchedulerEvent evt : events) { deployed = false; VirtualMachine vm = null; - List sortedPMs = manager.getSortedPMs(); - Collections.reverse(sortedPMs); + List sortedPMs = manager.getRevSortedPMs(); + for (PhysicalMachine pm : sortedPMs) { if (pm.isRunning() && (pm.countCurrentlyRunningVMs() > 0)) { vm = pm.getVirtualMachines().values().iterator().next(); diff --git a/src/at/ac/tuwien/lsdc/types/ScenarioData.java b/src/at/ac/tuwien/lsdc/types/ScenarioData.java index dd02c52..8d3ae02 100644 --- a/src/at/ac/tuwien/lsdc/types/ScenarioData.java +++ b/src/at/ac/tuwien/lsdc/types/ScenarioData.java @@ -11,7 +11,7 @@ public class ScenarioData { private int totalInSourced; private int totalOutSourced; private int totalResizeCalls; - private int delayedApps; + private int totalDelayedApps; public ScenarioData(String scheduler, String scenario, long totalPMs, long totalVMs, long totalDuration, double totalConsumption, @@ -31,7 +31,7 @@ public class ScenarioData { public ScenarioData(String scheduler, String scenario, long totalPMs, long totalVMs, long totalDuration, double totalConsumption, int totalInSourced, int totalOutSourced, - int totalResizeCalls, int delayedApps) { + int totalResizeCalls, int totalDelayedApps) { this.scheduler = scheduler; this.scenario = scenario; this.totalPMs = totalPMs; @@ -41,13 +41,13 @@ public class ScenarioData { this.totalInSourced = totalInSourced; this.totalOutSourced = totalOutSourced; this.totalResizeCalls = totalResizeCalls; - this.delayedApps = delayedApps; + this.totalDelayedApps = totalDelayedApps; } public String[] toStringArray() { return new String[] { scheduler, scenario, String.valueOf(totalPMs), String.valueOf(totalVMs), String.valueOf(totalDuration), String.valueOf(totalConsumption), String.valueOf(totalInSourced), - String.valueOf(totalOutSourced), String.valueOf(totalResizeCalls), String.valueOf(delayedApps) }; + String.valueOf(totalOutSourced), String.valueOf(totalResizeCalls), String.valueOf(totalDelayedApps) }; } @Override @@ -57,7 +57,8 @@ public class ScenarioData { + totalVMs + ", totalDuration=" + totalDuration + ", totalConsumption=" + totalConsumption + ", totalInSourced=" + totalInSourced + ", totalOutSourced=" - + totalOutSourced + "]"; + + totalOutSourced + ", totalResizeCalls=" + totalResizeCalls + + ", delayedApps=" + totalDelayedApps + "]"; } } diff --git a/src/at/ac/tuwien/lsdc/types/SchedulerData.java b/src/at/ac/tuwien/lsdc/types/SchedulerData.java index becf72e..c62cd58 100644 --- a/src/at/ac/tuwien/lsdc/types/SchedulerData.java +++ b/src/at/ac/tuwien/lsdc/types/SchedulerData.java @@ -13,6 +13,8 @@ public class SchedulerData { private int outSourced; private int totalResized; private int delayedApps; + private int started; + private int stopped; public SchedulerData(long timestamp, long totalRAM, long totalCPU, long totalSize, long runningPMs, long runningVMs, @@ -31,33 +33,28 @@ public class SchedulerData { public SchedulerData(long timestamp, long totalRAM, long totalCPU, long totalSize, long runningPMs, long runningVMs, double totalConsumption, int inSourced, int outSourced, int totalResized) { - this.timestamp = timestamp; - this.totalRAM = totalRAM; - this.totalCPU = totalCPU; - this.totalSize = totalSize; - this.runningPMs = runningPMs; - this.runningVMs = runningVMs; - this.totalConsumption = totalConsumption; - this.inSourced = inSourced; - this.outSourced = outSourced; + + this(timestamp, totalRAM, totalCPU, totalSize, runningPMs, runningVMs, totalConsumption, inSourced, outSourced); this.totalResized = totalResized; } public SchedulerData(long timestamp, long totalRAM, long totalCPU, long totalSize, long runningPMs, long runningVMs, double totalConsumption, int inSourced, int outSourced, int totalResized, int delayedApps) { - this.timestamp = timestamp; - this.totalRAM = totalRAM; - this.totalCPU = totalCPU; - this.totalSize = totalSize; - this.runningPMs = runningPMs; - this.runningVMs = runningVMs; - this.totalConsumption = totalConsumption; - this.inSourced = inSourced; - this.outSourced = outSourced; - this.totalResized = totalResized; + + this(timestamp, totalRAM, totalCPU, totalSize, runningPMs, runningVMs, totalConsumption, inSourced, outSourced, totalResized); this.delayedApps = delayedApps; } + + public SchedulerData(long timestamp, long totalRAM, long totalCPU, + long totalSize, long runningPMs, long runningVMs, + double totalConsumption, int inSourced, int outSourced, int totalResized, int delayedApps, int started, int stopped) { + + this(timestamp, totalRAM, totalCPU, totalSize, runningPMs, runningVMs, totalConsumption, inSourced, outSourced, + totalResized, delayedApps); + this.started = started; + this.stopped = stopped; + } public String[] toStringArray() { return new String[] { String.valueOf(timestamp), @@ -65,7 +62,8 @@ public class SchedulerData { String.valueOf(totalSize), String.valueOf(runningPMs), String.valueOf(runningVMs), String.valueOf(totalConsumption), String.valueOf(inSourced), String.valueOf(outSourced), - String.valueOf(totalResized), String.valueOf(delayedApps)}; + String.valueOf(totalResized), String.valueOf(delayedApps), + String.valueOf(started), String.valueOf(stopped)}; } @Override diff --git a/src/at/ac/tuwien/lsdc/util/CSVLogger.java b/src/at/ac/tuwien/lsdc/util/CSVLogger.java index a9d2cce..f5bf6b3 100644 --- a/src/at/ac/tuwien/lsdc/util/CSVLogger.java +++ b/src/at/ac/tuwien/lsdc/util/CSVLogger.java @@ -34,13 +34,14 @@ public class CSVLogger { private void writeScenarioDataHeader() throws IOException { String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs", "TotalVMs", "TotalDuration", "TotalPowerConsumption", "TotalInSourced", "TotalOutSourced", - "TotalResizeEvents" }; + "TotalResizeEvents", "TotalDelayedApps" }; writeCSVLine(header); } private void writeSchedulerDataHeader() throws IOException { String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU", "TotalSize", - "RunningPMs", "RunningVMs", "TotalPowerConsumption", "InSourced", "OutSourced" }; + "RunningPMs", "RunningVMs", "TotalPowerConsumption", "InSourced", "OutSourced", + "TotalResizes", "DelayedApps", "Started", "Stopped"}; writeCSVLine(header); } diff --git a/src/at/ac/tuwien/lsdc/util/NumberUtils.java b/src/at/ac/tuwien/lsdc/util/NumberUtils.java index 6eb1698..c86b2ae 100644 --- a/src/at/ac/tuwien/lsdc/util/NumberUtils.java +++ b/src/at/ac/tuwien/lsdc/util/NumberUtils.java @@ -1,9 +1,15 @@ package at.ac.tuwien.lsdc.util; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class NumberUtils { + private static final Logger LOG = LoggerFactory.getLogger(NumberUtils.class); + public static double roundDouble(double val) { + LOG.info("value = "+val); + return Math.floor(val * 100) / 100; } -- 2.43.0