Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL...

58
Peter Zaitsev, CEO, Percona April 14, 2015 Percona Live MySQL Conference and Expo Santa Clara,CA Practical MySQL Performance Optimization

Transcript of Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL...

Page 1: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

Peter Zaitsev, CEO, Percona April 14, 2015

Percona Live MySQL Conference and Expo Santa Clara,CA

Practical MySQL Performance Optimization

Page 2: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 3: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 3

First Things First

MySQL Performance does not matter!

Page 4: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 4

What DOES Matter?

Application Performance!

Page 5: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 5

Even Moreso

Application Performance Always Matters!

Page 6: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 6

Take Away

Performance Problems might not be MySQL

Performance Solutions might not

be with MySQL

Page 7: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 7

Many “Tools”

• MongoDB • Cassandra • Hadoop • Elastic Search • Redis

Use the best

tool for the job

Page 8: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 8

Say Performance

Think about response time

Page 9: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 9

Related Issues

Stability

Scalability

Efficiency

Page 10: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 10

Scalability?

• Load • Data Size • Infrastructure

Scalability with:

Page 11: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 11

Performance “Sandbags”

Security

Manageability

Compatibility

Compliance

Ease of use by Developers

Page 12: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 12

“Good Enough”

You can always

improve your system. Know when to stop.

Page 13: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 13

What MySQL Does

• Selects • Inserts • Deletes • Updates

Processes Queries

Page 14: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 14

What to focus on?

• Making queries run faster

• Using less resources

• Scaling better

Performance Optimization

focused

Page 15: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 15

Transaction Optimization

• Find out which queries it runs

• Optimize them

Specific Application Transaction

Page 16: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 16

General Optimization

• Prioritize them • Optimize them

Look at what

queries server runs

Page 17: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 17

Queries

• Get rid of them? • Can we change them to be doing less work?

Are those the

right queries ?

Page 18: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 19: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 20: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 20

Schema

• Minor Schema changes

• Data Architecture

Look at Schema

and Queries together

Page 21: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 22: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 22

The Following Also Matter

Infrastructure

Operating System and Configuration

MySQL Version

MySQL Configuration

Page 23: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 24: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 24

Infrastructure

Scaling Up or Out

• One MySQL Node

• Many MySQL Nodes

Type

• Public Cloud • Private Cloud • Bare Metal

Page 25: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 25

Hardware

CPU

Memory

Disk

Network

Page 26: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 26

CPU

Intel owns the market

2 sockets commonly used

Faster cores or more cores

Turboboost

Page 27: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 27

Memory

Main purpose – Cache

Think Database size vs Memory

Look together with Storage Optimization

Page 28: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 28

Invest in Memory or Storage

Page 29: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 29

Storage

Types

•  Directly Attached

•  SAN •  NAS •  Virtualized

Flash

•  PCI-E •  SATA

“Disks” •  TLC, MLC,

eMLC, SLC

RAID

•  Hardware •  Software •  Filesystem

Page 30: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 30

Network

Latency

•  Distance •  Number of

“Hops”

Throughput

•  1Gb is a must, trunking recommended

•  10Gb increasingly affordable

Availability

•  Bonding •  Multipath

Page 31: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 31

OS Choices

Linux

Server grade

Recent

Supporting MySQL well

Page 32: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 32

OS Tuning

Defaults are good for common workloads

Filesystem: EXT4 or XFS

More Detail http://bit.ly/MySQLonLinux

Page 33: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 33

MySQL Version

New versions typically improve performance

Scalability, Improved Optimizer, etc.

Expect some regressions

Try Percona Server 5.6

Page 34: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 34

MySQL Configuration

Do not run with defaults

Do not ever obsess with tuning

More Details: http://bit.ly/1vth5Cu

Page 35: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 36: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 36 www.percona.com

Tools and Processes

Page 37: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 38: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 39: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 39

Tools

PT-Query-Digest from Percona Toolkit

MySQL Enterprise Monitor

MonYog

VividCortex

Percona Cloud Tools

Page 40: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 41: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 41

Data

Queries

Metrics

Configuration

Page 42: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 42

Design

Capture metrics with 1sec resolution

Go beyond averages

Decouple graphs from metrics

Real-time interaction

Page 43: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 43

Query Profile

Page 44: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 44

Specifics

•  Pick a time range •  Pick queries you’re interested in

Page 45: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 45

Server Profile

Page 46: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 46

Drill Down

Page 47: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 47

Response Time Stability

Page 48: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 48

Query Information

Page 49: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 49

See Change

Page 50: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 50

Tag, Review, Comment

Page 51: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 51

Query Execution Details

Page 52: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 52

See live EXPLAIN

Page 53: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 53

System Information

Page 54: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 54

Watch Metrics

Page 55: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 55

Zoom

Page 56: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 56

Look at Distribution

Page 57: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

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

Page 58: Practical MySQL Performance Optimization - Percona · PDF fileSanta Clara,CA Practical MySQL Performance Optimization . ... case only • Consider daily, ... How much data is traversed

www.percona.com 58 www.percona.com

Peter Zaitsev [email protected]

@PeterZaitsev https://www.linkedin.com/in/peterzaitsev

Thank You!