730 likes | 934 Views
Database Replication in Tashkent. CSEP 545 Transaction Processing Sameh Elnikety. Replication for Performance. Expensive Limited scalability. DB Replication is Challenging. Single database system Large, persistent state Transactions Complex software Replication challenges
E N D
Database Replication in Tashkent CSEP 545 Transaction Processing Sameh Elnikety
Replication for Performance Expensive Limited scalability
DB Replication is Challenging • Single database system • Large, persistent state • Transactions • Complex software • Replication challenges • Maintain consistency • Middleware replication
Background Standalone DBMS Replica 1
Background Replica 1 Load Balancer Replica 2 Replica 3
Read Tx Read tx does not change DB state Replica 1 Load Balancer Replica 2 T Replica 3
Update Tx 1/2 Update txchanges DB state Replica 1 Load Balancer Replica 2 T ws ws Replica 3
Update Tx 1/2 Update txchanges DB state Apply (or commit) T everywhere Replica 1 ws Load Balancer Replica 2 T ws ws ws Replica 3 Example: T1: { set x = 1 } ws
Update Tx 2/2 Update txchanges DB state Replica 1 Ordering Load Balancer Replica 2 T T ws ws Replica 3 ws ws
Update Tx 2/2 Update txchanges DB state Commit updates in order Replica 1 ws ws Ordering Load Balancer Replica 2 ws T ws ws ws Replica 3 Replica 3 Example: T1: { set x = 1 }T2: { set x = 7 } ws T ws
Sub-linear Scalability Wall Replica 1 ws ws Ordering Load Balancer Replica 2 ws T ws ws ws Replica 3 Replica 3 Replica 4 ws T ws
This Talk • General scaling techniques • Address fundamental bottlenecks • Synergistic, implemented in middleware • Evaluated experimentally
Super-linear Scalability 37 X 25 X TPS 12 X 7 X 1 X
Big Picture: Let’s Oversimplify Standalone DBMS reading R update U logging
Big Picture: Let’s Oversimplify Standalone DBMS reading R update U logging R Replica 1/N (traditional) reading N.R U update (N-1).ws N.U logging
Big Picture: Let’s Oversimplify Standalone DBMS reading R update U logging R Replica 1/N (traditional) reading N.R U update (N-1).ws N.U logging R* Replica 1/N (optimized) reading N.R U* update (N-1).ws* N.U logging
Big Picture: Let’s Oversimplify Standalone DBMS reading R update U logging R Replica 1/N (traditional) reading N.R U update (N-1).ws N.U logging R* Replica 1/N (optimized) reading MALB Update Filtering Uniting O & D N.R U* update (N-1).ws* N.U logging
Key Points • Commit updates in order • Perform serial synchronous disk writes • Unite ordering and durability • Load balancing • Optimize for equal load: memory contention • MALB: optimize for in-memory execution • Update propagation • Propagate updates everywhere • Update filtering: propagate to where needed
Roadmap 2, 3 1 Tx A Replica 1 Ordering Load Balancer Replica 2 Replica 3 Commit updates in order Load balancing Update propagation
Key Idea • Traditionally: • Commit ordering and durability are separated • Key idea: • Unite commit ordering and durability
All Replicas Must Agree Replica 1 Tx A • All replicas agree on • which update tx commit • their commit order • Total order • Determined by middleware • Followed by each replica durability Replica 2 Tx B durability Replica 3 durability
Order Outside DBMS Replica 1 Tx A Tx A durability Tx B Ordering Replica 2 Tx B durability Replica 3 durability
Order Outside DBMS Replica 1 Tx A Tx A durability A B A B Tx B Ordering Replica 2 Tx B durability A B A B A B Replica 3 A B durability A B
DBMS Proxy Task A SQL interface Task B Tx A Tx B Enforce External Commit Order Ordering A B Replica 3 durability
DBMS Proxy Task A SQL interface Task B Tx A Tx B A Enforce External Commit Order Ordering A B Replica 3 durability B
DBMS Proxy Task A SQL interface Task B Tx A Tx B A Enforce External Commit Order Ordering A B Replica 3 durability B Cannot commit A & B concurrently!
Proxy Task A SQL interface Task B Tx A Tx B Enforce Order = Serial Commit Ordering A B Replica 3 DBMS durability A
Proxy Task A SQL interface Task B Tx A Tx B B Enforce Order = Serial Commit Ordering A B Replica 3 DBMS durability A
Commit Serialization is Slow Ordering A B C Commit orderA B C Proxy Ack B Ack A Ack C DBMS Commit A Commit B Commit C CPU DurabilityA CPU DurabilityA B CPU DurabilityA B C durability
Commit Serialization is Slow Ordering A B C Commit orderA B C Proxy Ack B Ack A Ack C Problem: Durability & ordering separated →serial disk writes DBMS Commit A Commit B Commit C CPU DurabilityA CPU DurabilityA B CPU DurabilityA B C durability
Unite D. & O. in Middleware Ordering A B C DurabilityA B C Commit orderA B C durability Proxy Ack B Ack A Ack C DBMS Commit A Commit B Commit C CPU CPU CPU durability OFF
Unite D. & O. in Middleware Ordering A B C DurabilityA B C Commit orderA B C durability Proxy Ack B Ack A Ack C Solution: Move durability to MW Durability & ordering in middleware →group commit DBMS Commit A Commit B Commit C CPU CPU CPU durability OFF
Implementation: Uniting D & O in MW • Middleware logs tx effects • Durability of update tx • Guaranteed in middleware • Turn durability off at database • Middleware performs durability & ordering • United → group commit → fast • Database commits update tx serially • Commit = quick main memory operation
Uniting Improves Throughput • Metric • Throughput • Workload • TPC-W Ordering • (50% updates) • System • Linux cluster • PostgreSQL • 16 replicas • Serializable exec. 12 X 7 X TPS 1 X TPC-W
Roadmap 2, 3 1 Tx A Replica 1 Ordering Load Balancer Replica 2 Replica 3 Commit updates in order Load balancing Update propagation
Key Idea Replica 1 Equal load on replicas Mem Disk Load Balancer Replica 2 Mem Disk
Key Idea Replica 1 Equal load on replicas Mem Disk Load Balancer Replica 2 Mem MALB: (Memory-Aware Load Balancing)Optimize for in-memory execution Disk
How Does MALB Work? 1 2 3 Database 1 2 Workload A → B → 2 3 Mem Memory
Read Data From Disk Replica 1 A → B → 1 2 A, B, A, B Mem 2 3 Disk A, B, A, B Least Loaded 1 1 2 3 3 Replica 2 Mem Disk A, B, A, B 1 2 3
Read Data From Disk Replica 1 A → B → 1 2 A, B, A, B Mem 2 3 1 1 2 3 3 Slow Disk A, B, A, B Least Loaded 1 1 2 3 3 Replica 2 Mem Slow 1 1 2 3 3 Disk A, B, A, B 1 2 3
Data Fits in Memory Replica 1 A → B → 1 2 A, A, A, A Mem 2 3 Disk A, B, A, B MALB 1 2 3 Replica 2 Mem Disk B, B, B, B 1 2 3
Data Fits in Memory Replica 1 A → B → 1 2 A, A, A, A Mem 2 3 1 2 Fast Disk A, B, A, B MALB 1 2 3 Replica 2 Mem Fast 2 3 Memory info? Many tx and replicas? Disk B, B, B, B 1 2 3
Estimate Tx Memory Needs • Exploit tx execution plan • Which tables & indices are accessed • Their access pattern • Linear scan, direct access • Metadata from database • Sizes of tables and indices
Grouping Transactions • Objective • Construct tx groups that fit together in memory • Bin packing • Item:tx memory needs • Bin: memory of replica • Heuristic: Best Fit Decreasing • Allocate replicas to tx groups • Adjust for group loads
MALB in Action A B CD E F MALB
MALB in Action Memory needs for A, B, C, D, E, F A B CD E F MALB
MALB in Action Group A Memory needs for A, B, C, D, E, F A B CD E F MALB Group B C Group D E F
MALB in Action Replica Group A Memory needs for A, B, C, D, E, F A Disk A B CD E F MALB Replica Group B C B C Disk Group D E F Replica D E F Disk
MALB Summary • Objective • Optimize for in-memory execution • Method • Estimate tx memory needs • Construct tx groups • Allocate replicas to tx groups
Experimental Evaluation • Implementation • No change in consistency • Still middleware • Compare • United: efficient baseline system • MALB: exploits working set information • Same environment • Linux cluster running PostgreSQL • Workload: TPC-W Ordering (50% update txs)