Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% •...
Transcript of Running&MySQL&on&CentOSLinux · Reasons&for&CentOS&& Server%Grade%Distribu7on% •...
Running MySQL on CentOS Linux
Peter Zaitsev April 14, 2014
About the Presenta9on
• Distribu7on • Hardware • OS Configura7on • MySQL Installa7on • MySQL Configura7on
Cover what you need to run
MySQL on CentOS Linux
successfully
2
Why Linux?
• Almost 80% for Development • hNp://bit.ly/QSdooC
Almost 90% of MySQL users use Linux for
produc7on
• hNp://bit.ly/1rLIUnv CentOS the Most Popular Linux
Distribu7on for MySQL
• Unless you have a very good reason not to, choose Linux for MySQL Great default choice
3
Reasons for CentOS
Server Grade Distribu7on • Long support, stability
Completely Open Source • Free
Modern • but not bleeding Edge
Great Community support • You can get help when you need to
4
Hardware
• Really! Hardware can go a long way!
• With 100 queries/page = 120K page views/minute
• Some 80M page views/day (considering daily spike)
Over 200K simple queries/sec on modern
hardware
5
Hardware
• Go for fast cores. All cores are rarely used these days
• Cache and fast memory bus is important
CPU
• Ocen most important for performance • Your working set must fit in memory well
• Less memory = more pressure on IO Memory
6
Storage
Directly aNached Flash is best -‐ PCI-‐E cards (FusionIO, Virident) are fastest
SATA SSD are very cost effec7ve
Mind vendors and monitor for uniform performance
Where performance might be limi7ng (hNp://bit.ly/1f2u919)
Ensure you have a RAID w BBU on conven7onal drives
RAID10 is best for heavy loads
7
Know your Goals
• Reads? • Writes? • Random? • Sequen7al?
Are you bound by
• Sustained writes? • Handle spikes? Do you need
• Many devices reach peak IOPs at unreachable concurrency What concurrency do you operate?
• SAN/NAS is a frequent cause of surprise Think about latency/
response 7me
8
Performance vs. Memory 9
Compression of Performance Gains 10
Alignment
Par77on alignment
File system alignment op7ons
Can cause significant performance difference • hNp://bit.ly.ilfNkT • hNp://bit.ly.ks9trM
11
Alignment Benchmarks 12
More on SSD/Flash
Think about Write Endurance
Behavior on Power Loss
Data Reten7on
Firmware
Linux RAID Compa7bility
13
Network
Latency is king
Minimize number of hops between Database and Web Server
Ensure running 1Gbit link speed at least (10Gb is gaining popularity)
Monitor for packet loss and latency
Network problems are ocen blamed on database
14
Network Tuning
Might be needed some7mes • echo 8192 > /proc/sys/net/ipv4/tcp_max_syn_backlog • Mysql: back_log=1000 • net.ipv4.ip_local_port_range="1024 64000“ • net.core.somaxconn = 1024 • net.core.rmem_max = 16777216 • net.core.wmem_max = 16777216 • net.ipv4.tcp_rmem = 4096 87380 16777216 • net.ipv4.tcp_wmem = 4096 65536 16777216 • net.ipv4.max_tw_buckets=360000 • net.core.netdev_max_backlog = 2500 • ifconfig eth0 txqueuelen 1000
Persistent connec7ons with MySQL • Thread_pool (Percona Server, MariaDB, MySQL Enterprise) • Proxy
15
Virtualiza9on and Cloud
Virtualiza7on has cost
Cloud rarely provides highest performance hardware (Gerng beNer)
There is a lot of MySQL use in the Cloud and Virtualized Environments
16
Linux Configura9on
17
In General…
For most workloads Linux Runs MySQL surprisingly well with no addi7onal tuning
18
General Configura9on
• Unless you really need it on your system • In /etc/selinux/config • SELINUX=disabled
• Same with AppArmor
Disable SELinux
• vm.swappiness=0 • vm.dirty_ra7o=5
Reduce Tendency to swap
19
General Configura9on
Reduce the File Cache • vm.dirty_ra7o=5
NUMA can cause problems • hNp://bit.ly/I0GSt3 • Interleaving with numactl • Out there in Percona Server startup scripts
20
Storage Configura9on
• Re-‐Configure MySQL without OS Reinstall Separate OS and MySQL Par77on
• CFQ can cause problems • Deadline or Noop are ocen beNer choice • elevator=deadline on kernel boot
Configure IO Scheduler
• # echo 100000 > /sys/block/sdX/queue/nr_requests Queue length (especially MyISAM)
• Virtually no overhead when not in snapshot mode • Reserve some space for snapshots Consider using LVM
21
Which one do you use ? FILESYSTEMS
22
Filesystems
XFS – “Old” High Performance Favorite
EXT4 – Works very good for some workloads
Avoid: • Ext2 • Ext3 • ReiserFS • ZFS (may be good for development) • Btrfs
23
FS Tuning
rela7me (noa7me)
ext3: tune2fs –O dir_index -‐c –l –i 0 –e remount-‐ro
xfs: nobarrier • Assuming RAID w BBU or Flash
24
Why are you running? MYSQL VARIANTS
25
Main Choices
MySQL
Percona Server
MariaDB
26
MySQL Versions
Newer versions scale beNer
MySQL 5.6 is most scalable
Percona Server 5.6 brings even more improvements J
Use 5.6 for New Development
Upgrade to MySQL 5.6 if you need it now
27
Check out Percona XtraDB Cluster
Based on Galera Technology
Innodb Storage Engine you already know
Synchronous Replica7on
Parallel Apply
Automa7c Provisioning
No Stale Reads
Not for all workloads
28
How to Install
• hNp://dev.mysql.com/downloads/repo/ • hNp://www.percona.com/doc/percona-‐server/5.6/installa7on.html
Use Repositories: Best
• Need older Version Download RPM
• Good for tes7ng with MySQL Sandbox Use Tar.gz package
• Do you really have good reason to do it ? • Many problems are caused by bad builds Build our own
29
MySQL Configura9on
• Even newer MySQL 5.6 defaults are unlikely to be op7mal
You need to tune MySQL configura7on
• hNp://bit.ly/1fuP0SZ Check out presenta7on which goes in depth into configura7on tuning
• Avoid obsessive tuning disorder Typically gerng 5 variables right
responsible for 90% performance gain
30
Top Variables
• Set 80% of memory some7mes more Innodb_buffer_pool_size
• Best serng in most cases Innodb_flush_method=O_DIRECT
• Set 256MB or more • Larger logs = longer recovery 7me
Innodb_log_file_size
• Truly ACID: 1 • Can Afford Data Loss: 2
Innodb_flush_log_at_trx_commit=?
31
Advanced Ideas
• taskset -‐pc 0,12,2,14 `cat /var/lib/mysql/mysqld1.pid`
Running mul7ple MySQL instances ?
• Jemalloc • Tcmalloc –old favorite
Memory Alloca7on Hostspot ?
• Roll back easily if things go wrong
LVM Snapshot before maintenance
or upgrade
32
Beware of the “Scripts”
• Timeouts might be not enough for safe database shutdown
• The automated upgrade/check
Start/Stop Scripts can be nasty
33
Automa9on
Manual approach is a no
• Does not Scale • And is Error Prone
Automate installa7on, upgrades,
configura7on
• Puppet, • Chef • Ansible
Keep Configura7on under version control
• At very least leave comments on what you chance and why
34
Monitoring and Trending
• Just make sure you’re doing it Many tools to choose from!
• Check out PMP • hNp://www.percona.com/socware/percona-‐monitoring-‐plugins
Nagios and CACTI
• hNp://graphite.wikidot.com/ Graphite is a great tool for advanced analyses
• Percona Cloud Tools (FREE Beta) • hNps://cloud.percona.com/
Looking for Cloud Based Solu7ons
35
Linux OOM Killer
• SSH • MySQL Server • Various jobs • Backup • Percona Toolkit • Background Batch jobs
What are your
priori7es ?
• echo -‐17 > /proc/2592/oom_adj • do not kill ever
• echo 10 > /proc/2592/oom_adj • More like to be killed
Configuring
36
Tools you need to know
General Linux
• Top • Vmstat • Iostat • Strace • gdb
MySQL
• Percona Toolkit • Innotop • Percona Xtrabackup
• MyDumper
37
Learn more
• hNp://www.percona.com/training Percona Training
• hNp://www.percona.com/webinars Percona Webinars
• hNp://www.mysqlperformanceblog.com
MySQL Performance Blog
38
Aaend The Conference
4 More Days of great Learning and Networking
Expo Hall, Keynote Free for CentOS Dojo ANendees
Single Day Passes Available
Use “GoLinux” Discount Code for 15% off
39