changes
authorbdemsky <bdemsky>
Sun, 10 Jan 2010 06:24:17 +0000 (06:24 +0000)
committerbdemsky <bdemsky>
Sun, 10 Jan 2010 06:24:17 +0000 (06:24 +0000)
Robust/TransSim/FileSim.java
Robust/TransSim/FlexScheduler.java

index 4e979a94cedb393a4aca9c9b88b19a9347f3489c..05bee9a734bb2358d2b707000331b35cd954267e 100644 (file)
@@ -1,16 +1,5 @@
 public class FileSim {
-  public static void main(String[] args) throws Exception {
-    //time between transactions
-    //split objects
-    int splitobjects=100;//10 percent of objects special
-    int splitaccesses=100;//40 percent of accesses to special objects
-    int abortThreshold=0; //need 4 aborts to declare risky
-    int abortRatio=0;//need 40% aborts vs commits to declare risky
-    int deadlockdepth=10;
-
-    String filename=args[0];
-    Executor e=new Executor(filename);
-    System.out.println(e.maxTime());
+  public static void p1(Executor e) throws Exception {
     FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY, null);
     ls.start();
 
@@ -18,69 +7,97 @@ public class FileSim {
     FlexScheduler ls4=new FlexScheduler(e, FlexScheduler.COMMIT, null);
     ls4.start();
 
-    //Eager attack
     FlexScheduler ls5=new FlexScheduler(e, FlexScheduler.ATTACK, null);
     ls5.start();
 
-    //Eager polite
-    FlexScheduler ls6=new FlexScheduler(e, FlexScheduler.SUICIDE, null);
-    ls6.start();
-    
-    //Karma
-    FlexScheduler ls7=new FlexScheduler(e, FlexScheduler.TIMESTAMP, null);
-    ls7.start();
-
-    //Random
-    FlexScheduler ls8=new FlexScheduler(e, FlexScheduler.RANDOM, null);
-    ls8.start();
-
-    //Random
-    FlexScheduler ls9=new FlexScheduler(e, FlexScheduler.KARMA, null);
-    ls9.start();
-
-    //Random
-    FlexScheduler ls10=new FlexScheduler(e, FlexScheduler.POLITE, null);
-    ls10.start();
-
-    //Random
-    FlexScheduler ls11=new FlexScheduler(e, FlexScheduler.ERUPTION, null);
-    ls11.start();
-
 
     ls.join();
     System.out.println("Lazy Time="+ls.getTime());
     System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits());
+    ls=null;
 
     ls4.join();
     System.out.println("Fast Abort="+ls4.getTime());
     System.out.println("Aborts="+ls4.getAborts()+" Commit="+ls4.getCommits());
+    ls4=null;
 
     ls5.join();
     System.out.println("Attack Abort="+ls5.getTime());
     System.out.println("Aborts="+ls5.getAborts()+" Commit="+ls5.getCommits());
+    ls5=null;
+  }
+
+  public static void p2(Executor e) throws Exception {
+    FlexScheduler ls6=new FlexScheduler(e, FlexScheduler.SUICIDE, null);
+    ls6.start();
+    
+    FlexScheduler ls7=new FlexScheduler(e, FlexScheduler.TIMESTAMP, null);
+    ls7.start();
+
+    FlexScheduler ls8=new FlexScheduler(e, FlexScheduler.RANDOM, null);
+    ls8.start();
+
 
     ls6.join();
     System.out.println("Suicide Abort="+ls6.getTime());
     System.out.println("Aborts="+ls6.getAborts()+" Commit="+ls6.getCommits());
+    ls6=null;
 
     ls7.join();
     System.out.println("Timestamp Abort="+ls7.getTime());
     System.out.println("Aborts="+ls7.getAborts()+" Commit="+ls7.getCommits());
+    ls7=null;
 
     ls8.join();
     System.out.println("Random Abort="+ls8.getTime());
     System.out.println("Aborts="+ls8.getAborts()+" Commit="+ls8.getCommits());
+    ls8=null;
+  }
+
+  public static void p3(Executor e) throws Exception {
+    FlexScheduler ls9=new FlexScheduler(e, FlexScheduler.KARMA, null);
+    ls9.start();
+
+    FlexScheduler ls10=new FlexScheduler(e, FlexScheduler.POLITE, null);
+    ls10.start();
+
+    FlexScheduler ls11=new FlexScheduler(e, FlexScheduler.ERUPTION, null);
+    ls11.start();
+
+
 
     ls9.join();
     System.out.println("Karma Abort="+ls9.getTime());
     System.out.println("Aborts="+ls9.getAborts()+" Commit="+ls9.getCommits());
+    ls9=null;
 
     ls10.join();
     System.out.println("Polite Abort="+ls10.getTime());
     System.out.println("Aborts="+ls10.getAborts()+" Commit="+ls10.getCommits());
+    ls10=null;
 
     ls11.join();
     System.out.println("Eruption Abort="+ls11.getTime());
     System.out.println("Aborts="+ls11.getAborts()+" Commit="+ls11.getCommits());
   }
+
+  public static void main(String[] args) throws Exception {
+    //time between transactions
+    //split objects
+    int splitobjects=100;//10 percent of objects special
+    int splitaccesses=100;//40 percent of accesses to special objects
+    int abortThreshold=0; //need 4 aborts to declare risky
+    int abortRatio=0;//need 40% aborts vs commits to declare risky
+    int deadlockdepth=10;
+
+    String filename=args[0];
+    Executor e=new Executor(filename);
+    System.out.println(e.maxTime());
+    if (args.length==1||args[1].equals("1"))
+      p1(e);
+    if (args.length==1||args[1].equals("2"))
+      p2(e);
+    if (args.length==1||args[1].equals("3"))
+      p3(e);
+  }
 }
\ No newline at end of file
index 5cc7c9b93350f2015cbe87aec039f8a396f805ab..c635882ab992794d27b7fdd8885d247b2fcc65b0 100644 (file)
@@ -31,6 +31,7 @@ public class FlexScheduler extends Thread {
     eq=new PriorityQueue();
     backoff=new int[e.numThreads()];
     retrycount=new int[e.numThreads()];
+    transferred=new int[e.numThreads()];
     objtoinfo=new Hashtable();
     threadinfo=new ThreadInfo[e.numThreads()];
     blocked=new boolean[e.numThreads()];
@@ -91,13 +92,14 @@ public class FlexScheduler extends Thread {
   Random r;
   int[] backoff;
   int[] retrycount;
+  int[] transferred;
   Hashtable objtoinfo;
   ThreadInfo[] threadinfo;
   
   boolean[] blocked;
 
   public boolean isEager() {
-    return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE;
+    return policy==ATTACK||policy==SUICIDE||policy==TIMESTAMP||policy==RANDOM||policy==KARMA||policy==POLITE||policy==ERUPTION;
   }
 
   public boolean countObjects() {
@@ -218,7 +220,7 @@ public class FlexScheduler extends Thread {
        tryCommit(ev, trans);
        tcount++;
        if ((tcount%100000)==0)
-         System.out.println("Attempted "+tcount+"transactions");
+         System.out.println("Attempted "+tcount+"transactions "+policy);
       } else {
        enqueueEvent(ev, trans);
       }
@@ -243,17 +245,18 @@ public class FlexScheduler extends Thread {
     boolean abort=aborted[ev.getThread()];
     aborted[ev.getThread()]=false;
     if (!abort) {
-      //if it is a transaction, increment comit count
+      //if it is a transaction, increment commit count
       if (trans.numEvents()>1||trans.getEvent(0)!=Transaction.DELAY) {
-       threadinfo[ev.getThread()].priority=0;
        commitcount++;
        if (serCommit!=null) {
          serCommit.addPoint(ev.getTime(),ev.getThread());
        }
       }
       //Reset our backoff counter
+      threadinfo[ev.getThread()].priority=0;
       backoff[ev.getThread()]=BACKOFFSTART;
       retrycount[ev.getThread()]=0;
+      transferred[ev.getThread()]=0;
 
       //abort the other threads
       for(int i=0;i<trans.numEvents();i++) {
@@ -370,7 +373,11 @@ public class FlexScheduler extends Thread {
       boolean b=r.nextBoolean();
       if (b) {
        //delay
-       stall(ev, time+r.nextInt(200));
+       int thread=ev.getThread();
+       int dback=backoff[thread]*2;
+       if (dback>0)
+         backoff[thread]=dback;
+       stall(ev, time+r.nextInt(backoff[thread]));
        return false;
       } else {
        //abort other transactions
@@ -383,23 +390,25 @@ public class FlexScheduler extends Thread {
       }
     } else if (policy==KARMA) {
       int maxpriority=0;
-      //abort other transactions
       for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
        Integer thread=(Integer)thit.next();
        if (threadinfo[thread].priority>maxpriority)
          maxpriority=threadinfo[thread].priority;
       }
-      if (maxpriority>threadinfo[ev.getThread()].priority) {
-       //we lose
-       threadinfo[ev.getThread()].priority++;
+      if (maxpriority>(threadinfo[ev.getThread()].priority+retrycount[ev.getThread()])) {
        //stall for a little while
-       stall(ev, time+20);
+       threadinfo[ev.getThread()].priority--;
+       retrycount[ev.getThread()]++;
+       stall(ev, time+r.nextInt(3000));
        return false;
       } else {
        //we win
        for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
          Integer thread=(Integer)thit.next();
-         reschedule(thread, time);
+         int dback=backoff[thread]*2;
+         if (dback>0)
+           backoff[thread]=dback;
+         reschedule(thread, time+r.nextInt(backoff[thread]));
          abortcount++;
        }
        return true;
@@ -412,40 +421,49 @@ public class FlexScheduler extends Thread {
        if (threadinfo[thread].priority>maxpriority)
          maxpriority=threadinfo[thread].priority;
       }
-      if (maxpriority>threadinfo[ev.getThread()].priority) {
+      if (maxpriority>(threadinfo[ev.getThread()].priority+retrycount[ev.getThread()])) {
        //we lose
+       threadinfo[ev.getThread()].priority--;
        //stall for a little while
-       stall(ev, time);
+       stall(ev, time+r.nextInt(3000));
        int ourpriority=threadinfo[ev.getThread()].priority;
+       ourpriority-=transferred[ev.getThread()];
        for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
          Integer thread=(Integer)thit.next();
-         threadinfo[thread].priority+=ourpriority;;
+         threadinfo[thread].priority+=ourpriority;
        }
+       transferred[ev.getThread()]=threadinfo[ev.getThread()].priority;
+       retrycount[ev.getThread()]++;
+
        return false;
       } else {
        //we win
        for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
          Integer thread=(Integer)thit.next();
-         reschedule(thread, time);
+         int dback=backoff[thread]*2;
+         if (dback>0)
+           backoff[thread]=dback;
+         reschedule(thread, time+r.nextInt(backoff[thread]));
          abortcount++;
        }
        return true;
       }
     } else if (policy==POLITE) {
-      int retry=retrycount[ev.getThread()]++;
-      if (retry==22) {
+      int retry=(++retrycount[ev.getThread()]);
+      if (retry>=22) {
+       retrycount[ev.getThread()]=0;
        for(Iterator thit=threadstokill.iterator();thit.hasNext();) {
          Integer thread=(Integer)thit.next();
          reschedule(thread, time);
-         int dback=backoff[thread.intValue()]*2;
-         if (dback>0)
-           backoff[thread.intValue()]=dback;
          abortcount++;
        }
        return true;
       } else {
        //otherwise stall
-       stall(ev, time+r.nextInt((1<<retry)*12));
+       int stalltime=(1<<(retry-1))*12;
+       if (stalltime<0)
+         stalltime=1<<30;
+       stall(ev, time+r.nextInt(stalltime));
        return false;
       }
     } else if (policy==ATTACK) {
@@ -562,8 +580,10 @@ public class FlexScheduler extends Thread {
        //do eager contention management
        Set conflicts=rdConflictSet(ev.getThread(), object);
        if (conflicts!=null) {
-         if (!handleConflicts(ev, conflicts, currtime))
+         if (!handleConflicts(ev, conflicts, currtime)) {
+           ((Set)rdobjmap.get(object)).remove(new Integer(ev.getThread()));
            return;
+         }
        }
       }
     } else if (operation==Transaction.WRITE) {
@@ -578,8 +598,10 @@ public class FlexScheduler extends Thread {
       if (isEager()) {
        Set conflicts=wrConflictSet(ev.getThread(), object);
        if (conflicts!=null) {
-         if (!handleConflicts(ev, conflicts, currtime))
+         if (!handleConflicts(ev, conflicts, currtime)) {
+           ((Set)wrobjmap.get(object)).remove(new Integer(ev.getThread()));
            return;
+         }
        }
       }
     } else if (operation==Transaction.BARRIER) {
@@ -603,7 +625,8 @@ public class FlexScheduler extends Thread {
       }
       return;
     }
-    
+    retrycount[ev.getThread()]=0;
+    transferred[ev.getThread()]=0;
     //enqueue the next event
     long deltatime=trans.getTime(event+1)-trans.getTime(event);
     Event nev=new Event(deltatime+currtime, trans, event+1, ev.getThread(), ev.getTransNum());