SlideShare a Scribd company logo
1 of 25
Scale MySQL on EC2 with Ansible
Presented by: Miklos ‘Mukka’ Szel
June 16, 2015
About : Miklos ‘Mukka’ Szel
• Currently MySQL Consultant, Pythian (Adobe, Edmodo, Ebay, Fitbit,
Sendgrid)
• 15+ years experience System and Database world
• Acted as Sr. DBA, Sr. Ops, Developer
• Previously worked
– Own startup
– ISP
– Walt Disney & ESPN - cricinfo.com, running ~1500 smaller and bigger
web sites
• How to Contact:
Email: szel@pythian.com
Linkedin: hu.linkedin.com/in/miklosszel/en
AGENDA
• Amazon RDS, EC2/EBS - pros, cons,
backup, scale, bottlenecks
• Ansible/MySQL/MHA
• Demo
• ???
• Profit
MySQL Master-Slave overview
MySQL - how to scale for reads
Create a new read replica in a nutshell:
• set up the new instance
• transfer the data
• set up the replication
• wait until it is in sync with the master
• enable traffic
MySQL in the cloud - RDS
pros:
• easy to manage/backup
• ease to scale
• Multi-AZ as HA (99.95% monthly up time SLA)
Cons:
• limited control over the MySQL(no SUPER priv, no shell
access, no direct access to your logfiles etc)
• data import/export via logical backup only (large
dataset?)
• backup/scale with snapshots (see later)
MySQL in the cloud - EC2
Pros:
• you only pay for what you need (ideally)
• relatively easy to scale (config management)
Cons:
• instances might die
• retirement policy is sometimes unpredictable
• you don’t always know what’s going on in the
background
• encryption have costs
MySQL in the cloud - EC2
Backup:
Logical
• mysqldump
• mydumper
Cold
• stop mysql, archive data files
Hot or Online
• MySQL Enterprise backup(expensive)
• Percona XtraBackup
Snapshots
• LVM(performance overhead)
• EBS snapshots
MySQL in the cloud - EC2 Disk types
Ephemeral
• Fast local disks, ready to use
• Comes with many instance types
• Doesn’t support snapshots
• “The data in an instance store persists only during the
lifetime of its associated instance.”
EBS
• Magnetic
• Generic SSD
• Provisioned SSD
MySQL in the cloud - EC2/EBS
Why EBS snapshots are great for backups/restore:
• easy to implement
• EC2 uses incremental snapshots
• great tool to provision multiple machines
Cons
• EBSs are network drives, check the throughput limit for
your instance
• (n disks * throughput)+other nw activity> bandwidth limit
• volumes are COLD in the beginning, penalty!
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-ec2-config.html
MySQL in the cloud - EBS
Allocating blocks on first access - warming up:
“This preliminary action takes time and can cause a
5 to 50 percent loss of IOPS for your volume the
first time each block is accessed.”
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-prewarm.html
MySQL in the cloud - EBS -
Contd.
Warming up new 100GB EBS disks - m3.2xlarge EBS optimized instance
Type Warmup Time Warmup Speed
SSD ‘io1’ PIOPS 3000 869s 124 MB/s
generic purpose ‘gp2’
SSD 300/3000
864s 124 MB/s
SSD ‘io1’ PIOPS 1500 1604s 66.8 MB/s
Magnetic ‘standard’ no
iops
4884s 22.0 MB/s
MySQL in the cloud - Let’s scale
Warming up 20GB EBS volumes created from snapshots
20GB PIOPS 600 4302.73 s, 5.0 MB/s
500GB => 27 hours
MySQL in the cloud - EBS
It’s a download from S3
“If you access a piece of data that hasn't been
loaded yet, the volume immediately downloads the
requested data from Amazon S3, and then
continues loading the rest of the volume's data in
the background. “
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html
MySQL in the cloud - Let’s scale
let’s use a ‘multithreaded download manager’ for snapshots - RAID0.
20GB 600 PIOPS single threaded
4302.73 s, 5.0 MB/s
5GB 150 PIOPS in parallel RAID0
5368709120 bytes (5.4 GB) copied, 1001.02 s, 5.4 MB/s
5368709120 bytes (5.4 GB) copied, 985.397 s, 5.4 MB/s
5368709120 bytes (5.4 GB) copied, 941.726 s, 5.7 MB/s
5368709120 bytes (5.4 GB) copied, 935.607 s, 5.7 MB/s
MySQL in the cloud - Let’s scale
Chain copy data with XtraBackup streams
last box:
nc -l 1234 | pigz -d | tar xvf -
boxes in the middle:
mkfifo copy_redirect
nc next_host_in_chain 1337 <copy_redirect &
nc -l 1337 | tee copy_redirect | pigz -d | tar -xvf -
‘donor’ box:
innobackupex --stream=tar /tmp/ --slave-info | pv --size $( du -sh
/data/mysql/ | cut -f1 ) | pigz | nc first_host_in_chain 1337
http://blog.jericon.net/2012/05/17/chain-copying-to-multiple-hosts/
http://engineering.tumblr.com/post/7658008285/efficiently-copying-files-to-
multiple-destinations
MySQL on EC2
•MHA
•MYSQL
•Ansible
About MHA
• Open Source HA utility written in Perl
• Automated/Interactive Master failover
• Easy to configure
For more: https://code.google.com/p/mysql-master-ha/
About MHA
Scale with CM - Ansible
• Simple
• Agentless
• Easy to manage
• Idempotent
• 100% Python
• Uses ssh to perform changes
Ansible - Modules
MySQL Modules
• mysql_db Add remove databases to remote hosts
• mysql_replication Manage MySQL replication
• mysql_user MySQL user management
• mysql_variables Manage global variables
Others Modules
• Package managers (yum, apt)
• Service
• File
• Template
For more: http://docs.ansible.com/list_of_database_modules.html#mysql
Ansible - Templates
•Use of templates
# MHA cluster configuration
# generated by Ansible, do not modify by hand.
# config for cluster: {{cluster_id}}
[server default]
user={{my_mha_user}}
password={{my_mha_pass}}
repl_user={{my_repl_user}}
repl_password={{my_repl_pass}}
ssh_user=root
manager_workdir=/var/log/masterha/{{cluster_id}}
remote_workdir=/var/log/masterha/{{cluster_id}}
...
#my.cnf
innodb_buffer_pool_size = {{ (ansible_memtotal_mb * 70 / 100) |round|int }}M
…
Demo – https://github.com/mszel-pythian/ansible_mha
• Show configuration files and sample setup
• Demonstrate launching EC2 mysql instances configuring MHA and failing
over with Ansible
• SYSTEM SETUP(common role)
– Fine tune system variables (sysctl - fe.: , swappiness=0)
– Install system packages and mha
– Create configuration files based on templates
– Create users based on public keys under files/users
• MYSQL PART(mysql role)
– Install mysql binaries
– Create my.cnf based on template (exception handling)
– Install mysql users (replica,system users, monitor app users), remove passwordless
users
– Build slave automatically with xtrabackup streaming
…
Demo
[system]
54.90.37.115 mysql_role=master nickname=dev-meetup-m1
54.237.26.245 mysql_role=slave nickname=dev-meetup-m2
54.157.139.143 mycnf=custom mysql_role=slave nickname=dev-meetup-s3
54.237.9.103 mysql_role=mha_manager ephemeral=true
[databases]
54.90.37.115 mysql_role=master server_id=42421
54.237.26.245 mysql_role=slave server_id=42422 backup_src=54.90.37.115
54.157.139.143 mysql_role=slave server_id=42423 backup_src=54.90.37.115
Demo
TASK: [mysql | copy src=root/mysql_parse_config.sh dest=/root/ owner=root
group=root mode=700] ***
skipping: [54.90.37.115]
skipping: [54.237.26.245]
changed: [54.157.139.143]
[…]
roles/mysql/tasks/main.yml:
- include: mysql_slave_xtrabackup.yml
when: "bootstrap_enabled and mysql_role != 'master'"
tags: slave
TASK: [mysql | Streaming the backup from {{ backup_src }} to {{
inventory_hostname }}] ***
skipping: [54.90.37.115]
changed: [54.237.26.245]
changed: [54.157.139.143]

More Related Content

Featured

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 

Featured (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Scale MySQL on EC2 with Ansible

  • 1. Scale MySQL on EC2 with Ansible Presented by: Miklos ‘Mukka’ Szel June 16, 2015
  • 2. About : Miklos ‘Mukka’ Szel • Currently MySQL Consultant, Pythian (Adobe, Edmodo, Ebay, Fitbit, Sendgrid) • 15+ years experience System and Database world • Acted as Sr. DBA, Sr. Ops, Developer • Previously worked – Own startup – ISP – Walt Disney & ESPN - cricinfo.com, running ~1500 smaller and bigger web sites • How to Contact: Email: szel@pythian.com Linkedin: hu.linkedin.com/in/miklosszel/en
  • 3. AGENDA • Amazon RDS, EC2/EBS - pros, cons, backup, scale, bottlenecks • Ansible/MySQL/MHA • Demo • ??? • Profit
  • 5. MySQL - how to scale for reads Create a new read replica in a nutshell: • set up the new instance • transfer the data • set up the replication • wait until it is in sync with the master • enable traffic
  • 6. MySQL in the cloud - RDS pros: • easy to manage/backup • ease to scale • Multi-AZ as HA (99.95% monthly up time SLA) Cons: • limited control over the MySQL(no SUPER priv, no shell access, no direct access to your logfiles etc) • data import/export via logical backup only (large dataset?) • backup/scale with snapshots (see later)
  • 7. MySQL in the cloud - EC2 Pros: • you only pay for what you need (ideally) • relatively easy to scale (config management) Cons: • instances might die • retirement policy is sometimes unpredictable • you don’t always know what’s going on in the background • encryption have costs
  • 8. MySQL in the cloud - EC2 Backup: Logical • mysqldump • mydumper Cold • stop mysql, archive data files Hot or Online • MySQL Enterprise backup(expensive) • Percona XtraBackup Snapshots • LVM(performance overhead) • EBS snapshots
  • 9. MySQL in the cloud - EC2 Disk types Ephemeral • Fast local disks, ready to use • Comes with many instance types • Doesn’t support snapshots • “The data in an instance store persists only during the lifetime of its associated instance.” EBS • Magnetic • Generic SSD • Provisioned SSD
  • 10. MySQL in the cloud - EC2/EBS Why EBS snapshots are great for backups/restore: • easy to implement • EC2 uses incremental snapshots • great tool to provision multiple machines Cons • EBSs are network drives, check the throughput limit for your instance • (n disks * throughput)+other nw activity> bandwidth limit • volumes are COLD in the beginning, penalty! http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-ec2-config.html
  • 11. MySQL in the cloud - EBS Allocating blocks on first access - warming up: “This preliminary action takes time and can cause a 5 to 50 percent loss of IOPS for your volume the first time each block is accessed.” http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-prewarm.html
  • 12. MySQL in the cloud - EBS - Contd. Warming up new 100GB EBS disks - m3.2xlarge EBS optimized instance Type Warmup Time Warmup Speed SSD ‘io1’ PIOPS 3000 869s 124 MB/s generic purpose ‘gp2’ SSD 300/3000 864s 124 MB/s SSD ‘io1’ PIOPS 1500 1604s 66.8 MB/s Magnetic ‘standard’ no iops 4884s 22.0 MB/s
  • 13. MySQL in the cloud - Let’s scale Warming up 20GB EBS volumes created from snapshots 20GB PIOPS 600 4302.73 s, 5.0 MB/s 500GB => 27 hours
  • 14. MySQL in the cloud - EBS It’s a download from S3 “If you access a piece of data that hasn't been loaded yet, the volume immediately downloads the requested data from Amazon S3, and then continues loading the rest of the volume's data in the background. “ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSSnapshots.html
  • 15. MySQL in the cloud - Let’s scale let’s use a ‘multithreaded download manager’ for snapshots - RAID0. 20GB 600 PIOPS single threaded 4302.73 s, 5.0 MB/s 5GB 150 PIOPS in parallel RAID0 5368709120 bytes (5.4 GB) copied, 1001.02 s, 5.4 MB/s 5368709120 bytes (5.4 GB) copied, 985.397 s, 5.4 MB/s 5368709120 bytes (5.4 GB) copied, 941.726 s, 5.7 MB/s 5368709120 bytes (5.4 GB) copied, 935.607 s, 5.7 MB/s
  • 16. MySQL in the cloud - Let’s scale Chain copy data with XtraBackup streams last box: nc -l 1234 | pigz -d | tar xvf - boxes in the middle: mkfifo copy_redirect nc next_host_in_chain 1337 <copy_redirect & nc -l 1337 | tee copy_redirect | pigz -d | tar -xvf - ‘donor’ box: innobackupex --stream=tar /tmp/ --slave-info | pv --size $( du -sh /data/mysql/ | cut -f1 ) | pigz | nc first_host_in_chain 1337 http://blog.jericon.net/2012/05/17/chain-copying-to-multiple-hosts/ http://engineering.tumblr.com/post/7658008285/efficiently-copying-files-to- multiple-destinations
  • 18. About MHA • Open Source HA utility written in Perl • Automated/Interactive Master failover • Easy to configure For more: https://code.google.com/p/mysql-master-ha/
  • 20. Scale with CM - Ansible • Simple • Agentless • Easy to manage • Idempotent • 100% Python • Uses ssh to perform changes
  • 21. Ansible - Modules MySQL Modules • mysql_db Add remove databases to remote hosts • mysql_replication Manage MySQL replication • mysql_user MySQL user management • mysql_variables Manage global variables Others Modules • Package managers (yum, apt) • Service • File • Template For more: http://docs.ansible.com/list_of_database_modules.html#mysql
  • 22. Ansible - Templates •Use of templates # MHA cluster configuration # generated by Ansible, do not modify by hand. # config for cluster: {{cluster_id}} [server default] user={{my_mha_user}} password={{my_mha_pass}} repl_user={{my_repl_user}} repl_password={{my_repl_pass}} ssh_user=root manager_workdir=/var/log/masterha/{{cluster_id}} remote_workdir=/var/log/masterha/{{cluster_id}} ... #my.cnf innodb_buffer_pool_size = {{ (ansible_memtotal_mb * 70 / 100) |round|int }}M …
  • 23. Demo – https://github.com/mszel-pythian/ansible_mha • Show configuration files and sample setup • Demonstrate launching EC2 mysql instances configuring MHA and failing over with Ansible • SYSTEM SETUP(common role) – Fine tune system variables (sysctl - fe.: , swappiness=0) – Install system packages and mha – Create configuration files based on templates – Create users based on public keys under files/users • MYSQL PART(mysql role) – Install mysql binaries – Create my.cnf based on template (exception handling) – Install mysql users (replica,system users, monitor app users), remove passwordless users – Build slave automatically with xtrabackup streaming …
  • 24. Demo [system] 54.90.37.115 mysql_role=master nickname=dev-meetup-m1 54.237.26.245 mysql_role=slave nickname=dev-meetup-m2 54.157.139.143 mycnf=custom mysql_role=slave nickname=dev-meetup-s3 54.237.9.103 mysql_role=mha_manager ephemeral=true [databases] 54.90.37.115 mysql_role=master server_id=42421 54.237.26.245 mysql_role=slave server_id=42422 backup_src=54.90.37.115 54.157.139.143 mysql_role=slave server_id=42423 backup_src=54.90.37.115
  • 25. Demo TASK: [mysql | copy src=root/mysql_parse_config.sh dest=/root/ owner=root group=root mode=700] *** skipping: [54.90.37.115] skipping: [54.237.26.245] changed: [54.157.139.143] […] roles/mysql/tasks/main.yml: - include: mysql_slave_xtrabackup.yml when: "bootstrap_enabled and mysql_role != 'master'" tags: slave TASK: [mysql | Streaming the backup from {{ backup_src }} to {{ inventory_hostname }}] *** skipping: [54.90.37.115] changed: [54.237.26.245] changed: [54.157.139.143]