From ab4b0fe43f45b5c44761bc293b4bdcbb2aff2a65 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 15 Sep 2009 19:40:21 +0000 Subject: [PATCH] simulator now models two locking modes: lock -- lazy conflict detection lockcommit -- kill threads as soon as committing thread conflicts with them --- Robust/TransSim/Executor.java | 44 ++++-- Robust/TransSim/FlexScheduler.java | 216 +++++++++++++++++------------ Robust/TransSim/ObjectInfo.java | 24 ++++ Robust/TransSim/ThreadInfo.java | 9 ++ Robust/TransSim/TransSim.java | 38 +++-- 5 files changed, 222 insertions(+), 109 deletions(-) diff --git a/Robust/TransSim/Executor.java b/Robust/TransSim/Executor.java index 0707eed2..1294e650 100644 --- a/Robust/TransSim/Executor.java +++ b/Robust/TransSim/Executor.java @@ -14,6 +14,9 @@ public class Executor { int readPercent; Random r; ThreadClass[] threads; + int splitobjects; + int splitaccesses; + int readPercentSecond; public String toString() { String s=""; @@ -23,8 +26,11 @@ public class Executor { return s; } - public Executor(int numThreads, int numTrans, int deltaTrans, int numObjects, int numAccesses, int deltaAccesses, int readPercent, int delay, int deltaDelay, int nonTrans, int deltaNonTrans) { + this(numThreads, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans, 100, 100, 0); + } + + public Executor(int numThreads, int numTrans, int deltaTrans, int numObjects, int numAccesses, int deltaAccesses, int readPercent, int delay, int deltaDelay, int nonTrans, int deltaNonTrans, int splitobjects, int splitaccesses, int readPercentSecond) { this.numThreads=numThreads; this.numTrans=numTrans; this.deltaTrans=deltaTrans; @@ -36,6 +42,9 @@ public class Executor { this.deltaDelay=deltaDelay; this.nonTrans=nonTrans; this.deltaNonTrans=deltaNonTrans; + this.splitobjects=splitobjects; + this.splitaccesses=splitaccesses; + this.readPercentSecond=readPercentSecond; r=new Random(); threads=new ThreadClass[numThreads]; generateThreads(); @@ -98,16 +107,29 @@ public class Executor { int accesses=getRandom(numAccesses, deltaAccesses); Transaction t=new Transaction(accesses); int time=0; + int splitpoint=(numObjects*splitobjects)/100; for(int i=0;i<(accesses-1); i++) { - boolean isRead=r.nextInt(100)1||trans.getEvent(0)!=Transaction.DELAY) { commitcount++; } //Reset our backoff counter backoff[ev.getThread()]=BACKOFFSTART; - //abort the other threads for(int i=0;ifs.abortThreshold)&& + aborts>(commits*fs.abortRatio/100)) + setRisky(true); + } + + public void recordCommit() { + commits++; } public void addWaiter(FlexScheduler.Event ev) { diff --git a/Robust/TransSim/ThreadInfo.java b/Robust/TransSim/ThreadInfo.java index 92ba65da..c8133798 100644 --- a/Robust/TransSim/ThreadInfo.java +++ b/Robust/TransSim/ThreadInfo.java @@ -6,6 +6,15 @@ public class ThreadInfo { this.fs=fs; } boolean stalled; + int oid; + + public void setObject(int oid) { + this.oid=oid; + } + + public int getObject() { + return oid; + } public boolean isStalled() { return stalled; diff --git a/Robust/TransSim/TransSim.java b/Robust/TransSim/TransSim.java index 4d439913..6f2a6281 100644 --- a/Robust/TransSim/TransSim.java +++ b/Robust/TransSim/TransSim.java @@ -1,22 +1,31 @@ public class TransSim { public static void main(String[] args) { - int numThreads=16; - int numTrans=20; + int numThreads=1; + int numTrans=4; int deltaTrans=0; - int numObjects=4000; - int numAccesses=20; - int deltaAccesses=5; - int readPercent=20; + int numObjects=400; + int numAccesses=10; + int deltaAccesses=0; + int readPercent=0; //time for operation int delay=20; int deltaDelay=4; //time between transactions int nonTrans=20; int deltaNonTrans=4; + //split objects + int splitobjects=100;//10 percent of objects special + int splitaccesses=100;//40 percent of accesses to special objects + int readPercentSecond=30;//20 percent of accesses are reads + int abortThreshold=0; //need 4 aborts to declare risky + int abortRatio=0;//need 40% aborts vs commits to declare risky + int deadlockdepth=10; long tlazy=0, tcommit=0, tattack=0, tpolite=0, tkarma=0; - for(int i=0;i<100;i++) { - Executor e=new Executor(numThreads, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans); + + for(int i=1;i<100;i++) { + System.out.println("i="+i); + Executor e=new Executor(i, numTrans, deltaTrans, numObjects, numAccesses, deltaAccesses, readPercent, delay, deltaDelay, nonTrans, deltaNonTrans, splitobjects, splitaccesses, readPercentSecond); System.out.println(e.maxTime()); FlexScheduler ls=new FlexScheduler(e, FlexScheduler.LAZY); ls.dosim(); @@ -26,14 +35,25 @@ public class TransSim { tlazy+=ls.getTime(); //Lock object accesses - ls=new FlexScheduler(e, FlexScheduler.LOCK); + ls=new FlexScheduler(e, FlexScheduler.LOCK, abortThreshold, abortRatio, deadlockdepth); ls.dosim(); + System.out.println("Deadlock count="+ls.getDeadLockCount()); System.out.println("Lock Abort="+ls.getTime()); System.out.println("Aborts="+ls.getAborts()+" Commit="+ls.getCommits()); if (ls.getTime()