The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet

advertisement
The ATOMOS Transactional
Programming Language
Mehdi Amirijoo
Linköpings universitet
2007-03-16
1
 Background
 Transactional memory
 Conditional waiting
 Transaction Nesting
 Evaluation
 Conclusion
2007-03-16
Mehdi Amirijoo
2
Background
 Multi-threaded application
 Access to shared data using locks
semaphore s;
...
wait(s); //decrease s
count++;
signal(s); //increase s
...
2007-03-16
Mehdi Amirijoo
3
Background
 Course-grained locking leads to serialization
on high-contention data structures
Process P1 {
wait(s);
...
d.a++;
...
signal(s);
}
2007-03-16
Process P2 {
wait(s);
...
d.b++;
...
signal(s);
}
Mehdi Amirijoo
Process P3 {
wait(s);
...
d.a++;
...
signal(s);
}
4
Background
 Fine-grained locking:



improves concurrency
increases code complexity (deadlocks)
degrading performance
Process P1 {
...
wait(s1);
d.a++;
signal(s1);
...
}
2007-03-16
Process P2 {
...
wait(s2);
d.b++;
signal(s2);
...
}
Mehdi Amirijoo
5
Transactional Memory
 Focus on where atomic execution is
necessary

Not how it is implemented
Process P1 {
...
atomic {
d.a++;
}
...
}
2007-03-16
Process P2 {
...
atomic {
d.b++;
}
...
}
Mehdi Amirijoo
6
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) vs
pessimistic waiting (locks)
 Roll-back due to writes
outside the transaction
2007-03-16
Mehdi Amirijoo
Process P1 {
atomic {
atomic {
...
}
}
...
7
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
8
Conditional Waiting
Class Buffer {
Class Buffer {
public int get (){
synchronized (this) {
while (!available)
wait();
available = false;
notifyAll();
return contents;}}
public int get() {
atomic {
if (!available) {
watch available;
retry;}
available = false;
return contents;}}
public void put(int value) { public void put (int value) {
synchronized (this) {
atomic {
while (available)
if (available) {
wait();
watch available;
contents = value;
retry;}
available = true;
contents = value;
notifyAll();}}
available = true;}}
} 2007-03-16
}
Mehdi Amirijoo
9
Conditional Waiting
Example: Barrier synchronization
synchronized (lock) {
count++;
if (count != nThreads)
lock.wait();
else
lock.notifyAll();
}
2007-03-16
atomic {
count++;
if (count != nThreads) {
watch count;
retry; }}
atomic {
count++; }
atomic {
if (count != nThreads) {
watch count;
retry; }}
Mehdi Amirijoo
10
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
11
Nesting
2007-03-16
Mehdi Amirijoo
12
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
13
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
14
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
15
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
16
Evaluation
Benchmark focusing on business object manipulation
Hashtable and
HashMap use only
one mutex
ConcurrentHashMap
uses fine-grained
locking
2007-03-16
Mehdi Amirijoo
Atomos uses single
atomic statement 17
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
2007-03-16
Mehdi Amirijoo
18
Download