From bfff9085eb2365a6ffc9e3a3add405cbed47b7d1 Mon Sep 17 00:00:00 2001 From: Stefan Derkits Date: Thu, 20 Jun 2013 15:18:45 +0200 Subject: [PATCH] log resize events --- .../lsdc/management/MachineManager.java | 7 +++++ .../tuwien/lsdc/sched/AbstractScheduler.java | 12 ++++----- .../ac/tuwien/lsdc/types/PhysicalMachine.java | 6 +++++ src/at/ac/tuwien/lsdc/types/ScenarioData.java | 7 +++-- .../ac/tuwien/lsdc/types/VirtualMachine.java | 26 ++++++++++++------- src/at/ac/tuwien/lsdc/util/CSVLogger.java | 14 +++++----- 6 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/at/ac/tuwien/lsdc/management/MachineManager.java b/src/at/ac/tuwien/lsdc/management/MachineManager.java index 044d44b..fe5f282 100644 --- a/src/at/ac/tuwien/lsdc/management/MachineManager.java +++ b/src/at/ac/tuwien/lsdc/management/MachineManager.java @@ -24,6 +24,7 @@ public class MachineManager { private int totalPMs = 0; private int totalVMs = 0; + private int totalResizeCalls = 0; public MachineManager(int numPMs) { this.numPMs = numPMs; @@ -58,6 +59,7 @@ public class MachineManager { PhysicalMachine pm = PMs.get(id); totalVMs += pm.getTotalVMs(); pm.stop(); + totalResizeCalls += pm.getTotalResizeCalls(); PMs.remove(id); } } @@ -184,4 +186,9 @@ public class MachineManager { public int getTotalVMs() { return totalVMs; } + + public int getTotalResizeCalls() { + return totalResizeCalls; + } + } diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 217c838..db020b9 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -117,7 +117,7 @@ public abstract class AbstractScheduler { app); insertEvent(evt); } - + /** * Insert a start insourced event into the map, at timestamp when the application should start * @@ -157,7 +157,7 @@ public abstract class AbstractScheduler { endTime = timestamp; } } - + /** * Insert a stop event into the map, at timestamp when the application should stop. * @@ -259,7 +259,7 @@ public abstract class AbstractScheduler { } } } - + /** * handle running of outsourced apps. * @@ -287,7 +287,7 @@ public abstract class AbstractScheduler { } } } - + /** * handle stopping of outsourced apps. * @@ -326,11 +326,11 @@ public abstract class AbstractScheduler { protected ScenarioData doEndLogging() { return new ScenarioData(getSchedulerType(), scenario.toString(), manager.getTotalPMs(), manager.getTotalVMs(), endTime, NumberUtils.roundDouble(totalConsumption), - numTotalInSourced, numTotalOutSourced); + numTotalInSourced, numTotalOutSourced, manager.getTotalResizeCalls()); } protected abstract String getSchedulerType(); - + public static long getCurrentTime() { return currTime; } diff --git a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java index 1c87df8..f159cb8 100644 --- a/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java +++ b/src/at/ac/tuwien/lsdc/types/PhysicalMachine.java @@ -33,6 +33,7 @@ public class PhysicalMachine implements Comparable { private final int initialCPU = 500; private int totalVMs = 0; + private int totalResizeCalls = 0; private boolean running = false; @@ -97,6 +98,7 @@ public class PhysicalMachine implements Comparable { reservedSize = reservedSize - vm.getReservedSize(); reservedRAM = reservedRAM - vm.getReservedRAM(); reservedCPU = reservedCPU - vm.getReservedCPU(); + totalResizeCalls += vm.getTotalResizeCalls(); } } } @@ -234,6 +236,10 @@ public class PhysicalMachine implements Comparable { return totalVMs; } + public int getTotalResizeCalls() { + return totalResizeCalls; + } + @Override public int compareTo(PhysicalMachine other) { if (this == other) diff --git a/src/at/ac/tuwien/lsdc/types/ScenarioData.java b/src/at/ac/tuwien/lsdc/types/ScenarioData.java index e49938d..1aa1c10 100644 --- a/src/at/ac/tuwien/lsdc/types/ScenarioData.java +++ b/src/at/ac/tuwien/lsdc/types/ScenarioData.java @@ -10,10 +10,12 @@ public class ScenarioData { private double totalConsumption; private int totalInSourced; private int totalOutSourced; + private int totalResizeCalls; public ScenarioData(String scheduler, String scenario, long totalPMs, long totalVMs, long totalDuration, double totalConsumption, - int totalInSourced, int totalOutSourced) { + int totalInSourced, int totalOutSourced, + int totalResizeCalls) { this.scheduler = scheduler; this.scenario = scenario; this.totalPMs = totalPMs; @@ -22,12 +24,13 @@ public class ScenarioData { this.totalConsumption = totalConsumption; this.totalInSourced = totalInSourced; this.totalOutSourced = totalOutSourced; + this.totalResizeCalls = totalResizeCalls; } 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(totalOutSourced), String.valueOf(totalResizeCalls) }; } @Override diff --git a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java index 747f407..3803e43 100644 --- a/src/at/ac/tuwien/lsdc/types/VirtualMachine.java +++ b/src/at/ac/tuwien/lsdc/types/VirtualMachine.java @@ -30,6 +30,8 @@ public class VirtualMachine { private VMType type; + private int totalResizeCalls = 0; + public VirtualMachine(int size, int RAM, int CPU, PhysicalMachine pm, VMType type) { id = count; count++; @@ -70,35 +72,37 @@ public class VirtualMachine { // reservedRAM = initialRAM + newRAM; // reservedCPU = initialCPU + newCPU; // return true; -// } else +// } else // return false; //// throw new VMResizeException("Could not resize VM!", this); // } - + public boolean resizeUp(Application app) throws VMResizeException { - + int diffSize = (app.getSize() - availableSize()); int diffRAM = (app.getRam() - availableRAM()); int diffCPU = (app.getCpu() - availableCPU()); - - if(!(type == VMType.Resizable) || !runningOn.checkExtendVM(diffSize, diffRAM, diffCPU)) { + + if(!(type == VMType.Resizable) || !runningOn.checkExtendVM(diffSize, diffRAM, diffCPU)) { throw new VMResizeException("Could not resize VM!", this); } - + runningOn.resizeUp(diffSize, diffRAM, diffCPU); - + reservedSize = reservedSize + diffSize; reservedRAM = reservedRAM + diffRAM; reservedCPU = reservedCPU + diffCPU; + totalResizeCalls++; return true; } - + public boolean resizeDown(Application app) { runningOn.resizeDown(app); - + reservedSize = reservedSize - app.getSize(); reservedRAM = reservedRAM - app.getRam(); reservedCPU = reservedCPU - app.getCpu(); + totalResizeCalls++; return true; } @@ -175,6 +179,10 @@ public class VirtualMachine { return reservedCPU; } + public int getTotalResizeCalls() { + return totalResizeCalls; + } + @Override public String toString() { return "VirtualMachine [posOnPM=" + posOnPM + ", runningOn=" + runningOn + ", id=" + id + ", reservedSize=" diff --git a/src/at/ac/tuwien/lsdc/util/CSVLogger.java b/src/at/ac/tuwien/lsdc/util/CSVLogger.java index 54604f4..a9d2cce 100644 --- a/src/at/ac/tuwien/lsdc/util/CSVLogger.java +++ b/src/at/ac/tuwien/lsdc/util/CSVLogger.java @@ -32,22 +32,20 @@ public class CSVLogger { } private void writeScenarioDataHeader() throws IOException { - String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs", - "TotalVMs", "TotalDuration", "TotalPowerConsumption", - "TotalInSourced", "TotalOutSourced" }; + String[] header = new String[] { "Scheduler", "Scenario", "TotalPMs", "TotalVMs", + "TotalDuration", "TotalPowerConsumption", "TotalInSourced", "TotalOutSourced", + "TotalResizeEvents" }; writeCSVLine(header); } private void writeSchedulerDataHeader() throws IOException { - String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU", - "TotalSize", "RunningPMs", "RunningVMs", - "TotalPowerConsumption", "InSourced", "OutSourced" }; + String[] header = new String[] { "Timestamp", "TotalRAM", "TotalCPU", "TotalSize", + "RunningPMs", "RunningVMs", "TotalPowerConsumption", "InSourced", "OutSourced" }; writeCSVLine(header); } private void writeCSVLine(String[] arr) throws IOException { - PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( - file, true))); + PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file, true))); StringBuilder csvBuilder = new StringBuilder(); for (String s : arr) { -- 2.43.0