Top Banner
Jay Edwards & Ben Black PalominoDB {jay, ben}@palominodb.com MySQL in AWS Patterns
55

MYSQL Patterns in Amazon - Make the Cloud Work For You

Jan 15, 2015

Download

Technology

Blackbird.io

PalominodDB's Jay Edwards and Ben Black will show you how to build your MySQL environment in the cloud -- how to maintain it -- how to grow it -- and how to deal with failure.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: MYSQL Patterns in Amazon - Make the Cloud Work For You

Jay Edwards & Ben Black

PalominoDB

{jay, ben}@palominodb.com

MySQL in AWS

Patterns

Page 2: MYSQL Patterns in Amazon - Make the Cloud Work For You

Agenda

1. Introduction

2. RDS, EC2/MySQL

3. Web console, CLI, API

4. Performance/Availability

5. Implementation choices

6. Managing DDL

7. Common failures

8. Cost

9. Questions

Page 3: MYSQL Patterns in Amazon - Make the Cloud Work For You

About us

Jay!

CTO, PDB, OFA, Twitter

Ben!

Sr. DBA, PDB, Garmin

Booth? Yes. Hiring? Yes.

Page 4: MYSQL Patterns in Amazon - Make the Cloud Work For You

Interactivity

Ask away; we've got time. Ben will be glad to

try and solve your problems.

AWS tutorial?

• "Click on the replica button and come back

in 30 minutes"

• "PIOPs <-> EBS. Uncheck that box and

come back in 2 hours"

Page 5: MYSQL Patterns in Amazon - Make the Cloud Work For You

RDS and EC2/MySQL

Page 6: MYSQL Patterns in Amazon - Make the Cloud Work For You

RDS benefits

Fully managed

• High Availability

• Replicas? *click*

• PIT recover? *click*

• *click, click, click*

Page 7: MYSQL Patterns in Amazon - Make the Cloud Work For You

RDS un-benefits

Fully managed

• No binlog access

• No SUPER

• No flexible topology

The more experienced a DBA you are, the

crankier you will be.

Page 8: MYSQL Patterns in Amazon - Make the Cloud Work For You

RDS improves!

Like all AWS properties, RDS features continue

to improve all the time.

It's perfect for developers, proofs of concept,

one-offs, absorbing temporary load.

(Tungsten supports replication into RDS from

MySQL).

Page 9: MYSQL Patterns in Amazon - Make the Cloud Work For You

EC2/MySQL

All the MySQL you've come to love & hate

Multi-Region via replication & WAN tunnel

Page 10: MYSQL Patterns in Amazon - Make the Cloud Work For You

Why RDS or EC2?

RDS

1. You can tolerate ~99% uptime (which many

people can)

2. You don't have lots of DBAs and need to

optimize for operational ease

EC2

1. Multi-region availability

2. Vertical scaling

Page 11: MYSQL Patterns in Amazon - Make the Cloud Work For You

Questions?

Any particular scenarios you want to ask us

about?

Page 12: MYSQL Patterns in Amazon - Make the Cloud Work For You

Web Console, CLI, API

Page 13: MYSQL Patterns in Amazon - Make the Cloud Work For You

Overview

Functionality isn't complete

• some things aren't exposed via some

methods

Page 14: MYSQL Patterns in Amazon - Make the Cloud Work For You

Web Console

Most of the stuff you need for common day-to-

day maintenance

Sometimes:

• slow

• isn't working

• needs rage-clicking

Page 15: MYSQL Patterns in Amazon - Make the Cloud Work For You

CLI setup

RDS CLI

export AWS_RDS_HOME

export AWS_CREDENTIAL_FILE

(AWSAccessKeyId,AWSSecretKey)

Page 16: MYSQL Patterns in Amazon - Make the Cloud Work For You

CLI pain

It's written in Java right now*. The JVM

overhead makes it painfully slow for large-

scale automation.

* The future is the Redshift CLI (python,

coherent interface)

Page 17: MYSQL Patterns in Amazon - Make the Cloud Work For You

CLI output

Verbose and clunky

DBINSTANCE,scp01-replica2,2010-05-

22T01:53:47.372Z,db.m1.large,mysql,50,(nil),master,available,scp01-

replica2.cdysvrlmdirl.us-east-1.rds.amazonaws.com,3306,us-east-

1b,(nil),0,(nil),(nil),(nil),(nil),(nil),(nil),(nil),(nil),sun:05:00-sun:09:00,23:00-

01:00,(nil),n,5.1.50,n,simcoprod01,general-public-license

SECGROUP,Name,Status

SECGROUP,default,active

PARAMGRP,Group Name,Apply Status

PARAMGRP,default.mysql5.1,in-synch

Combining the worst features of machine- and human-readable text

formats.

Page 18: MYSQL Patterns in Amazon - Make the Cloud Work For You

API

Use Boto! (Mitch works for AWS).

Page 19: MYSQL Patterns in Amazon - Make the Cloud Work For You

Apply immediately.

--apply-immediately

Check the box hiding at the bottom of the page.

Page 20: MYSQL Patterns in Amazon - Make the Cloud Work For You

Availability

How many nines?

Page 21: MYSQL Patterns in Amazon - Make the Cloud Work For You

EC2 Region SLA

99.95% SLA

“Annual Uptime Percentage” is calculated by subtracting from 100% the percentage of 5 minute periods during the Service Year in which Amazon EC2 was in the state of “Region Unavailable.”

("Region unavailable" == "multiple AZs are toast")

Implies you've got to go multi-region

Page 22: MYSQL Patterns in Amazon - Make the Cloud Work For You

EC2 Region SLA

~99.2% Reality

The previous definition is very strict; 2 or more

regions; can't create instances; blah, blah.

1-2X year multi-AZ degradation (EBS, network,

who knows)

Page 23: MYSQL Patterns in Amazon - Make the Cloud Work For You

Multi-region

It's coming for RDS. Probably before the end of

the year.

Until then...

Page 24: MYSQL Patterns in Amazon - Make the Cloud Work For You

Always go Multi-AZ

Minimal downtime for most maintenance

Saves you from most master crashes

{Sometimes, often, frequently} destroys all

replicas

Page 25: MYSQL Patterns in Amazon - Make the Cloud Work For You

Multi-AZ binlogs

sync_binlog=1

innodb_support_xa=1

• used to DESTROY write throughput

• MySQL 5.6 drastic improvements

Page 26: MYSQL Patterns in Amazon - Make the Cloud Work For You

Questions?

Questions about designing for availability?

Page 27: MYSQL Patterns in Amazon - Make the Cloud Work For You

Implementation Choices

Page 28: MYSQL Patterns in Amazon - Make the Cloud Work For You

Instance sizing

Dynamicity == reduced cost

(Now, in general, $$ isn't why you go to the

cloud; it's operational efficiency & reduced

friction).

Have a spreadsheet and do capacity analyses

frequently.

Page 29: MYSQL Patterns in Amazon - Make the Cloud Work For You

Ephemeral SSDs

Really nice! 150,000* IOPs

Really bad! ~~POOF~~

• Excellent for replicas

• Requires operational excellence

* YMMV

Page 30: MYSQL Patterns in Amazon - Make the Cloud Work For You

Provisioned IOPs

Really, really nice!

• Drastically lower failure rate (order of

magnitude)

• Guaranteed throughput

Not so nice.

• Costs $$

Page 31: MYSQL Patterns in Amazon - Make the Cloud Work For You

Provisioned IOPs

Masters and replicas can be different.

You can convert PIOPs <-> EBS back and

forth.

Consider multi-AZ PIOPs master for the best in

durability.

Page 32: MYSQL Patterns in Amazon - Make the Cloud Work For You

VPCs

Go VPC from the beginning for production.

• Hard to convert

• Use ELBs for internal load-balancing

• Not sharing the 10.net with everybody

Page 33: MYSQL Patterns in Amazon - Make the Cloud Work For You

Cluster compute

Placement groups are available for CC

instances.

"Placement group" means "physically close

hardware".

Very low-latency 10GbE full bisection

Page 34: MYSQL Patterns in Amazon - Make the Cloud Work For You

Questions?

Questions about your particular setup?

Page 35: MYSQL Patterns in Amazon - Make the Cloud Work For You

Managing DDL

Page 36: MYSQL Patterns in Amazon - Make the Cloud Work For You

DDL

Not possible to perform ddl on a slave, then

swap with master.

Slave promotion

Blocking DDL

Page 37: MYSQL Patterns in Amazon - Make the Cloud Work For You

DDL

Online schema changes

(log_bin_trust_function_creators)

No OS access

Be careful cleaning up if you ctrl-c

CALL mysql.rds_skip_repl_error;

Page 38: MYSQL Patterns in Amazon - Make the Cloud Work For You

Questions?

Questions about DDL?

Page 39: MYSQL Patterns in Amazon - Make the Cloud Work For You

Escape from RDS

mysql schema

--routines

users?

Page 40: MYSQL Patterns in Amazon - Make the Cloud Work For You

Dumping Users

mysql --host=olddatabasehost -BNe "select

concat('\'',user,'\'@\'',host,'\'') from mysql.user where user

not like 'rds%' and user != 'master'" | \

while read uh; do mysql --host=olddatabasehost -BNe

"show grants for $uh" | sed 's/$/;/; s/\\\\/\\/g'; done >

user_grants.sql

http://www.villescorner.com/2012/11/mysqldump-from-

amazon-rds-headaches-of.html

Page 41: MYSQL Patterns in Amazon - Make the Cloud Work For You

Common failures

(Should really be called zones and regions)

Page 42: MYSQL Patterns in Amazon - Make the Cloud Work For You

Operations is about

managing change and

mitigating risk.

Page 43: MYSQL Patterns in Amazon - Make the Cloud Work For You

Local failures

Database crashes

Human error

Localized EBS hang

How to mitigate?

Multi-AZ PIOPs master

Operational excellence

Throw away & rebuild replicas

Page 44: MYSQL Patterns in Amazon - Make the Cloud Work For You

Local failures redux

Local failures should be, at most, annoyances.

Runbooks*

Game days

Monitoring

* Process is a poor substitute for competence.

Page 45: MYSQL Patterns in Amazon - Make the Cloud Work For You

If you can't deal with

expected and desired

change, you'll never be

able to handle unexpected

and unwanted change.

Page 46: MYSQL Patterns in Amazon - Make the Cloud Work For You

Regional failures

A well-designed architecture will save you.

How quickly can your DNS flip?

How good is your replication?

Do you have a CDN?

Is your application going to run?

Not everybody can afford this.

Page 47: MYSQL Patterns in Amazon - Make the Cloud Work For You

Zones and Regions

A zone is analogous to a data center (for some

small number of buildings).

A region is a geographically dispersed

collection of zones that is distinct from any

other region.

Page 48: MYSQL Patterns in Amazon - Make the Cloud Work For You

Zones & Regions differ

Different instance types

Different features

Different provisioning capacity

OFA had ~40% of the US-East medium

instances at one point. Couldn't duplicate that

in US-West

Page 49: MYSQL Patterns in Amazon - Make the Cloud Work For You

Questions?

Page 50: MYSQL Patterns in Amazon - Make the Cloud Work For You

Cost

Page 51: MYSQL Patterns in Amazon - Make the Cloud Work For You

Reserved instances

• Substantial savings (how often do you turn

off production databases?)

• Secondary market

• Must match AZ and instance size

• Discount coupon

Heavy utilization instances charge the

hourly rate 24x7

Page 52: MYSQL Patterns in Amazon - Make the Cloud Work For You

Watch the $

Spreadsheet!

Inventory!

Load analysis!

Cloudability!

Page 53: MYSQL Patterns in Amazon - Make the Cloud Work For You

Dynamicity

The only thing you can't do is downsize

storage.

Change instance size? Check.

Turn PIOPs off? Check.

Delete replicas? Check.

Up to meet need. Down to meet budget.

Page 54: MYSQL Patterns in Amazon - Make the Cloud Work For You

Upgrading

Minor upgrade (can be auto during maint

window / will reboot or failover)

*Disable this

Upgrade from 5.5 to 5.6

1) Dump/load

2) Delta load

3) Switchover

Page 55: MYSQL Patterns in Amazon - Make the Cloud Work For You

Fin

Ask away!