Top Banner
How to scale out MySQL databases CloudParty 2013 – Database in Cloud – Milan 27 Sep Walter Dal Mut - @walterdalmut www.corley.it
70

MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Jan 28, 2015

Download

Technology

Corley S.r.l.

MySQL scalability, from shodow instances to Master/Slave and Master/Master architectures.
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 - Scale Out @ CloudParty 2013 Milano Talent Garden

How to scale out MySQL databasesCloudParty 2013 – Database in Cloud – Milan 27 Sep

Walter Dal Mut - @walterdalmut

www.corley.it

Page 2: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

http://www.slideshare.net/ziobrando/ddd-dirty-harry-styleCloudParty 2013 - 27 Sep Milan Italy

Page 3: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Why we are interested in:Scale-Out databases on the Cloud?

CloudParty 2013 - 27 Sep Milan Italy

Page 4: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 5: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

We need more resources

Single hard drives has limitsNetwork interfaces too

And so on...

CloudParty 2013 - 27 Sep Milan Italy

Page 6: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

We are also looking for availability

CloudParty 2013 - 27 Sep Milan Italy

Page 7: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

we want toensure SERVICE availability

and NOTserver availability

CloudParty 2013 - 27 Sep Milan Italy

Page 8: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Availability % Downtime per Month

90% 72 Hours

95% 36 Hours

99% 7.2 Hours

99.5% 3.6 Hours

99.8 86.23 Minutes

99.95 21.56 Minutes

99.99 4.32 Minutes

Page 9: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Ok, we can start...First of all we have to talk about

replication

CloudParty 2013 - 27 Sep Milan Italy

Page 10: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 11: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

How many kind of replications?

CloudParty 2013 - 27 Sep Milan Italy

Page 12: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Synchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

Page 13: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Sync Replicais the process that writes data to the primary and secondary node at the

SAME time.It is more expensive and introduce latency that slow down the application

because.

CloudParty 2013 - 27 Sep Milan Italy

Page 14: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Asynchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

Page 15: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Async ReplicaIs the process that writes data to the primary and secondary node at different

time.Is more simple, a primary node doesn't care about others

CloudParty 2013 - 27 Sep Milan Italy

Page 16: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Semi-Synchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

Page 17: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Semi-Sync ReplicaOn the master side, write when at least one slave acknowledges that is has

received all events

CloudParty 2013 - 27 Sep Milan Italy

Page 18: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Which kind of replications can we sort up with MySQL?

CloudParty 2013 - 27 Sep Milan Italy

Page 19: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

ASYNC Master/Slave Replica(Read Replicas)

CloudParty 2013 - 27 Sep Milan Italy

Page 20: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

ASYNC Master/Master Replica(Read/Write replicas)

CloudParty 2013 - 27 Sep Milan Italy

Page 21: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Always Async!That means: LAG REPLICA TIME

CloudParty 2013 - 27 Sep Milan Italy

Page 22: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Just this?

CloudParty 2013 - 27 Sep Milan Italy

Page 23: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Semi-Sync ReplicasStarting with MySQL 5.5Implemented by plugins

http://dev.mysql.com/doc/refman/5.5/en/replication-semisync.html

CloudParty 2013 - 27 Sep Milan Italy

Page 24: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

A slave indicates that it is semy-sync capableOn the master side, write when at least one slave acknowledges that is has

received all eventsIf no one slave is available, the master revert to async replication

If one slave catches up, the master returns to semi-sync replication

CloudParty 2013 - 27 Sep Milan Italy

Page 25: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

And if I need something SYNC?

CloudParty 2013 - 27 Sep Milan Italy

Page 26: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Percona XtraDB ClusterMySQL Cluster NDB (internally)

CloudParty 2013 - 27 Sep Milan Italy

Page 27: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Instead using MySQL Replicationwe can look for replication of network devices

“Distributed Replication Block Device”DRBD

http://www.drbd.org/users-guide-8.3/ch-heartbeat.htmlhttp://dev.mysql.com/doc/refman/5.0/en/ha-drbd.html

CloudParty 2013 - 27 Sep Milan Italy

Page 28: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

DRBD is essentially a RAID 1 on a network

CloudParty 2013 - 27 Sep Milan Italy

Page 29: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

DRBD has 3 replication modes:A → Async

B → Semi Sync

C → Sync

CloudParty 2013 - 27 Sep Milan Italy

Page 30: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

global { usage-count no; }common { net { protocol C; } }resource r0 { on drbd01 { device /dev/drbd0; disk /dev/sdb1; address 192.168.0.1:7788; meta-disk internal; } on drbd02 { device /dev/drbd0; disk /dev/sdb1; address 192.168.0.2:7788; meta-disk internal; }}

CloudParty 2013 - 27 Sep Milan Italy

Page 31: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Exactly like a RAID1 array you cannot query the “second device”

It means that: “the device” on a secondary node is not mounted/available

CloudParty 2013 - 27 Sep Milan Italy

Page 32: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 33: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

DRBD is a RAID on networksyour entire system doesn't switch automatically in case of

failures.In order to automate the failover switch you can use

Peacemaker/Corosync

http://dev.mysql.com/doc/refman/5.5/en/ha-drbd.html

CloudParty 2013 - 27 Sep Milan Italy

Page 34: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 35: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

AWS RDS – Multi AZ

CloudParty 2013 - 27 Sep Milan Italy

Page 36: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 37: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 38: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master/Slave – Read ReplicasAsync Replication

CloudParty 2013 - 27 Sep Milan Italy

Page 39: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 40: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 41: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master-Slave: Writes-Reads

CloudParty 2013 - 27 Sep Milan Italy

Page 42: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 43: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 44: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Capacity left for READS

Capacity left for WRITES

Master-Slave: Write Intensive

CloudParty 2013 - 27 Sep Milan Italy

Page 45: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master/Master – Multi MasterAsync Replication

CloudParty 2013 - 27 Sep Milan Italy

Page 46: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

A primary nodesee the secondary node

as a slaveand vice-versa

CloudParty 2013 - 27 Sep Milan Italy

Page 47: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master M1 Slave M1

CloudParty 2013 - 27 Sep Milan Italy

Page 48: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master M1Slave M2

Slave M1Master M2

CloudParty 2013 - 27 Sep Milan Italy

Page 49: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Super Easy! But, it works?

CloudParty 2013 - 27 Sep Milan Italy

Page 50: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

YES?

CloudParty 2013 - 27 Sep Milan Italy

Page 51: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden
Page 52: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Why?

CloudParty 2013 - 27 Sep Milan Italy

Page 53: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Because of auto increment columns

CloudParty 2013 - 27 Sep Milan Italy

Page 54: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

As a cause of LAG replication time two auto-increment keys conflicts quite immediately in a

production environment!

CloudParty 2013 - 27 Sep Milan Italy

Page 55: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

1 1

22

APPLICATION APPLICATIONMASTER 1 MASTER 2

INSERT

INSERT

Both replica stops immediately on replication (split brain)

INSERT INTO table (id) VALUES (2)

INSERT INTO table (id) VALUES (2)

CloudParty 2013 - 27 Sep Milan Italy

Page 56: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Any solution?

CloudParty 2013 - 27 Sep Milan Italy

Page 57: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Avoid auto-increments columns

CloudParty 2013 - 27 Sep Milan Italy

Page 58: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 59: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Work on auto-increment columns

CloudParty 2013 - 27 Sep Milan Italy

Page 60: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

l auto_increment_increment controls the increment between successive AUTO_INCREMENT values.

l auto_increment_offset determines the starting point for AUTO_INCREMENT column values.

CloudParty 2013 - 27 Sep Milan Italy

Page 61: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

server-id=1auto-increment-offset = 1

auto-increment-increment = 4Produces: 1 5 9 13 17 21 25

server-id=2auto-increment-offset = 2

auto-increment-increment = 4Produces: 2 6 10 14 18 22 26

CloudParty 2013 - 27 Sep Milan Italy

Page 62: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

CloudParty 2013 - 27 Sep Milan Italy

Page 63: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Collisions can occurs on all unique indexesUser names, emails e unique fields in general causes

collisions in a asynchronous replicated database.The application must ensure zero collisions

CloudParty 2013 - 27 Sep Milan Italy

Page 64: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

You have to deal also with inconsistencies

CloudParty 2013 - 27 Sep Milan Italy

Page 65: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master Master

Application

UPDATE users SET email='[email protected]' where id=1;

UPDATE users SET email='[email protected]' where id=1;

[email protected]

[email protected]

[email protected]

[email protected]

CloudParty 2013 - 27 Sep Milan Italy

Page 66: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Do we have scale writes?

CloudParty 2013 - 27 Sep Milan Italy

Page 67: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

NO!

CloudParty 2013 - 27 Sep Milan Italy

Page 68: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Master-Master: Writes-Reads

Every write still has to be performed on both masters!CloudParty 2013 - 27 Sep Milan Italy

Page 69: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

We can use Master/Master for:

High Availability (Hot Stand-By)Maintenance Tasks

CloudParty 2013 - 27 Sep Milan Italy

Page 70: MySQL - Scale Out @ CloudParty 2013 Milano Talent Garden

Thanks for listeningAny question?

[email protected]@walterdalmut

CloudParty 2013 - 27 Sep Milan Italy