Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.
-
Upload
adam-crutcher -
Category
Documents
-
view
220 -
download
0
Transcript of Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.
Replication for Availability & Durability with MySQL and Amazon RDS
Grant McAlister
Overview
Why replicate?What are the options?What are the issues?What do we do.
Why Replicate?
DurabilityAvailabilityScaling
Durability
Replicate
Location 1 Location 2
Availability
When disaster or failure happens Read availability from readable replicas Read/Write availability by promoting a replica
Can be faster than waiting for a reboot
Online DDL operations (create index, alter table) Make changes on a replica Failover to it Requires Logical Replication
Read Scaling
Master Replica1
R/WClient
R/WClient
ReadClient
Replica2 Replica3
ReadClient
ReadClient
ReadClient
Replication Options
Logical vs. PhysicalSynchronous vs. Asynchronous
Logical vs. Physical
Logical Standard MySQL Replication Logical statement or transaction is shipped Non-deterministic? (Statement vs. Mixed vs. Row)
Physical Shipping the physical block changes
• Oracle Dataguard• Filesystem or block layer replication• Physical SAN device replication
Deterministic (physically exactly the same)
Primary
Logical Replication
Buffer
Data
insert into person values(‘grant’); commit;
Parse
Recovery Log
Replication Log
Replica
Buffer
Data
Parse
Recovery Log
Replication Log
Relay Log
Single Threaded
Primary
Physical Replication
Buffer
Data
insert into person values(‘grant’); commit;
Parse
Recovery Log
Replication Log
Replica
Buffer
Data
Parse
Recovery Log
Replication Log
Relay Log
Synchronous vs. Asynchronous Replication
Synchronous Replication Write is not committed until it is written on both replicas Guarantees high durability (almost no data loss) Higher transaction latency Pay penalty now (maybe)
Asynchronous Replication Acknowledged as soon as written to the local storage Some level of durability (possible data loss) Can be far behind on shipping
About LOG SHIPPING – NOT APPLY
Asynchronous
insert into person values (‘grant’);
Primary Secondary
commit;
Replication Log Relay Log
grant
ACKACK
DURABLE in ONE LOCATIONDURABLE in TWO LOCATION
Synchronous
insert into person values (‘grant’);
Primary Secondary
commit;
Replication Log Relay Log
grant
ACKACK DURABLE in TWO LOCATION
Performance
1 2 40
1000
2000
3000
4000
5000
6000
Inserts
Aync Sync
Insert Threads
Tra
nsa
ctio
ns
Per
Sec
on
d
Max Apply Rate
Read Scaling Challenges
Eventual ConsistencyRead to Write Ratio
Eventual Consistency = Replication Lag
Primary Replica
Writer Reader
Large Commit = Replication Delay
0 12 24 36 48 60 72 84 96 1081201321441561681801922042162282402522642762883003123243363483603723840
10
20
30
40
50
60
Elapsed Time in Seconds
Rep
lica
tio
n D
elay
in
Sec
on
ds
500,000 rows
100,000 rows
Reasons for Replication Lag
Large transactionsSingle apply thread on replicaNetwork problemsOverloaded replica
DON’T ASSUME THE BEST CASE
Reads10% Reads10% Reads10% Reads10%Reads10% Reads10% Reads10% Reads10%
Reads10%Writes10%
Reads10%
Reads10%Writes10%
Reads10%Reads10%Writes10%
Reads10%
Reads10%Writes10%
Reads10%
Reads10%Writes10%
Reads10%
Reads10%Writes10%
Reads10%Reads10%Writes10%
Reads10%
Reads10%Writes10%
Reads10%
Reads10%Writes10%Reads10%
Writes10%Reads10%
Reads90%
Writes10%
Read to Write Ratio
Primary
Writes10%
Replica1
Writes10%
Replica2
Writes10%
Replica3
Writes10%
Replica4
1X2X3X SCALE
Writes 20% Writes 20% Writes 20% Writes 20%
Reads80%
Reads 20% Reads 20% Reads 20% Reads 20%
Reads 20%
Writes 20%
Reads 20%
Writes 20%
Reads 20%
Writes 20%
Reads 20%
Writes 20%
Writes 20%
Writes20%
Read to Write Ratio - More Writes
Primary Replica1 Replica2 Replica3 Replica4
1X2X SCALE
1 2 4 8 16 32 1
2
3
4
5
6
7
8 Scale based on % Write
50% 40% 30% 20% 10%
Number of Nodes
Sc
ale
What is RDS MySQL
Managed Relational Database Service (RDS) Automated Backups and Point in Time Recovery Can Scale CPU & Memory up and down Online storage scaling User controlled patching Multi-AZ replication Read Replicas
RDS MySQL - Replication
Multi-AZ Synchronous Replication Across Availability Zones (AZ) for increased durability Standby is not usable for reads Automated rebuilding of failed replica
Read Replica Standard Asynchronous MySQL replication Readable by default but also writeable Can have multiple per master
Highly Available, Durable, & Scalable MySQL Deployments
Multi-AZ Deployments Read Replicas
Demo of RDS Multi-AZ failover
THANK YOU