Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

27
Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister

Transcript of Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Page 1: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Replication for Availability & Durability with MySQL and Amazon RDS

Grant McAlister

Page 2: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.
Page 3: 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.

Page 4: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Why Replicate?

DurabilityAvailabilityScaling

Page 5: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Durability

Replicate

Location 1 Location 2

Page 6: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 7: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Read Scaling

Master Replica1

R/WClient

R/WClient

ReadClient

Replica2 Replica3

ReadClient

ReadClient

ReadClient

Page 8: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Replication Options

Logical vs. PhysicalSynchronous vs. Asynchronous

Page 9: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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)

Page 10: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 11: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 12: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 13: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Asynchronous

insert into person values (‘grant’);

Primary Secondary

commit;

Replication Log Relay Log

grant

ACKACK

DURABLE in ONE LOCATIONDURABLE in TWO LOCATION

Page 14: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Synchronous

insert into person values (‘grant’);

Primary Secondary

commit;

Replication Log Relay Log

grant

ACKACK DURABLE in TWO LOCATION

Page 15: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 16: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Read Scaling Challenges

Eventual ConsistencyRead to Write Ratio

Page 17: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Eventual Consistency = Replication Lag

Primary Replica

Writer Reader

Page 18: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 19: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Reasons for Replication Lag

Large transactionsSingle apply thread on replicaNetwork problemsOverloaded replica

DON’T ASSUME THE BEST CASE

Page 20: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 21: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 22: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 23: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 24: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

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

Page 25: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Highly Available, Durable, & Scalable MySQL Deployments

Multi-AZ Deployments Read Replicas

Page 26: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

Demo of RDS Multi-AZ failover

Page 27: Replication for Availability & Durability with MySQL and Amazon RDS Grant McAlister.

THANK YOU