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