The ATOMOS Transactional Programming Language Mehdi Amirijoo Linkpings

  • Slides: 18
Download presentation
The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet 2007 -03 -16 1

The ATOMOS Transactional Programming Language Mehdi Amirijoo Linköpings universitet 2007 -03 -16 1

n Background n Transactional memory n Conditional waiting n Transaction Nesting n Evaluation n

n Background n Transactional memory n Conditional waiting n Transaction Nesting n Evaluation n Conclusion 2007 -03 -16 Mehdi Amirijoo 2

Background n Multi-threaded application n Access to shared data using locks semaphore s; .

Background n Multi-threaded application n Access to shared data using locks semaphore s; . . . wait(s); //decrease s count++; signal(s); //increase s. . . 2007 -03 -16 Mehdi Amirijoo 3

Background n Course-grained locking leads to serialization on high-contention data structures Process P 1

Background n Course-grained locking leads to serialization on high-contention data structures Process P 1 { wait(s); . . . d. a++; . . . signal(s); } 2007 -03 -16 Process P 2 { wait(s); . . . d. b++; . . . signal(s); } Mehdi Amirijoo Process P 3 { wait(s); . . . d. a++; . . . signal(s); } 4

Background n Fine-grained locking: n improves concurrency n increases code complexity (deadlocks) n degrading

Background n Fine-grained locking: n improves concurrency n increases code complexity (deadlocks) n degrading performance Process P 1 {. . . wait(s 1); d. a++; signal(s 1); . . . } 2007 -03 -16 Process P 2 {. . . wait(s 2); d. b++; signal(s 2); . . . } Mehdi Amirijoo 5

Transactional Memory n Focus on where atomic execution is necessary n Not how it

Transactional Memory n Focus on where atomic execution is necessary n Not how it is implemented Process P 1 {. . . atomic { d. a++; }. . . } 2007 -03 -16 Process P 2 {. . . atomic { d. b++; }. . . } Mehdi Amirijoo 6

Transactional Memory n Statements within atomic appear to have serialization with respect to: Other

Transactional Memory n Statements within atomic appear to have serialization with respect to: Other transactions n Reads and writes outside of transactions n n Nested transactions n Optimistic speculation (transactions) vs pessimistic waiting (locks) n Roll-back due to writes outside the transaction 2007 -03 -16 Mehdi Amirijoo Process P 1 { atomic {. . . } }. . . 7

Conditional Waiting n Conditional critical region (CCR) n Similar property as critical sections, and

Conditional Waiting n Conditional critical region (CCR) n Similar property as critical sections, and n A process can enter the critical region iff the condition evaluates to be true. n In ATOMOS: atomic { if ( !condition(condition_variables) ) { watch condition_variables; retry; } // critical region } 2007 -03 -16 Mehdi Amirijoo 8

Conditional Waiting Class Buffer { public int get (){ synchronized (this) { while (!available)

Conditional Waiting Class Buffer { public int get (){ synchronized (this) { while (!available) wait(); available = false; notify. All(); 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; notify. All(); }} available = true; }} } 2007 -03 -16 } Mehdi Amirijoo 9

Conditional Waiting Example: Barrier synchronization synchronized (lock) { count++; if (count != n. Threads)

Conditional Waiting Example: Barrier synchronization synchronized (lock) { count++; if (count != n. Threads) lock. wait(); else lock. notify. All(); } 2007 -03 -16 atomic { count++; if (count != n. Threads) { watch count; retry; }} atomic { count++; } atomic { if (count != n. Threads) { watch count; retry; }} Mehdi Amirijoo 10

Nesting n In databases transactions usually reduce isolation to improve performance n Communication from

Nesting n In databases transactions usually reduce isolation to improve performance n Communication from within uncommitted transactions! n Closed-nested transaction: Results of children visible only to parent n Open-nested Transaction: Results of children visible globally 2007 -03 -16 Mehdi Amirijoo 11

Nesting 2007 -03 -16 Mehdi Amirijoo 12

Nesting 2007 -03 -16 Mehdi Amirijoo 12

Nesting public static int generate. ID { atomic { return id++; } } public

Nesting public static int generate. ID { atomic { return id++; } } public static void create. Order (. . . ) { atomic { Order order = new Order(); order. set. ID(generate. ID()); // finish initialization of order. This could // include more calls to generate. ID. orders. put(new Integer(order. get. ID()), order); } } 2007 -03 -16 Mehdi Amirijoo 13

Nesting public static open int generate. ID { open { return id++; } }

Nesting public static open int generate. ID { open { return id++; } } public static void create. Order (. . . ) { atomic { Order order = new Order(); order. set. ID(generate. ID()); // finish initialization of order. This could // include more calls to generate. ID. orders. put(new Integer(order. get. ID()), order); } } 2007 -03 -16 Mehdi Amirijoo 14

Evaluation n Goal: Compare ATOMOS with Java n Synchronized → atomic n wait(), notify.

Evaluation n Goal: Compare ATOMOS with Java n Synchronized → atomic n wait(), notify. All() → watch, retry n 1 to 32 CPU: s (no thread migration) n No garbage collection n Measure execution time 2007 -03 -16 Mehdi Amirijoo 15

Evaluation Benchmark focusing on business object manipulation Only 1% chance of contention between threads.

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 Hash. Map use only one

Evaluation Benchmark focusing on business object manipulation Hashtable and Hash. Map use only one mutex Concurrent. Hash. Map uses fine-grained locking 2007 -03 -16 Mehdi Amirijoo Atomos uses single atomic statement 17

Conclusion n Transactional programming simplifies design of programs n Conditional waiting enables CCR n

Conclusion n Transactional programming simplifies design of programs n Conditional waiting enables CCR n Open nesting increases performance by reducing time to commit n Evaluation shows that the approach is scalable with the number of processors 2007 -03 -16 Mehdi Amirijoo 18