amazon rds for mysql: best practices and data …...things to consider – read replicas • mysql...

38
© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc. Amazon RDS for MySQL: Best Practices and Data Migration

Upload: others

Post on 16-Feb-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Amazon RDS for MySQL: Best

Practices and Data Migration

Page 2: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after
Page 3: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Multi-AZ deployments

Physical

Synchronous

Replication

AZ1 AZ2

DNS

cname update

Primary Update

Less than 2 minutes for failover

New!

Page 4: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Read Replicas

Sync

Replication

Async Replication

Page 5: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Logical Failover – Replicas of Replicas

Sync

Replication

Async Replication

Page 6: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Things to consider – Read Replicas

• MySQL replication is single-threaded

• MySQL 5.1 and 5.5 – Replication may stop after crash recovery on the master – sync_binlog = 0 by default

– Includes Multi-AZ failover

– mysql.rds_next_master_log if potential missing info. is acceptable.

• MySQL 5.6 – Crash safe slaves – sync_binlog = 1 by default

– Less performance impact but more replica reliability

Page 7: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after
Page 8: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Backup and Restore

Amazon S3

AZ1 AZ2

Log

2

Log

1

Log

5

Page 9: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Cross Region – Snapshot Copy

Amazon

S3

AZ1

Region 1 Region 2

Amazon

S3

AZ3

Page 10: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Cross Region – Read Replicas

AZ1

Region 1 Region 2

AZ3

Page 11: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after
Page 12: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Provisioned IOPS - Scale

0

2,500

5,000

7,500

10,000

12,500

15,000

17,500

20,000

T

P

S

db.m2.4xlarge - 130GB Data - Partial Random Read Workload

333GB - Regular 333GB - 1000 PIOPS 300GB - 3000 PIOPS

Page 13: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Provisioned IOPS - Latency

7.69%

1.38%

0.01%

7.89%

0.42% 0.00%

3.83%

0.00% 0.00% 0%

1%

2%

3%

4%

5%

6%

7%

8%

9%

3-20 ms 20-500ms >500ms

Perc

en

tag

e i

n L

ate

ncy B

ucket

db.m2.4xlarge - 130GB Data - Partial Random Read Workload - Max Rate

333GB - Regular 333GB - 1000 PIOPS 300GB - 3000 PIOPS

Page 14: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Provisioned IOPS - Scale

0

2,500

5,000

7,500

10,000

12,500

15,000

17,500

20,000

T

P

S

db.m2.4xlarge - 130GB Data - Partial Random Read Workload

333GB - Regular 333GB - 1000 PIOPS 300GB - 3000 PIOPS

Target = 5000

Page 15: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Provisioned IOPS– Latency @ 5000 TPS

7.89%

1.17%

0.04% 0.35%

0.00% 0.00% 0.27%

0.00% 0.00% 0%

1%

2%

3%

4%

5%

6%

7%

8%

9%

3-20 ms 20-500ms >500ms

Perc

en

tag

e i

n L

ate

ncy B

ucket

db.m2.4xlarge - 130GB Data - Partial Random Read Workload - 5000 TPS

333GB - Regular 333GB - 1000 PIOPS 300GB - 3000 PIOPS

Page 16: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Provisioned IOPS– 10,000 IOPS

0

5,000

10,000

15,000

20,000

25,000

30,000

35,000

40,000

T

P

S

db.m2.4xlarge - 130GB Data - Partial Random Read Workload

333GB - Regular 333GB - 1000 PIOPS

300GB - 3000 PIOPS 1000GB-10000 PIOPS

Page 17: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

What Limit? – Amazon CloudWatch

Metrics

Page 18: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Bottlenecks and Scaling

DB Instance Class • db.t1.micro – db.cr1.8xlarge

• 1-88 ECU

• 0.6 – 244 GB RAM

IOPS • Regular or 1,000-30,000

Storage • 5GB - 100GB - 3TB

Ratio 3:1 to 10:1

Throughput • EBS Optimized (0.5 -1Gbit)

• db.m1.large,db.m1.xlarge,m2.2xlarge,m2.4xlarge

• db.cr1.8xlarge – 10Gbit

• Regular + non optimized – shared

Memory to ECU Ratio • 1.7 to 2.8 (exclude micro)

DB Engine • Block Size 8 – 16K

• Ability to utilize resources

Page 19: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Read/Write Benchmark

5,850 13,200

42,000 47,000

-

10,000

20,000

30,000

40,000

50,000

60,000

70,000

80,000

TP

S

130GB Data - Partial Random 90R/10W Workload 10K IOPS

db.m1.large db.m1.xlarge db.m2.4xlarge db.cr1.8xlarge

cpu 85%

r/s 3450

w/s 600

rMB/s 52

cpu 100%

r/s 6800

w/s 950

rMB/s 104

cpu 95%

r/s 6800

w/s 2600

rMB/s 104

cpu 40%

r/s 0

w/s 3200

rMB/s 0

Page 20: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Bottlenecks and Scaling – Read Replicas

Page 21: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Read/Write Benchmark – Using RR

5,850 13,200

42,000 47,000

126,000

-

20,000

40,000

60,000

80,000

100,000

120,000

TP

S

130GB Data - Partial Random 90R/10W Workload – 10K IOPS

db.m1.large db.m1.xlarge db.m2.4xlarge db.cr1.8xlarge cr1 + 3 x 4xlarge

Page 22: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Things to consider – Provisioned IOPS

• Use Provisioned IOPS optimized instances – M1.L, M3.XL, M2.2XL (500Mbps)

– M1.XL, M3.2XL, M2.4XL (1000Mbps)

– CR1.8XL (>1000 Mbps)

• Understand Channel Bandwidth – Full duplex

– 1000 Mbps ~ 100MBps (with protocol overhead) or

– 100 MBps ~ 6250 16KB IOPS

Page 23: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Things to consider – Provisioned IOPS

• Max realizable IOPS – Workload dependent

– 1:1 R/W -> Max realizable IOPS ~12.5K 16KB IOPS for M2.4XL

– 1:1 R/W -> 20K 16KB IOPS for CR1.8XL

• Provisioning more than Max can help lower latency

• IO Size – IO Sizes <= 16KB is same

– IO Sizes > 16KB consumes more IO

– 6250 16KB IOPS = 3125 32KB IOPS

Page 24: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Things to consider – Provisioned IOPS

• Not able to realize IOPS provisioned? – Using Provisioned IOPS optimized instances?

– Running automated backups, snapshots, scale storage?

– Reviewed Queue Depth?

– Database contention? Locking? Deadlocks?

Page 25: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Other Best Practices

• Storage Engine – Avoid MyISAM – not transactional

• Cloudwatch alarms – CPU, Memory, Storage, Latency, Replica Lag

• SMS/email notifications – Failover, Replication status

• Number of Tables – Not more than 1000 tables (standard) and 10,000 tables (PIOPS)

Page 26: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after
Page 27: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

RDS Pre-Migration Steps

• Stop applications accessing the DB

• Take a snapshot

• Disable backups

• Use Single-AZ instances

• Configure security for cross-DB traffic

Page 28: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Importing from a MySQL DB Instance

DB

Application

Staging

area AWS Region

Replication

Application

mysqldump scp

Tsunami UDP

Load data

Staging server

Page 29: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Create a DB Instance for MySQL and EC2

PROMPT>rds-create-db-instance mydbinstance -s 1024 -c db.m3.2xlarge -e MySQL - u

<masterawsuser> -p <secretpassword> --backup-retention-period 3

Create DB instance for MySQL using AWS Management Console or CLI

aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type m3.2xlarge --key-name

MyKeyPair --security-groups MySecurityGroup

Create Amazon EC2 (Staging server) using AWS Management Console or CLI

mysql> GRANT SELECT,REPLICATION USER,REPLICATION CLIENT ON *.* TO

repluser@‘<RDS Endpoint>' IDENTIFIED BY ‘<password>';

Create replication user on the master

Page 30: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Configure the Master Database

$ mysql -h localhost -u root -p

mysql> show master status\G

*************************** 1. row ***************************

File: mysql-bin.000023

Position: 107

Binlog_Do_DB: mytest

Binlog_Ignore_DB:

1 row in set (0.00 sec)

Record the “File” and the “Position” values.

Page 31: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Importing from a MySQL DB Instance

Page 32: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Upload Files to Amazon EC2 using UDP

• Tar and compress MySQL dump file preparation to

ship to Amazon EC2 staging server.

• Update the Amazon EC2 security group to allow

UDP connection from the server where the dump file

is being created to your new MySQL client server.

• On the Amazon EC2 staging instance, untar the

tar.tgz file.

Page 33: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Configure the Amazon RDS database

mysql> create database bench;

Create the database

Mysql> load data local infile '/reinvent/tables/customer_address.txt' into table customer_address

fields terminated by ',';

Mysql> load data local infile '/reinvent/tables/customer.txt' into table customer fields terminated by ',';

Import the database that you previously exported from the master database

mysql> call mysql.rds_set_external_master(‘<master

server>',3306,‘<replicationuser>',‘<password>','mysql-bin.000013',107,0);

mysql> call mysql.rds_start_replication;

Configure the slave DB instance for MySQL, and start the slave server

Page 34: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

Make Amazon RDS instance the Master

Switch over to the RDS instance – Stop the service/application that is pointing at the Master

Database

– Once all changes have been applied to New RDS

Database. Stop replication with “call mysql.rds_stop_replication”

– Point the service/application at the New RDS Database.

– Once Migration is complete. “call mysql.

rds_reset_external_master”

Page 35: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

RDS Post-migration Steps

• Turn on backups

• Turn on multi-az

• Tighten down security

• Set up alarms for key metrics

• Turn on notifications for Database Events

Page 37: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Questions?

Page 38: Amazon RDS for MySQL: Best Practices and Data …...Things to consider – Read Replicas • MySQL replication is single-threaded • MySQL 5.1 and 5.5 – Replication may stop after

© 2011 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.

Thank You