aws re:invent 2016: amazon aurora best practices: getting the best out of your databases (dat301)

71
© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Puneet Agarwal AWS Solutions Architect Steve Abraham AWS Solutions Architect Mario Kostelac Intercom Product Engineer November 30, 2016 Amazon Aurora Best Practices Getting the Best Out of Your Databases DAT301

Upload: amazon-web-services

Post on 11-Jan-2017

121 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

© 2016, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

Puneet Agarwal – AWS Solutions Architect

Steve Abraham – AWS Solutions Architect

Mario Kostelac – Intercom Product Engineer

November 30, 2016

Amazon Aurora Best PracticesGetting the Best Out of Your Databases

DAT301

Page 2: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

What to Expect from the Session

• Migration best practices

• Performance best practices

• Real-time reporting and analytics

• Concurrent event stores

• Integration with AWS services

• Welcome Intercom!

Page 3: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Amazon Aurora

• MySQL-compatible relational

database

• Performance and availability of

commercial databases

• Simplicity and cost effectiveness of

open source databases

• Delivered as managed serviceFastest growing service

in AWS history

Page 4: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best practices: Migrations

Page 5: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Amazon Aurora migration options

Source database From where Recommended option

RDS

EC2, on-premises

EC2, on-premises, RDS

Console based automated

snapshot ingestion and catch

up via binlog replication.

Binary snapshot ingestion

through S3 and catch up via

binlog replication.

Schema conversion using

SCT and data migration via

DMS.

Page 6: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

DB snapshot migration

One-click migration from

RDS MySQL 5.6 to Aurora

Automatic conversion from

MyISAM to InnoDB

Most migrations take <1 hr,

longer for large databases

One click replication from

RDS MySQL to Amazon

Aurora

DB

Snapshot

One-click

Migrate

RDS MySQL

Master/Slave New Aurora

Cluster

Page 7: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Migrating from self-managed MySQL to Aurora

• Import MySQL snapshots into Aurora through

S3

1) Execute Percona XtraBackup

2) Upload database snapshot to S3

3) Import snapshot from S3 to Aurora cluster

4) Setup logical replication to catch-up

5) Transition database workload to Aurora

cluster

• Faster migration for large databases (1+ TB)

• Import schema and data in one operation

Page 8: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Demo: Restore from S3

Page 9: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 10: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best practices – binary snapshot ingestion

• File splitting and compression recommended for 1+ TB databases

• Supported file compression formats:1. Gzip (.gz)

2. Percona xbstream (.xbstream)

• Sample compression and splitting command:• innobackupex --user=myuser --password=<password> --stream=tar

\ /mydata/s3-restore/backup | gzip | split -d --bytes=512000 \- /mydata/s3-restore/backup3/backup.tar.gz

• Import separately:1. User accounts/passwords

2. Functions

3. Stored procedures

Page 11: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Data copy: Existing data is copied from source tables to tables on the target.

Chance data capture and apply: Changes to data on source are captured

while the tables are loaded. Once load is complete, buffered changes are

applied to the target. Additional changes captured on the source are applied to the target until the task

stopped or terminated AWS Database

Migration Service

AWS Schema

Conversion Tool

Oracle, SQL Server to Aurora Migration

Assessment report: SCT analyses the source database and provides a

report with a recommended target engine and information on automatic

and manual conversions

Code Browser and recommendation engine: Highlights places that require

manual edits and provides architectural and design guidelines.

Page 12: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Demo: Oracle to Aurora

migration

Page 13: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 14: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Migration best practices

• Use the right migration approach for your use case

• Test, migrate, test again!

• Consolidate shards on Aurora

• Schema conversion

• Schema optimization post conversion

• For tables with wide text columns, enable DYNAMIC row format

• Primary key implementation differences

Page 15: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best practices: Performance

Page 16: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Aurora performance characteristics

Optimized for highly concurrent random access (OLTP)

Performance scales with number of connections

Consistent performance as number of

databases/schemas/tables increase

Consistent performance with increasing number of

Aurora read-replicas

Low replication lag

Page 17: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Performance testing

h t t p s : / / d 0 . a w s s t a t i c . c o m / p r o d u c t - m a rk e t i n g / Au r o r a / R D S_ Au r o r a _ Pe r f o r m a n c e _ As s e s s m e n t _ Be n c hm a r k i n g _ v 1 - 2 . p d f

AMAZON

AURORA

R3.8XLARGE

R3.8XLARGE

R3.8XLARGE

R3.8XLARGE

R3.8XLARGE

• Create an Amazon VPC (or use an existing one).

• Create four EC2 R3.8XL client instances to run the

SysBench client. All four should be in the same AZ.

• Enable enhanced networking on your clients.

• Tune your Linux settings (see whitepaper).

• Install Sysbench version 0.5.

• Launch a r3.8xlarge Amazon Aurora DB instance in

the same VPC and AZ as your clients.

• Start your benchmark!

1

2

3

4

5

6

7

Page 18: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Performance Best Practices

MySQL/RDBMS practices still apply

Choose the right tool for the right job (OLAP vs OLTP)

Create appropriate indexes

Tune your SQL code, use explain plans, performance schema

Leverage high concurrency

Aurora throughput increases with number of connections

Architect your applications to leverage high concurrency in Aurora

Read Scaling

Aurora offers read replicas with virtually no replication lag

Leverage multiple read replicas to distribute your reads

Page 19: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Performance Best Practices

Parameter tuning

No need to migrate your performance-related MySQL parameters to

Aurora

Aurora Parameter Groups are pre-tuned and already optimal in most

cases

Performance comparison

Don’t obsess over individual metrics (CPU, IOPS, IO throughput)

Focus on what matters, i.e., application performance

Other best practices

Keep query cache on

Leverage CloudWatch metrics

Page 20: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best Practices: Real-Time

Reporting & Analytics

Page 21: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Scenario

• Travel & Booking Industry

• Live Contextual Product Recommendations

• Near Real-Time Reporting

• ~700+ Users

• ~8 TB Dataset

• Usage cycles over 24 hour period

• Cost Considerations

Page 22: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Database EngineStorage Backend

Application Users

Challenges – Original Design

Page 23: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Aurora Cluster

Application Users

DNS Endpoint

Load Balanced

Solutions – New Design

Page 24: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Scheduled Job Reads

Instance Load Metrics

and Calls Lambda

Cluster Instances

Added, Removed

or Resized

Lambda Function

Applies Logic

and Calls RDS API

Desired Scale

Achieved

Solutions – Fleet Scaling

Page 25: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best practices: Massively

Concurrent Event Stores

Page 26: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Scenario

• Gaming Industry

• Millions of RPS

• Consistent Latency

• Cost Considerations

Page 27: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

NoSQL (performance, steady state)

Partitioned

NoSQL TableUser Applications User Applications

Optimal Performance

Under Moderate Load

Page 28: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

NoSQL (performance “hot” state)

Partitioned

NoSQL TableUser Applications User Applications

Degraded Performance

Under Heavy Load

Page 29: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Aurora implementation (performance)

Aurora ClusterUser Applications User Applications

Consistent Performance

Under Load

Page 30: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

NoSQL implementation (cost)

Partitioned

NoSQL TableUser Applications

Each Read/Write

Billed Separately

Page 31: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Aurora implementation (cost)

Aurora ClusterUser Applications

Most Operations

Served From Memory

Small Portion of IO

Requests Billed

Cost-Efficient

Storage

Page 32: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Best practices: AWS Service

Integrations

Page 33: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

AWS Services

Generating Data

Amazon S3

Data Lake

Amazon Aurora

Load From S3

S3 Event Driven

Lambda Call

Lambda Call

S3 Load Completed

Notification Delivered

Data Flow

Call / Notification

Flow

Event Driven Data Pipeline

Page 34: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

User Modifies a

Monitored Table

Table Trigger

Invokes Lambda

Lambda Function

Applies Logic

Security Notification

Delivered

Event Driven Audit Notification

Page 35: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Demo: Lambda Integration

Page 36: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Amazon SQS

Aurora Cluster

AWS Lambda

Amazon SNSAmazon CloudWatch AWS Lambda

Demo: Lambda Integration

Page 37: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 38: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Mario KostelacProduct engineer

mariokostelac

Page 39: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

?

Page 40: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 41: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

How did we start using Aurora?

Page 42: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 43: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

<>

Page 44: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Our stack

<whatever>.js

Page 45: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Our first MySQL instance

Page 46: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Then we got bigger...

Page 47: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

And bigger…

Page 48: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Eventually, two MySQL instances…

Page 49: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Why so slow?

Page 50: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

2 billion rows problem

- Your table can’t fit in RAM

- Your table can’t fit in RAM!

- You can’t modify your table schema

Page 51: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Page 52: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Replace RDS MySQL with?

- DynamoDB

- Partitioned RDS MySQL

- Aurora?

Page 53: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Is Aurora good enough for us?

Page 54: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 55: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Test your load!

Page 56: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

“The only testing that should matter to

you is testing against YOUR production

load!”

me, right now!

Page 57: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

How to test your load?

1. Test your tools (why?)

2. Create an image of your load! (how?)

3. Test your load!

Page 58: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

MySQL

prod

Aurora MySQL

prod

How we migrated from RDS MySQL to

Aurora?

Page 59: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Write a migration runbook!

1. Downtimes are stressful

2. Induced downtimes have to be

carefully planned

Page 60: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)
Page 61: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

🚀 Migrated within 8 minutes of

downtime, no records lost!

Page 62: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

How does it work for us?

Page 63: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Use secondaries when you can

Page 64: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Check your drivers

Page 65: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Build your tooling

Page 66: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

What don’t we have to do anymore?

Cluster monitoring got simpler Parameter tweaking

Page 67: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

So you say it’s impossible to break

it?

Page 68: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Test your load! Write a runbook! Use secondaries

Check your drivers! Build your tooling

Page 69: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Thank you!

Page 70: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Related Sessions

• DAT203 - Getting Started with Amazon Aurora

• DAT303 - Deep Dive on Amazon Aurora

• DAT302 - Best Practices for Migrating from Commercial

Database Engines to Amazon Aurora or PostgreSQL

Page 71: AWS re:Invent 2016: Amazon Aurora Best Practices: Getting the Best Out of Your Databases (DAT301)

Remember to complete

your evaluations!