mysql - scale out @ cloudparty 2013 milano talent garden

Post on 28-Jan-2015

105 Views

Category:

Technology

2 Downloads

Preview:

Click to see full reader

DESCRIPTION

MySQL scalability, from shodow instances to Master/Slave and Master/Master architectures.

TRANSCRIPT

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

Walter Dal Mut - @walterdalmut

www.corley.it

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

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

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

We need more resources

Single hard drives has limitsNetwork interfaces too

And so on...

CloudParty 2013 - 27 Sep Milan Italy

We are also looking for availability

CloudParty 2013 - 27 Sep Milan Italy

we want toensure SERVICE availability

and NOTserver availability

CloudParty 2013 - 27 Sep Milan Italy

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

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

replication

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

How many kind of replications?

CloudParty 2013 - 27 Sep Milan Italy

Synchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

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

Asynchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

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

Semi-Synchronous Replication

CloudParty 2013 - 27 Sep Milan Italy

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

Which kind of replications can we sort up with MySQL?

CloudParty 2013 - 27 Sep Milan Italy

ASYNC Master/Slave Replica(Read Replicas)

CloudParty 2013 - 27 Sep Milan Italy

ASYNC Master/Master Replica(Read/Write replicas)

CloudParty 2013 - 27 Sep Milan Italy

Always Async!That means: LAG REPLICA TIME

CloudParty 2013 - 27 Sep Milan Italy

Just this?

CloudParty 2013 - 27 Sep Milan Italy

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

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

And if I need something SYNC?

CloudParty 2013 - 27 Sep Milan Italy

Percona XtraDB ClusterMySQL Cluster NDB (internally)

CloudParty 2013 - 27 Sep Milan Italy

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

DRBD is essentially a RAID 1 on a network

CloudParty 2013 - 27 Sep Milan Italy

DRBD has 3 replication modes:A → Async

B → Semi Sync

C → Sync

CloudParty 2013 - 27 Sep Milan Italy

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

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

CloudParty 2013 - 27 Sep Milan Italy

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

CloudParty 2013 - 27 Sep Milan Italy

AWS RDS – Multi AZ

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

Master/Slave – Read ReplicasAsync Replication

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

Master-Slave: Writes-Reads

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

Capacity left for READS

Capacity left for WRITES

Master-Slave: Write Intensive

CloudParty 2013 - 27 Sep Milan Italy

Master/Master – Multi MasterAsync Replication

CloudParty 2013 - 27 Sep Milan Italy

A primary nodesee the secondary node

as a slaveand vice-versa

CloudParty 2013 - 27 Sep Milan Italy

Master M1 Slave M1

CloudParty 2013 - 27 Sep Milan Italy

Master M1Slave M2

Slave M1Master M2

CloudParty 2013 - 27 Sep Milan Italy

Super Easy! But, it works?

CloudParty 2013 - 27 Sep Milan Italy

YES?

CloudParty 2013 - 27 Sep Milan Italy

Why?

CloudParty 2013 - 27 Sep Milan Italy

Because of auto increment columns

CloudParty 2013 - 27 Sep Milan Italy

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

production environment!

CloudParty 2013 - 27 Sep Milan Italy

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

Any solution?

CloudParty 2013 - 27 Sep Milan Italy

Avoid auto-increments columns

CloudParty 2013 - 27 Sep Milan Italy

CloudParty 2013 - 27 Sep Milan Italy

Work on auto-increment columns

CloudParty 2013 - 27 Sep Milan Italy

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

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

CloudParty 2013 - 27 Sep Milan Italy

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

You have to deal also with inconsistencies

CloudParty 2013 - 27 Sep Milan Italy

Master Master

Application

UPDATE users SET email='your.email@me.com' where id=1;

UPDATE users SET email='ane@y.com' where id=1;

ane@y.com

your.email@me.com

your.email@me.com

ane@y.com

CloudParty 2013 - 27 Sep Milan Italy

Do we have scale writes?

CloudParty 2013 - 27 Sep Milan Italy

NO!

CloudParty 2013 - 27 Sep Milan Italy

Master-Master: Writes-Reads

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

We can use Master/Master for:

High Availability (Hot Stand-By)Maintenance Tasks

CloudParty 2013 - 27 Sep Milan Italy

Thanks for listeningAny question?

walter.dalmut@corley.it@walterdalmut

CloudParty 2013 - 27 Sep Milan Italy

top related