View
214
Download
0
Category
Preview:
Citation preview
2007-03-16 1
The ATOMOS Transactional Programming Language
Mehdi AmirijooLinköpings universitet
2007-03-16 Mehdi Amirijoo 2
Background Transactional memory Conditional waiting Transaction Nesting Evaluation Conclusion
2007-03-16 Mehdi Amirijoo 3
Background
Multi-threaded application
Access to shared data using locks
semaphore s;...wait(s); //decrease scount++;signal(s); //increase s...
2007-03-16 Mehdi Amirijoo 4
Background
Course-grained locking leads to serialization on high-contention data structures
Process P1 { wait(s); ... d.a++; ... signal(s);}
Process P2 { wait(s); ... d.b++; ... signal(s);}
Process P3 { wait(s); ... d.a++; ... signal(s);}
2007-03-16 Mehdi Amirijoo 5
Background
Fine-grained locking: improves concurrency increases code complexity (deadlocks) degrading performance
Process P1 { ...
wait(s1); d.a++; signal(s1); ...}
Process P2 { ... wait(s2); d.b++; signal(s2); ...}
2007-03-16 Mehdi Amirijoo 6
Transactional Memory
Focus on where atomic execution is necessary Not how it is implemented
Process P1 { ...
atomic { d.a++; } ...}
Process P2 { ... atomic { d.b++; } ...}
2007-03-16 Mehdi Amirijoo 7
Transactional Memory
Statements within atomic appear to have serialization with respect to: Other transactions Reads and writes outside of transactions
Nested transactions Optimistic speculation
(transactions) vspessimistic waiting (locks)
Roll-back due to writesoutside the transaction
Process P1 {
atomic { atomic { ... } } ...
2007-03-16 Mehdi Amirijoo 8
Conditional Waiting
Conditional critical region (CCR) Similar property as critical sections, and A process can enter the critical region iff the
condition evaluates to be true. In ATOMOS:
atomic {
if ( !condition(condition_variables) ) {
watch condition_variables;
retry;} // critical region}
2007-03-16 Mehdi Amirijoo 9
Conditional WaitingClass Buffer {
public int get (){ synchronized (this) { while (!available) wait(); available = false; notifyAll(); return contents;}}
public void put(int value) { synchronized (this) { while (available) wait(); contents = value; available = true; notifyAll();}} }
Class Buffer {
public int get() { atomic { if (!available) { watch available; retry;} available = false; return contents;}}
public void put (int value) { atomic { if (available) { watch available; retry;} contents = value; available = true;}}}
2007-03-16 Mehdi Amirijoo 10
Conditional Waiting
synchronized (lock) { count++; if (count != nThreads) lock.wait(); else lock.notifyAll();}
atomic { count++; if (count != nThreads) { watch count; retry; }}
Example: Barrier synchronization
atomic { count++; }atomic { if (count != nThreads) { watch count; retry; }}
2007-03-16 Mehdi Amirijoo 11
Nesting
In databases transactions usually reduce isolation to improve performance Communication from within uncommitted
transactions! Closed-nested transaction:
Results of children visible only to parent Open-nested Transaction:
Results of children visible globally
2007-03-16 Mehdi Amirijoo 12
Nesting
2007-03-16 Mehdi Amirijoo 13
Nesting
public static int generateID { atomic { return id++; }}
public static void createOrder (...) { atomic { Order order = new Order(); order.setID(generateID()); // finish initialization of order. This could // include more calls to generateID. orders.put(new Integer(order.getID()),order); }}
2007-03-16 Mehdi Amirijoo 14
Nesting
public static open int generateID { open { return id++; }}
public static void createOrder (...) { atomic { Order order = new Order(); order.setID(generateID()); // finish initialization of order. This could // include more calls to generateID. orders.put(new Integer(order.getID()),order); }}
2007-03-16 Mehdi Amirijoo 15
Evaluation
Goal:Compare ATOMOS with Java
Synchronized → atomic wait(), notify(), notifyAll() → watch, retry
1 to 32 CPU:s (no thread migration) No garbage collection Measure execution time
2007-03-16 Mehdi Amirijoo 16
Evaluation
Benchmark focusing on business object manipulation
Only 1% chance of
contention between
threads.
ATOMOS does not
incur additional
bottlenecks
2007-03-16 Mehdi Amirijoo 17
Evaluation
Benchmark focusing on business object manipulation
Hashtable and
HashMap use only
one mutex
ConcurrentHashMap
uses fine-grained
locking
Atomos uses single
atomic statement
2007-03-16 Mehdi Amirijoo 18
Conclusion
Transactional programming simplifies design of programs
Conditional waiting enables CCR Open nesting increases performance by
reducing time to commit Evaluation shows that the approach is
scalable with the number of processors
Recommended