Adding insourcing of events
authorAndreas Egger <egger.andreas.1@gmail.com>
Thu, 20 Jun 2013 12:21:46 +0000 (14:21 +0200)
committerAndreas Egger <egger.andreas.1@gmail.com>
Thu, 20 Jun 2013 12:21:46 +0000 (14:21 +0200)
build.xml
src/at/ac/tuwien/lsdc/federation/Federation.java
src/at/ac/tuwien/lsdc/sched/AbstractScheduler.java
src/at/ac/tuwien/lsdc/sched/SchedulerA.java
src/at/ac/tuwien/lsdc/sched/SchedulerB.java
src/at/ac/tuwien/lsdc/sched/SchedulerC.java
src/at/ac/tuwien/lsdc/types/SchedulerEvent.java

index 4cdc7f15cdf64db7973b2906fd2047575be0e8ff..581f328e7fa339094565f69fe6bea9b21359c2ff 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -7,8 +7,8 @@
        <property name="log.dir" value="logs" />\r
        <property name="scen.dir" value="scenarios" />\r
 \r
-       <property name="numPMs" value="2" />\r
-       <property name="numCloudPartners" value="3" />\r
+       <property name="numPMs" value="15" />\r
+       <property name="numCloudPartners" value="0" />\r
 \r
        <path id="project.classpath">\r
                <dirset dir="${build.dir}" />\r
                        <arg value="A" />\r
                        <arg value="${numPMs}" />\r
                        <arg value="${numCloudPartners}" />\r
-                       <arg value="scenarios/scenarioA.csv" />\r
+                       <arg value="scenarios/A.csv" />\r
                        <arg value="logs/all.csv" />\r
                        <arg value="logs/schedulerC_scenarioA.csv" />\r
                </java>\r
                        <arg value="B" />\r
                        <arg value="${numPMs}" />\r
                        <arg value="${numCloudPartners}" />\r
-                       <arg value="scenarios/scenarioB.csv" />\r
+                       <arg value="scenarios/B.csv" />\r
                        <arg value="logs/all.csv" />\r
                        <arg value="logs/schedulerC_scenarioB.csv" />\r
                </java>\r
                        <arg value="C" />\r
                        <arg value="${numPMs}" />\r
                        <arg value="${numCloudPartners}" />\r
-                       <arg value="scenarios/scenarioC.csv" />\r
+                       <arg value="scenarios/C.csv" />\r
                        <arg value="logs/all.csv" />\r
                        <arg value="logs/schedulerC_scenarioC.csv" />\r
                </java>\r
        </target>\r
 \r
+       <target name="run-scheduler-C-D" depends="compile" description="Run scheduler C on scenario C">\r
+                       <java classname="at.ac.tuwien.lsdc.SchedSimulator" fork="true" classpathref="project.classpath">\r
+                               <assertions refid="project.assertions" />\r
+                               <arg value="C" />\r
+                               <arg value="C" />\r
+                               <arg value="${numPMs}" />\r
+                               <arg value="${numCloudPartners}" />\r
+                               <arg value="scenarios/D.csv" />\r
+                               <arg value="logs/all.csv" />\r
+                               <arg value="logs/schedulerC_scenarioD.csv" />\r
+                       </java>\r
+               </target>\r
 \r
        <target name="run-all-schedulers" depends="run-scheduler-A-A, run-scheduler-A-B, run-scheduler-A-C, run-scheduler-B-A, run-scheduler-B-B, run-scheduler-B-C, run-scheduler-C-A, run-scheduler-C-B, run-scheduler-C-C" description="Run all schedulers and all scenarios">\r
        </target>\r
index ad60a6b3f6ad37b141a855e68b298449a886623b..7fdb79e68e4fd88c2d2f003bf700645d411e5d1a 100644 (file)
@@ -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;
        }
 }
index 7998823fafe40f4812e684d7ada54c8a0e1a82b2..217c83860a6463a62a1feb006ceef208dd521def 100644 (file)
@@ -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<SchedulerEvent> 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<SchedulerEvent> 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<SchedulerEvent> 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;
+       }
 
 }
index f65e699609ea83eb4851bec48d70ee4c133f1423..15db35cfe9f040b0a82990fe8c3f297a69cf5871 100644 (file)
@@ -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");
                }
 
index 949aa2344690dece0b1e6f494ae62a37e8746e97..be8c6011b2cfb09791362014c28d127dd83cd231 100644 (file)
@@ -67,7 +67,7 @@ public class SchedulerB extends AbstractSchedulerWithMigration {
         */
        @Override
        protected void handleEndEvents(LinkedList<SchedulerEvent> 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<SchedulerEvent> 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());
+                                       }
+                               }
+                       }
                }
        }
 
index 173d353dd255d6ecc1fda9b640dc2bb40b45cf47..20ef92a0ea8f00232a2098ce7fe6fff49360f9ed 100644 (file)
@@ -49,7 +49,7 @@ public class SchedulerC extends AbstractSchedulerWithMigration {
         */
        @Override
        protected void handleEndEvents(LinkedList<SchedulerEvent> 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<SchedulerEvent> 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());
+                                       }
+                               }
+                       }
                }
        }
 
index 11f21ba8270a4ff9b21b97f81c67c217774ef4cb..eafaa2b487b1294219f4375b9b5ef6c2d21c18eb 100644 (file)
@@ -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;