ATOM: Automatic Transaction-Oriented Memoization Hugo Rito and Jo˜ ao Cachopo INESC-ID Instituto Superior T´ ecnico September 11, 2009
Overview of Memoization Functional Programming Memoization
Overview of Memoization Functional Programming Functional Programming
Overview of Memoization Functional Programming Memoization
Overview of Memoization Fibonacci function static int fib(int n) { if (n <= 1) return n; return fib(n-1) + fib(n-2); }
Overview of Memoization fib(4) 4 3 2 2 1 1 0 1 0
Overview of Memoization fib(4) 4 3 2 2 1 1 0 1 0
Overview of Memoization fib(5) 5 3 4 3 2 2 1 2 1 1 0 1 0 1 0
Overview of Memoization fib(5) 5 3 4 3 2 2 1 2 1 1 0 1 0 1 0
Overview of Memoization fib(5) 5 3 4 3 2 2 1 2 1 1 0 1 0 1 0
Overview of Memoization Memoization Optimization technique Memoization Function cache Relevant state �− → Result
Overview of Memoization Memo fib(5) 5 3 4 3 2 2 1 2 1 1 0 1 0 1 0
Overview of Memoization Memo fib(5) 5 4 3 2 1 0
Limitations of Memoization Non-Functional Programming Object-Oriented Imperative Programming
Limitations of Memoization Non-Functional Programming Memoization
Limitations of Memoization Banking Domain Account Client 1 * balance : long getTotalBalance() : long
Limitations of Memoization Banking Domain class Client { Set<Account> accounts; long getTotalBalance() { long total = 0; for (Account account : accounts) { total += accounts.getBalance(); } return total; } }
Limitations of Memoization Banking Domain: Relevant State class Client { Set<Account> accounts ; long getTotalBalance() { long total = 0; for (Account account : accounts) { total += accounts.getBalance(); } return total; } }
Limitations of Memoization Banking Domain: Relevant State class Client { Set<Account> accounts ; long getTotalBalance() { long total = 0; for (Account account : accounts) { total += accounts.getBalance() ; } return total; } }
Limitations of Memoization Relevant State: Problem No automatic solutions
Limitations of Memoization Relevant State: Problem No automatic solutions Manually Difficult Error-prone
Limitations of Memoization Side-effects Share state reads difficult...
Limitations of Memoization Side-effects Share state reads difficult... and side-effects make it worse!
Proposed Solution Proposed Solution Memoization
Proposed Solution Proposed Solution Memoization + Software Transactional Memory
Proposed Solution Proposed Solution
Proposed Solution Proposed Solution Automatic Transaction-Oriented Memoization
Proposed Solution Proposed Solution Object-Oriented Imperative Programming
Proposed Solution Proposed Solution Automatic Transaction-Oriented Memoization
Proposed Solution Software Transactional Memory Concurrent programming
Proposed Solution Software Transactional Memory Concurrent programming Transaction
Proposed Solution Software Transactional Memory Concurrent programming Transaction Intercept accesses
Proposed Solution Software Transactional Memory Concurrent programming Transaction Intercept accesses Read-set / Write-set
Proposed Solution JVSTM Example class Client { Set<Account> accounts; long getTotalBalance() { long total = 0; for (Account account : accounts) { total += accounts.getBalance(); } return total; } }
Proposed Solution JVSTM Example class Client { VSet<Account> accounts; long getTotalBalance() { long total = 0; for (Account account : accounts) { total += accounts.getBalance(); } return total; } }
Proposed Solution JVSTM Example class Client { VSet<Account> accounts; long getTotalBalance() { long total = 0; for (Account account : accounts.get() ) { total += accounts.getBalance(); } return total; } }
Proposed Solution JVSTM Example class Client { VSet<Account> accounts; @Atomic long getTotalBalance() { long total = 0; for (Account account : accounts.get()) { total += accounts.getBalance(); } return total; } }
Proposed Solution The ATOM Java library
Proposed Solution The ATOM Java library Uses an STM to.. Build the relevant state Detect side-effects Capture side-effects
Proposed Solution The ATOM Java library Uses an STM to.. Build the relevant state Detect side-effects Capture side-effects Simple interface
Proposed Solution Evolution Memoization Cache Search Cache No Execute Hit? Method Yes Get Result From Cache Add New Cache Entry Return Result
Proposed Solution Evolution Extended Begin Memoization Transaction Cache Search Cache No Execute Hit? Method Yes Read-set: Relevant state Write-set: Side-effects Get Result From Cache Add New Cache Entry Commit Transaction Return Result
Proposed Solution Evolution Extended Begin Memoization Transaction Cache Search Two memoization strategies: Read-only Cache No Execute Hit? Method Write-allowed Yes Can No Memoize? Yes Collect Get Result Information From Cache “Collect Information” caches: Add New Read-set Cache Entry Possibly the write-set Commit Transaction Return Result
Proposed Solution Evolution Extended Begin Memoization Transaction Cache Search Cache No Execute Hit? Method Yes Can No Read Memoize? No Apply Only? Changes Possibly apply the write-set Yes Yes Collect Get Result Information From Cache Add New Cache Entry Commit Transaction Return Result
Proposed Solution Evolution Extended Begin Memoization Transaction Cache Search Cache No Execute Hit? Method Yes Two caching policies: Can No Read Memoize? No Apply Only? Version Changes Yes Yes Value Collect Get Result Information From Cache Add New Cache Entry Commit Transaction Return Result
Proposed Solution ATOM Example @Atomic long getTotalBalance() { /* Body of getTotalBalance() */ }
Proposed Solution ATOM Example @Memo long getTotalBalance() { /* Body of getTotalBalance() */ }
Experimental Results STMBench7 benchmark Customizable Evaluate STM implementations CAD domain
Experimental Results Experimental Setting Dual-Quadcore Nehalem Xeon, 12Gb of RAM 1, 2, 4, 8, and 16 threads Read-dominated workload Three mixes of operations
Experimental Results Results No read-write traversals / No structural modifications 6000 5000 d n 4000 o c e s 3000 ATOM / s JVSTM n o i 2000 t a r e p O 1000 0 1 2 4 8 16 Number of Threads
Experimental Results Results No traversals 10000 9000 8000 d 7000 n o c 6000 e s 5000 ATOM / s JVSTM n 4000 o i t a 3000 r e p 2000 O 1000 0 1 2 4 8 16 Number of Threads
Experimental Results Results No traversals / No structural modifications 25000 20000 d n o c 15000 e s ATOM / s JVSTM n 10000 o i t a r e p 5000 O 0 1 2 4 8 16 Number of Threads
Conclusions Summary Memoize object-oriented imperative programs is hard
Conclusions Summary Memoize object-oriented imperative programs is hard ATOM Relevant state dynamically constructed Detects/Integrates side-effects Simple interface
Conclusions Summary Memoize object-oriented imperative programs is hard ATOM Relevant state dynamically constructed Detects/Integrates side-effects Simple interface Memoization improves STMs’ performance
Conclusions Questions
Recommend
More recommend