A Proactive approach to Monitoring Slow Queries Shashank Sahni - - PowerPoint PPT Presentation

a proactive approach to monitoring slow queries
SMART_READER_LITE
LIVE PREVIEW

A Proactive approach to Monitoring Slow Queries Shashank Sahni - - PowerPoint PPT Presentation

A Proactive approach to Monitoring Slow Queries Shashank Sahni ThousandEyes Shashank Sahni Principal SRE @ThousandEyes Reach out to shashank@thousandeyes.com Twitter @shredder12 @shredder12 @ThousandEyes 2 MySQL @ThousandEyes Percona


slide-1
SLIDE 1

A Proactive approach to Monitoring Slow Queries

Shashank Sahni ThousandEyes
slide-2
SLIDE 2 2

Shashank Sahni

Principal SRE @ThousandEyes Reach out to shashank@thousandeyes.com Twitter @shredder12

@ThousandEyes @shredder12
slide-3
SLIDE 3 3

MySQL @ThousandEyes

Percona Xtradb Clusters Low Latency Transactional store 7k tx/sec

@ThousandEyes @shredder12
slide-4
SLIDE 4

What is a Slow Query?

slide-5
SLIDE 5

If exec_time > threshold

Poorly Designed Dealing with a lot of data Victims of Database Congestion

@ThousandEyes @shredder12 5
slide-6
SLIDE 6

Performance Impact

slide-7
SLIDE 7

Database Performance Impact

  • Slow by Design
  • High latency for

applications issuing them

  • Steal resources from
  • ther queries
  • DB congestion due to

extended locks.

  • Thrashing System Resources
  • Leaving DB unresponsive.

Outage!!

WORST WORSE BAD

@ThousandEyes @shredder12 7
slide-8
SLIDE 8

Slow Queries Always Sneak in

Bad Design

Human Mistake

Deleted Index Increasing table size

Schema Changes Performance Degrades Over Time

@ThousandEyes @shredder12 8
slide-9
SLIDE 9

Proactively dealing with Slow Queries

slide-10
SLIDE 10

Catch Early and Minimize Impact

New changes are pushed everyday Faster analysis Notify application

  • wner for faster

resolution

Continuous Process Automation Notification

@ThousandEyes @shredder12 10
slide-11
SLIDE 11

Slow Query Pipeline @ThousandEyes

slide-12
SLIDE 12 12 12

20 min

Detects new queries in under

@ThousandEyes @shredder12
slide-13
SLIDE 13

Notifications

  • Notifies the application owner

– MySQL user associated to app

  • JIRA Issues

– Creates Issue for new queries – Raises priority if performance worsens – Reopens Issue if query shows up again

@ThousandEyes @shredder12 13
slide-14
SLIDE 14

Select Top Offenders

Occurrence Total Exec Time Avg Exec Time

  • Avoids one off queries
  • Captures Recurring queries
  • Queries with high total exec_time
  • Filters queries which have small
avg but high count

count > C && (time_sum > S || time_avg > A)

  • Queries with high avg exec_time
  • Filters queries which have high
avg but small coun @ThousandEyes @shredder12 14
slide-15
SLIDE 15

Select Poorly Designed Queries

Full Table Scan Queued or Executing

  • Not using Indexes
  • Poor Joins
  • Rarely genuine
  • Filters query whose exec_time wasn’t spend in Storage
engine’s queue. Their Execution was indeed slow.
  • Set T to just under your slow query threshold
long_query_time.

full_scan_sum > 0 && Innodb_queue_wait_max < T

@ThousandEyes @shredder12 15
slide-16
SLIDE 16

Architecture

pt-query-digest pushing analyzed logs from databases Slow Query Database Anemometer Slow Query Notifier SQN Jira

@ThousandEyes @shredder12 16
slide-17
SLIDE 17

pt-query-digest

MySQL Query Analyzer from Percona

  • Great tool for ad hoc or batch analysis
  • Invaluable Insights

Our Setup

  • Runs periodically on all DB nodes
  • Analyzes slow query logs and stores the

data in a central slow query database.

@ThousandEyes @shredder12 17
slide-18
SLIDE 18

Anemometer

Slow Query Monitor from Box

  • Web utility to visualize and search through analyzed slow query data
  • Good Search and Deepdive features
  • Not under active development.
  • Github - box/anemometer
@ThousandEyes @shredder12 18
slide-19
SLIDE 19

Slow Query Notifier

SQN

From ThousandEyes

  • In-house tool to monitor slow query events.
  • Configurable query properties to catch top offenders

– JIRA workflow for notifications

  • create/reopen/prioritize
  • To be open-sourced
@ThousandEyes @shredder12 19
slide-20
SLIDE 20

Lessons Learned

slide-21
SLIDE 21

Target Top Offenders

Less Noise More Impact Happy Developers!

21 @ThousandEyes @shredder12
slide-22
SLIDE 22

Share Every Win

Result of resolving Top 4 queries

@ThousandEyes @shredder12 22
slide-23
SLIDE 23

Future Works

slide-24
SLIDE 24 @ThousandEyes @shredder12 24

Future Works

Support for notification backends – email etc. Support for Mongodb Evaluate PMM for Slow Query visualization Open source Slow-Query-Notifier

slide-25
SLIDE 25 25 @ThousandEyes @shredder12
slide-26
SLIDE 26

Thank You