Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL...
Transcript of Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL...
Peter Zaitsev, CEO, Percona April 14, 2015
Percona Live MySQL Conference and Expo Santa Clara,CA
Practical MySQL Performance Optimization
www.percona.com 2
In This Presentation We’ll
Look at how to approach Performance Optimization
Discuss Practical Performance Optimization Tips
Look at the tools which can help us
www.percona.com 3
First Things First
MySQL Performance does not matter!
www.percona.com 4
What DOES Matter?
Application Performance!
www.percona.com 5
Even Moreso
Application Performance Always Matters!
www.percona.com 6
Take Away
Performance Problems might not be MySQL
Performance Solutions might not
be with MySQL
www.percona.com 7
Many “Tools”
• MongoDB • Cassandra • Hadoop • Elastic Search • Redis
Use the best
tool for the job
www.percona.com 8
Say Performance
Think about response time
www.percona.com 9
Related Issues
Stability
Scalability
Efficiency
www.percona.com 10
Scalability?
• Load • Data Size • Infrastructure
Scalability with:
www.percona.com 11
Performance “Sandbags”
Security
Manageability
Compatibility
Compliance
Ease of use by Developers
www.percona.com 12
“Good Enough”
You can always
improve your system. Know when to stop.
www.percona.com 13
What MySQL Does
• Selects • Inserts • Deletes • Updates
Processes Queries
www.percona.com 14
What to focus on?
• Making queries run faster
• Using less resources
• Scaling better
Performance Optimization
focused
www.percona.com 15
Transaction Optimization
• Find out which queries it runs
• Optimize them
Specific Application Transaction
www.percona.com 16
General Optimization
• Prioritize them • Optimize them
Look at what
queries server runs
www.percona.com 17
Queries
• Get rid of them? • Can we change them to be doing less work?
Are those the
right queries ?
www.percona.com 18
Things to Consider
• But avoid focusing only on outliers
Do not look at the average case only
• Consider daily, weekly, monthly cycles
Look at trends over time
• Data size change? Cardinality?
Think about future
performance
www.percona.com 19
Query Tips
Do less queries – latency and overhead
Read or modify less data
Less data processing on the fly
How much data is traversed vs sent
How much data is sent vs used by app
www.percona.com 20
Schema
• Minor Schema changes
• Data Architecture
Look at Schema
and Queries together
www.percona.com 21
Schema Tips
• http://bit.ly/1rAtamE Learn Indexing
• Starting with Text book schema is OK ending is likely not
Design Schema for data access
• Partitioning & Sharding • Normalization and Denormalization • Covering Indexes
Technics
www.percona.com 22
The Following Also Matter
Infrastructure
Operating System and Configuration
MySQL Version
MySQL Configuration
www.percona.com 23
Optimization Process
Low Hanging Fruit
• MySQL Configuration
• OS Settings • Indexes • Caching
Medium Level
• Infrastructure • OS • MySQL
Version
Hard Changes
• Major schema changes
• Application architecture change
www.percona.com 24
Infrastructure
Scaling Up or Out
• One MySQL Node
• Many MySQL Nodes
Type
• Public Cloud • Private Cloud • Bare Metal
www.percona.com 25
Hardware
CPU
Memory
Disk
Network
www.percona.com 26
CPU
Intel owns the market
2 sockets commonly used
Faster cores or more cores
Turboboost
www.percona.com 27
Memory
Main purpose – Cache
Think Database size vs Memory
Look together with Storage Optimization
www.percona.com 28
Invest in Memory or Storage
www.percona.com 29
Storage
Types
• Directly Attached
• SAN • NAS • Virtualized
Flash
• PCI-E • SATA
“Disks” • TLC, MLC,
eMLC, SLC
RAID
• Hardware • Software • Filesystem
www.percona.com 30
Network
Latency
• Distance • Number of
“Hops”
Throughput
• 1Gb is a must, trunking recommended
• 10Gb increasingly affordable
Availability
• Bonding • Multipath
www.percona.com 31
OS Choices
Linux
Server grade
Recent
Supporting MySQL well
www.percona.com 32
OS Tuning
Defaults are good for common workloads
Filesystem: EXT4 or XFS
More Detail http://bit.ly/MySQLonLinux
www.percona.com 33
MySQL Version
New versions typically improve performance
Scalability, Improved Optimizer, etc.
Expect some regressions
Try Percona Server 5.6
www.percona.com 34
MySQL Configuration
Do not run with defaults
Do not ever obsess with tuning
More Details: http://bit.ly/1vth5Cu
www.percona.com 35
MySQL Tuning in 1 Slide
• max_connections • log_bin • table_open_cache_size • table_definitions_cache_size • open_files_limit • innodb_buffer_pool_size • innodb_log_file_size • Innodb_flush_log_at_trx_commit • Innodb_flush_method=O_DIRECT
www.percona.com 36 www.percona.com
Tools and Processes
www.percona.com 37
Process
• Do not bring bad queries and schema in production
Developers Part
• Catch bad queries • Validate changes in hardware,
configuration, versions
Operations Process
www.percona.com 38
Queries will be impacted
Hardware Changes
Configuration
MySQL Version Changes
Impact of Data Growth
Changes to the Query Mix
Optimizer Plan Changes
www.percona.com 39
Tools
PT-Query-Digest from Percona Toolkit
MySQL Enterprise Monitor
MonYog
VividCortex
Percona Cloud Tools
www.percona.com 40
Percona Cloud Tools
Hosted Performance Management and Monitoring Solution from Percona
Everything I show is available in a FREE version
Register at http://cloud.percona.com
www.percona.com 41
Data
Queries
Metrics
Configuration
www.percona.com 42
Design
Capture metrics with 1sec resolution
Go beyond averages
Decouple graphs from metrics
Real-time interaction
www.percona.com 43
Query Profile
www.percona.com 44
Specifics
• Pick a time range • Pick queries you’re interested in
www.percona.com 45
Server Profile
www.percona.com 46
Drill Down
www.percona.com 47
Response Time Stability
www.percona.com 48
Query Information
www.percona.com 49
See Change
www.percona.com 50
Tag, Review, Comment
www.percona.com 51
Query Execution Details
www.percona.com 52
See live EXPLAIN
www.percona.com 53
System Information
www.percona.com 54
Watch Metrics
www.percona.com 55
Zoom
www.percona.com 56
Look at Distribution
www.percona.com 57
In Summary
It is the application performance that matters!
Use the right tools for the right job
See what queries MySQL is running
Reduce the umber of queries
Reduce the data They Return
See how they can do less work
Do that work more efficiently
www.percona.com 58 www.percona.com
Peter Zaitsev [email protected]
@PeterZaitsev https://www.linkedin.com/in/peterzaitsev
Thank You!