Practical MySQL Performance Optimization€¦ · 3 In This Presentation We’l Look at how to...

Preview:

Citation preview

Peter Zaitsev, CEO, Percona

October 01, 2014 MySQL Central @ OOW

San Francisco, CA

Practical MySQL Performance Optimization

www.percona.com 2

Unsafe Harbor Statement

To join my Oracle friends in their spirit I’m also adding the meaningless slide with a lot of text which no one really reads or cares about in the start of the presentation I am about to deliver. It is so good to be part of the private company when you do not have to worry about earning restatement or being sued by shareholders. Have you got to the end of this text? Wow you’re a fast reader.

www.percona.com 3

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 4

First Things First

MySQL Performance does not Matter!

www.percona.com 5

What DOES Matter?

Application Performance!

www.percona.com 6

Even More so

Application Performance Always Matters!

www.percona.com 7

Take Away

Performance Problems might not be MySQL

Performance Solutions might not

be with MySQL

www.percona.com 8

Many “Tools”

• MongoDB • Cassandra • Hadoop • Elastic Search • Redis

Use the best

Tool for the job

www.percona.com 9

Say Performance

Mean Response Time

www.percona.com 10

Related Issues

Stability

Scalability

Efficiency

www.percona.com 11

Scalability?

• Load • Data Size • Infrastructure

Scalability with:

www.percona.com 12

Performance “Sandbags”

Security

Manageability

Compatibility

Compliance

Ease of use by Developers

www.percona.com 13

“Good Enough”

You can always

improve your system. Know when to stop.

www.percona.com 14

What MySQL Does

• Selects • Inserts • Deletes • Updates

Processes Queries

www.percona.com 15

What to focus on?

• Making queries run faster

• Using less resources

• Scaling better

Performance Optimization

focused

www.percona.com 16

Transaction Optimization

• Find out which queries it runs

• Optimize them

Specific Application Transaction

www.percona.com 17

General Optimization

• Prioritize them • Optimize them

Look at what

queries Server Runs

www.percona.com 18

Queries

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

Are those the

right queries ?

www.percona.com 19

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 20

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 21

Schema

• Minor Schema changes

• Data Architecture

Look at Schema

and Queries together

www.percona.com 22

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 23

The Following Also Matter

Infrastructure

Operating System and Configuration

MySQL Version

MySQL Configuration

www.percona.com 24

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 25

Infrastructure

Scaling Up or Out

• One MySQL Node

• Many MySQL Nodes

Type

• Public Cloud • Private Cloud • Bare Metal

www.percona.com 26

Hardware

CPU

Memory

Disk

Network

www.percona.com 27

CPU

Intel owns the market

2 sockets commonly used

Faster cores or more cores

Turboboost

www.percona.com 28

Memory

Main purpose – Cache

Think Database size vs Memory

Look together with Storage Optimization

www.percona.com 29

Invest in Memory or Storage

www.percona.com 30

Storage

Types

•  Directly Attached

•  SAN •  NAS •  Virtualized

Flash

•  PCI-E •  SATA

“Disks” •  TLC, MLC,

eMLC, SLC

RAID

•  Hardware •  Software •  Filesystem

www.percona.com 31

Network

Latency

•  Distance •  Number of

“Hops”

Throughput

•  1Gb is a must, trunking recommended

•  10Gb increasingly affordable

Availability

•  Bonding •  Multipath

www.percona.com 32

OS Choices

Linux

Server grade

Recent

Supporting MySQL well

www.percona.com 33

OS Tuning

Defaults are good for common workloads

Filesystem: EXT4 or XFS

More Detail http://bit.ly/MySQLonLinux

www.percona.com 34

MySQL Version

New versions typically improve performance

Scalability, Improved Optimizer, etc.

Expect some regressions

Try Percona Server 5.6

www.percona.com 35

MySQL Configuration

Do not run with defaults

Do not ever obsess with tuning

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

www.percona.com 36

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 37 www.percona.com

Tools and The Process

www.percona.com 38

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 39

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 40

Tools

PT-Query-Digest from Percona Toolkit

MySQL Enterprise Monitor

MonYog

VividCortex

Percona Cloud Tools

www.percona.com 41

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 42

Data

Queries

Metrics

Configuration

www.percona.com 43

Design

Capture metrics with 1sec resolution

Go beyond averages

Decouple graphs from metrics

Real-time interaction

www.percona.com 44

Query Profile

www.percona.com 45

Specifics

•  Pick Time Range •  Pick Queries you’re interested in

www.percona.com 46

Server Profile

www.percona.com 47

Drill Down

www.percona.com 48

Response Time Stability

www.percona.com 49

Query Information

www.percona.com 50

See Change

www.percona.com 51

Tag, Review, Comment

www.percona.com 52

Query Execution Details

www.percona.com 53

See live EXPLAIN

www.percona.com 54

System Information

www.percona.com 55

Watch Metrics

www.percona.com 56

Zoom

www.percona.com 57

Look at Distribution

www.percona.com 58

To Sum it Up

It is Application Performance what Matters!

Use Right Tools for Right Job

See what Queries MySQL is Running

Reduce Number of Queries

Reduce Data They Return

See how they can do less work

Do that work more efficiently

www.percona.com 59

Percona

Support

Managed Services

Consulting

Software

www.percona.com 60 www.percona.com

Peter Zaitsev pz@percona.com

Thank You!

Recommended