From 114c67500682c7849c28f16e06b57d9f684fb42f Mon Sep 17 00:00:00 2001 From: Andreas Egger Date: Thu, 20 Jun 2013 14:21:46 +0200 Subject: [PATCH] Adding insourcing of events --- build.xml | 22 +++++-- .../ac/tuwien/lsdc/federation/Federation.java | 19 ++++-- .../tuwien/lsdc/sched/AbstractScheduler.java | 64 ++++++++++++++++++- src/at/ac/tuwien/lsdc/sched/SchedulerA.java | 28 +++++--- src/at/ac/tuwien/lsdc/sched/SchedulerB.java | 14 +++- src/at/ac/tuwien/lsdc/sched/SchedulerC.java | 14 +++- .../ac/tuwien/lsdc/types/SchedulerEvent.java | 2 +- 7 files changed, 133 insertions(+), 30 deletions(-) diff --git a/build.xml b/build.xml index 4cdc7f1..581f328 100644 --- a/build.xml +++ b/build.xml @@ -7,8 +7,8 @@ - - + + @@ -162,7 +162,7 @@ - + @@ -175,7 +175,7 @@ - + @@ -188,12 +188,24 @@ - + + + + + + + + + + + + + diff --git a/src/at/ac/tuwien/lsdc/federation/Federation.java b/src/at/ac/tuwien/lsdc/federation/Federation.java index ad60a6b..7fdb79e 100644 --- a/src/at/ac/tuwien/lsdc/federation/Federation.java +++ b/src/at/ac/tuwien/lsdc/federation/Federation.java @@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory; import at.ac.tuwien.lsdc.JobGenerator; import at.ac.tuwien.lsdc.SchedSimulator; +import at.ac.tuwien.lsdc.sched.AbstractScheduler; import at.ac.tuwien.lsdc.sched.SchedulerB; import at.ac.tuwien.lsdc.types.Application; @@ -35,9 +36,10 @@ public class Federation { * @return true, if application can be outsourced. */ public boolean askToOutsource(Application app) { - LOG.info("askToOutsource():" + app); - if ((Math.random() * 100) < (10 * numPartners)) + if ((Math.random() * 100) < (10 * numPartners)) { + LOG.info("Outsource:" + app); return true; + } return false; } @@ -48,33 +50,36 @@ public class Federation { */ @SuppressWarnings("unused") public Application askToInsource() { - LOG.info("askToOutsource()"); int size; int ram; int cpu; int duration; + + long timestamp = AbstractScheduler.getCurrentTime() + JobGenerator.randomInt(1, 3); - if ((Math.random() * 100) < (10 * numPartners) && false) + if ((Math.random() * 100) < (10 * numPartners)) { + LOG.info("Insource app "); switch (SchedSimulator.getScenario()) { case A : size = JobGenerator.randomInt(20, 100); ram = JobGenerator.randomInt(30, 50); cpu = JobGenerator.randomInt(50, 100); duration = JobGenerator.randomInt(1, 50); - return new Application(0, size, ram, cpu, duration); + return new Application(timestamp, size, ram, cpu, duration); case B : size = JobGenerator.randomInt(150, 500); ram = JobGenerator.randomInt(100, 700); cpu = JobGenerator.randomInt(100, 400); duration = JobGenerator.randomInt(1, 50); - return new Application(0, size, ram, cpu, duration); + return new Application(timestamp, size, ram, cpu, duration); default : size = JobGenerator.randomInt(20, 500); ram = JobGenerator.randomInt(30, 700); cpu = JobGenerator.randomInt(50, 400); duration = JobGenerator.randomInt(1, 50); - return new Application(0, size, ram, cpu, duration); + return new Application(timestamp, size, ram, cpu, duration); } + } return null; } } diff --git a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java index 7998823..217c838 100644 --- a/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java +++ b/src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java @@ -57,7 +57,7 @@ public abstract class AbstractScheduler { * Scheduler has an internal Time "Abstraction" at every point in time it checks for Events in * his "EventList" and handles them (via the individual scheduling algorithm) */ - protected long currTime = 0; + protected static long currTime = 0; /** * the timestamp at which the Scheduler is finished it is updated with every added "EndEvent" @@ -117,6 +117,18 @@ public abstract class AbstractScheduler { app); insertEvent(evt); } + + /** + * Insert a start insourced event into the map, at timestamp when the application should start + * + * @param timestamp the timestamp when the application should start + * @param app the application to start + */ + protected void insertInsourcedStartEvent(long timestamp, Application app) { + SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.startInsourcedApplication, + app); + insertEvent(evt); + } /** * Insert a stop event into the map, at timestamp when the application should stop. @@ -145,6 +157,20 @@ public abstract class AbstractScheduler { endTime = timestamp; } } + + /** + * Insert a stop event into the map, at timestamp when the application should stop. + * + * @param timestamp the timestamp when the application should stop + * @param app the application to stop + */ + protected void insertInsourcedStopEvent(long timestamp, Application app) { + SchedulerEvent evt = new SchedulerEvent(timestamp, EventType.endInsourcedApplication, app); + insertEvent(evt); + if (endTime < timestamp) { + endTime = timestamp; + } + } private void insertEvent(SchedulerEvent evt) { LinkedList list; @@ -194,11 +220,15 @@ public abstract class AbstractScheduler { handleEndEvents(events.get(EventType.endApplication)); if (events.containsKey(EventType.endOutsourcedApplication)) handleOutsourcedEndEvents(events.get(EventType.endOutsourcedApplication)); + if (events.containsKey(EventType.endInsourcedApplication)) + handleInsourcedEndEvents(events.get(EventType.endInsourcedApplication)); handleDelayedApps(); if (events.containsKey(EventType.startOutsourcedApplication)) handleOutsourcedStartEvents(events.get(EventType.startOutsourcedApplication)); if (events.containsKey(EventType.startApplication)) handleStartEvents(events.get(EventType.startApplication)); + if (events.containsKey(EventType.startInsourcedApplication)) + handleInsourcedStartEvents(events.get(EventType.startInsourcedApplication)); } protected void handleDelayedApps() { @@ -229,6 +259,21 @@ public abstract class AbstractScheduler { } } } + + /** + * handle running of outsourced apps. + * + * @param events list of all events that happened in this timeslot. + */ + protected void handleInsourcedStartEvents(LinkedList events) { + for (SchedulerEvent evt : events) { + if (evt.getType() == EventType.startInsourcedApplication) { + insertInsourcedStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); + numCurrInSourced++; + numTotalInSourced++; + } + } + } /** * handle stopping of outsourced apps. @@ -242,6 +287,19 @@ public abstract class AbstractScheduler { } } } + + /** + * handle stopping of outsourced apps. + * + * @param events list of all events that happened in this timeslot. + */ + protected void handleInsourcedEndEvents(LinkedList events) { + for (SchedulerEvent evt : events) { + if (evt.getType() == EventType.endInsourcedApplication) { + numCurrInSourced--; + } + } + } /** * Does the logging for each timestamp. It uses the CSVLogger to write directly to the specific @@ -272,5 +330,9 @@ public abstract class AbstractScheduler { } protected abstract String getSchedulerType(); + + public static long getCurrentTime() { + return currTime; + } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java index f65e699..15db35c 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerA.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerA.java @@ -69,10 +69,10 @@ public class SchedulerA extends AbstractScheduler { if (enoughResources) { appDeployed = startApp(pm, app); - log.info("Application " + app.toString() + " started on new pm " + pm.getId()); +// 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"); +// log.info("Application " + app.toString() + " cannot be run on pm " +// + pm.getId() + ", too little space"); } } else { // sorting physical machines by resource utilization @@ -86,8 +86,8 @@ public class SchedulerA extends AbstractScheduler { if (enoughResources) { appDeployed = startApp(pm, app); - log.info("Application " + app.toString() + " started new vm " - + pm.getLatestVMID() + " on pm " + pm.getId()); +// log.info("Application " + app.toString() + " started new vm " +// + pm.getLatestVMID() + " on pm " + pm.getId()); break; } } @@ -98,11 +98,11 @@ public class SchedulerA extends AbstractScheduler { if (enoughResources) { appDeployed = startApp(pm, app); - log.info("Application " + app.toString() + " started on new pm " - + pm.getId()); +// 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"); +// log.warn("Application " + app.toString() + " cannot be run on pm " +// + pm.getId() + ", too little space"); } } } @@ -113,7 +113,15 @@ public class SchedulerA extends AbstractScheduler { } else delayedApps.add(app); } - if (!appDeployed) + if(appDeployed) { + if(manager.countCurrentlyRunningPMs() < manager.getMaxPMs()) { + Application application = federation.askToInsource(); + if(application != null) { + insertInsourcedStartEvent(currTime + 1, application); + } + } + } + else log.warn("Application " + app.toString() + " could not be deployed on any pm"); } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java index 949aa23..be8c601 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerB.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerB.java @@ -67,7 +67,7 @@ public class SchedulerB extends AbstractSchedulerWithMigration { */ @Override protected void handleEndEvents(LinkedList events) { - LOG.debug("stopApps():" + events); +// LOG.debug("stopApps():" + events); for (SchedulerEvent evt : events) { VirtualMachine vm = evt.getApp().getRunningOn(); evt.getApp().setRunningOn(null); @@ -90,7 +90,7 @@ public class SchedulerB extends AbstractSchedulerWithMigration { */ @Override protected void handleStartEvents(LinkedList events) { - LOG.debug("startApps():" + events); +// LOG.debug("startApps():" + events); boolean deployed = false; for (SchedulerEvent evt : events) { deployed = false; @@ -120,8 +120,16 @@ public class SchedulerB extends AbstractSchedulerWithMigration { } } } - if (deployed) + if (deployed) { insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); + + if(manager.countCurrentlyRunningPMs() < manager.getMaxPMs()) { + Application app = federation.askToInsource(); + if(app != null) { + insertInsourcedStartEvent(currTime + 1, evt.getApp()); + } + } + } } } diff --git a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java index 173d353..20ef92a 100644 --- a/src/at/ac/tuwien/lsdc/sched/SchedulerC.java +++ b/src/at/ac/tuwien/lsdc/sched/SchedulerC.java @@ -49,7 +49,7 @@ public class SchedulerC extends AbstractSchedulerWithMigration { */ @Override protected void handleEndEvents(LinkedList events) { - LOG.debug("stopApps():" + events); +// LOG.debug("stopApps():" + events); for (SchedulerEvent evt : events) { VirtualMachine vm = evt.getApp().getRunningOn(); evt.getApp().setRunningOn(null); @@ -72,7 +72,7 @@ public class SchedulerC extends AbstractSchedulerWithMigration { */ @Override protected void handleStartEvents(LinkedList events) { - LOG.debug("startApps():" + events); +// LOG.debug("startApps():" + events); boolean deployed = false; for (SchedulerEvent evt : events) { deployed = false; @@ -102,8 +102,16 @@ public class SchedulerC extends AbstractSchedulerWithMigration { } } } - if (deployed) + if (deployed) { insertStopEvent(currTime + evt.getApp().getDuration(), evt.getApp()); + + if(manager.countCurrentlyRunningPMs() < manager.getMaxPMs()) { + Application app = federation.askToInsource(); + if(app != null) { + insertInsourcedStartEvent(currTime + 1, evt.getApp()); + } + } + } } } diff --git a/src/at/ac/tuwien/lsdc/types/SchedulerEvent.java b/src/at/ac/tuwien/lsdc/types/SchedulerEvent.java index 11f21ba..eafaa2b 100644 --- a/src/at/ac/tuwien/lsdc/types/SchedulerEvent.java +++ b/src/at/ac/tuwien/lsdc/types/SchedulerEvent.java @@ -3,7 +3,7 @@ package at.ac.tuwien.lsdc.types; public class SchedulerEvent { public enum EventType { - startApplication, endApplication, startOutsourcedApplication, endOutsourcedApplication + startApplication, endApplication, startOutsourcedApplication, endOutsourcedApplication, startInsourcedApplication, endInsourcedApplication }; final private long timestamp; -- 2.43.0