34
Scaling MySQL in 2014? Przemysław Malkowski Atmosphere 2014

Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

Scaling MySQL in 2014? Przemysław Malkowski

Atmosphere 2014

Page 2: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

What is this talk about?

● Is MySQL still a good choice for today's web projects?

● Does it work on scale?● Does it work in cloud?● How MySQL is evolving to keep up with

changes?● What are the best practices to scale?● Improved replication and clustering

Page 3: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Still right choice?

● MySQL first released in 1995● Open Source/GPL (3.23) since 2000/2001● Owner changes – MySQL AB, Sun, Oracle● Competition – Percona, MariaDB● NoSQL movement● Cloud boom

Page 4: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Most popular database for web

● 'M' in LAMP● Default database for webhosting offers● Most popular CMS/blog/forum software supports

mainly MySQL● Top world biggest web sites use MySQL● OpenStack: default DBaaS provider

Page 5: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Can you scale with MySQL?

● Do you plan to reach the scale of Facebook?● From Harrison Fisk talk in 2013:

– many petabytes of data (real time access)– 11M row changes /s – 60M selects /s– 2.5B rows read /s

● WebScaleSQL● Not IF but HOW

Page 6: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scaling for the web

● Stay fast and reliable as you grow● More visitors/users● More features/products● Continuous performance optimization

● How fast you can serve client request?● You may not know how bad your application or

configuration is until...

Page 7: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Best practices

● Design your schema well● Primary key in each table!● Secondary keys designed with application

● Do the fancy stuff asynchronously! ● Advanced reports, statistics?

● Remember the OLTP principles

Page 8: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Best practices

● Cache● Use the right tools!

● Percona XtraBackup● Percona Toolkit

~ 30 tools including pt-online-schema-change, pt-query-digest, pt-table-checksum, and more

● Percona Monitoring Plugins– Nagios, Cacti, Zabbix

Page 9: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Do my queries scale?

● Percona Cloud Tools

cloud.percona.com

Page 10: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scalability areas

Page 11: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Not quite that simple

● Number of connections● Total active● New connections per second

● Write conflicts (deadlocks)● Stale data● Large data management

● Backups● Node provisioning● Number of databases and tables

Page 12: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale up

Page 13: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale up

● More/faster CPU cores● More memory● Bigger disks● Faster disks● Application optimization/redesign● MySQL optimization!

● Default is not good

Page 14: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale up – MySQL version matters!

http://dimitrik.free.fr/

http://mikaelronstrom.blogspot.com/

Page 15: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale up – use the right engine

● Forget MyISAM!

https://blogs.oracle.com/MySQL/entry/comparing_innodb_to_myisam_performance

Page 16: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale up – use right engine

● InnoDB - business standard● Hot backups (MEB, Percona XtraBackup)● Online schema change (pt-osc or in 5.6+)● Compression (Facebook++)

● TokuDB● Excellent compression● Impressive write throughput● Will be shipped with Percona Server 5.6 soon (beta

builds available)

Page 17: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Data growth

● How fast can you make a full backup? No! How fast can you restore from backup!

● How fast can you provision number of nodes capable of handling the traffic (worst case scenario)?

● How fast can you alter table● Query performance (fit hot data in memory)

Page 18: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scale out

Page 19: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scaling out - replication

● Cons

● Complexity – application and DBA

● Data consistency issues

● Slave lag

● Writes are a bottleneck

writ

es

reads

replication

master

slaves

MySQL replication (async)● Pros

● Easy to deploy

● Flexible replication topology

● Unlimited slaves

● No write latency on master

Page 20: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scaling out – MySQL replication

● Replication improvements:● GTID (5.6, MariaDB 10)● Semi-sync replication (5.5+)● Multi-threaded slaves per-database (5.6+) ● Multi-threaded slaves intra-database (5.7)● Multi-Source replication (MySQL 5.7, Maria 5.5)

● Still master -> slave(s)

Page 21: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Make it simple

● Does complexity scale? ;)● Team experience● How fast can you make changes?● Humans make errors● Demand for HA increases as you grow● Simpler management -> higher availability

Page 22: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scaling out made easy – Percona XtraDB Cluster

● Complete HA solution:● Percona Server (5.5 or 5.6)● Galera library from Codership● Percona XtraBackup

● Core features● Synchronous replication● Multi-master replication● Parallel replication● Automatic node provisioning● No need for application change - keep using InnoDB

Page 23: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

PXC – how does it work

GALERAREPLICATION

node1 node2

node3

ReadsWrites

ReadsWrites

ReadsWrites

● No SPOF - availability

● Data consistency

● No partitioning tolerance

● Reasonable overhead

● Transactions pass certification test before

returning to the client but applying is done

asynchronously

● Row based, parallel replication

● No slave lag

Page 24: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

PXC - Data consistency is priority

Node partitioned from the cluster

Page 25: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

PXC - Syncing nodes

● Incremental State Transfer (IST)● Gcache (Writeset Cache)

● State Snapshot Transfer (SST)● Adding a new node● Rebuilding failed node● Node's consistency was compromised

Page 26: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

GALERAREPLICATION

PXC - Automatic node provisioning

Fast and non-blockingwith Percona XtraBackup

node1

node2

JOINER

node4

DONOR

node3

SST

Page 27: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

GALERA

PXC – replication flexibility

Async master

Async slave

GTID

Page 28: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

PXC – WAN awareness

● WAN segments (Galera 3+)

DC1

DC2

DC3 DC3

DC2

DC1

● Smart donor selection● Less network traffic

Page 29: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Scaling out (writes)

● Functional Partitioning

● Sharding

Cluster A

Cluster B

ID 1-1000

ID 1001-2000

Page 30: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Sharding/partitioning – solutions

● Make your application shard aware (design your own logic)

● Use existing solutions● MySQL Fabric● Shard-Query

Page 31: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Cloud

● Scaling on demand, unlimited● “MySQLaaS”

● Amazon RDS● Google Cloud SQL (MySQL only)● Rackspace Cloud Databases (MySQL only)● HP Cloud Relational Database (MySQL only)

Page 32: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

References

Benchmarkshttp://mikaelronstrom.blogspot.com/2013/09/mysql-57-improves-cpu-scaling-further.htmlhttp://dimitrik.free.fr/blog/Large scalehttps://www.youtube.com/watch?v=kbYdvHB-l0sNew cool stuffhttp://www.mysqlperformanceblog.com/2014/03/27/percona-server-5-6-16-64-2-tokudb-engine-beta-now-available/http://www.mysqlperformanceblog.com/2014/01/16/analyzing-wordpress-mysql-queries-query-analytics/http://geek.rohitkalhans.com/2013/09/enhancedMTS-deepdive.htmlCloudhttp://www.percona.com/live/mysql-conference-2013/sessions/using-percona-server-database-service-openstackhttp://www.hpcloud.com/products-services/relational-databasehttp://www.rackspace.com/cloud/databases/https://cloud.google.com/products/cloud-sql/https://aws.amazon.com/rds/mysql/http://www.hastexo.com/resources/presentations/hands-trove-database-service-openstackShardinghttp://www.percona.com/live/mysql-conference-2014/sessions/sharding-and-scale-out-using-mysql-fabrichttps://github.com/greenlion/swanhart-tools/tree/master/shard-queryPXC use caseshttp://capttofu.livejournal.com/29380.htmlhttp://www.acquia.com/resources/case-study/kpn-corporate-markethttp://marketplace.redhat.com/openstack/21615-Percona-XtraDB-Cluster-5-6

Page 33: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

www.percona.com

Learn from MySQL Community

Page 34: Scaling MySQL in 2014? - Proideadata.proidea.org.pl/.../Scaling_MySQL.pdf · Most popular database for web 'M' in LAMP Default database for webhosting offers Most popular CMS/blog/forum

[email protected]@mysqlmaniac.com

We're Hiring! www.percona.com/about-us/careers/