Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Troubleshooting with MySQL
Performance Schema
Ivan Ma
2015-01-10
Join Hong Kong MySQL User Group on Facebook
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
2
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
MySQL : Agenda
1
2
3
4
5
Why and What – Performance Schema
Performance Schema Tables
Using MySQL Workbench
Try and See !
Questions
3
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Why Performance Schema?
System
Low throughput?
?
4
DBA
Hot table?
Network
High traffic on link?
Storage
Too much disk spin?App Developer
Slow application?
MySQL Developer
Code contention?
End User
Stuck session?
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
What is Performance Schema
• The MySQL Performance Schema is a feature for monitoring MySQL Server
execution at a low level.
– to inspect internal execution of the server at runtime.
(Data Collection by Instrumentation at code level. No separate threads.)
– implemented using the PERFORMANCE_SCHEMA storage engine
– to monitor server events. An “event” is anything the server does that takes time and
has been instrumented so that timing information can be collected.
• Tables in the performance_schema database are views or temporary tables
that use no persistent on-disk storage.
• No memory allocation is done beyond that which occurs during server
startup
5
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
The Journey : Then and now..
• MySQL 5.5
(1st Release P_S)
• Only waits events
– Mutex waits
– Conditions waits
– R/W locks waits
– File I/O waits
• Setup_(timers/consumers
/instruments) tables
• Few summary tables
• 17 Tables and 218
Instruments
• MySQL 5.6
• Statements and stages
• Table, Index and network
I/O. Table locks
• Host Cache
• User, account, host
• Setup_(actor/objects)
• Multiple summary tables
• Events’ hierarchy
• 52 Tables and 550
Instruments
• MySQL 5.7 (DMRs)
• Instrumentation:
– Transactions
– Metadata locks
– Prepared statements
– Stored programs
– Memory usage
• User variables
• Replication summary tables
• 76 Tables and 885
Instruments
• …
6
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
MySQL performance_schema Database
7
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
MySQL 5.6 Performance Schema Tables
• setup_% tables
• event_% tables
– Category
• stage
• statement
• wait
– Type
• current
• history
• Summary Tables
• Instances tables
• Connection tables
• Misc Tables
– host cache table
– performance timers
– threads
– users
– session*attrs
8
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Some notes with Using MySQL Workbench
• Default SQL Editor with
MySQL Workbench is
using ‘Safe update mode’
– Edit  Perference
• Why care –
– With Performance Schema,
No KEY
– Update setup_% tables may
not have ‘key’ on where
clause
9
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Performance Schema Options …(1)
10
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Performance Schema Options …(2)
11
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Performance Schema Options …(3)
12
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Default P_S setup_consumer
• Only a few instrumentation is ON
13
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
setup_actor
• (HOST, USER, ROLE) default with (‘%’, ‘%’, ’%’)
• All foreground threads are monitored.
• Update to this table has no change to existing started threads.
• Demo
14
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Summary Tables
15
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Getting statements summary by account (e.g. ‘tpcc’)
16
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Why the SQL takes so long to run …
17
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
At this moments
• We see
– How we can enable Performance Schema
– What to see (enable what you want to see to reduce the overhead)
• e.g. Only the session with the user login
– Statement taking too long to run
• What about “Wait Time”, “IO Time”, “Thread”, “Internal Stages”
18
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
A Better way to look at this by using sys schema
• Using MySQL Workbench
– The first time clicking the Performance Schema Setup  Install SYS schema
• SYS Schema
– A set of VIEWs on the Performance Schema
– A set of SPs to make things easier
• to clean up performance schema tables
19
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 20
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | 21
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
Summary
• Using Performance Schema
– Data Collection
– As a tools
– Overhead! Enable what you want to see.
• Using SYS Schema
– Friendly VIEWs to explore performance data set
22
20150110 my sql-performanceschema

20150110 my sql-performanceschema

  • 1.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Troubleshooting with MySQL Performance Schema Ivan Ma 2015-01-10 Join Hong Kong MySQL User Group on Facebook
  • 2.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. 2
  • 3.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | MySQL : Agenda 1 2 3 4 5 Why and What – Performance Schema Performance Schema Tables Using MySQL Workbench Try and See ! Questions 3
  • 4.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Why Performance Schema? System Low throughput? ? 4 DBA Hot table? Network High traffic on link? Storage Too much disk spin?App Developer Slow application? MySQL Developer Code contention? End User Stuck session?
  • 5.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | What is Performance Schema • The MySQL Performance Schema is a feature for monitoring MySQL Server execution at a low level. – to inspect internal execution of the server at runtime. (Data Collection by Instrumentation at code level. No separate threads.) – implemented using the PERFORMANCE_SCHEMA storage engine – to monitor server events. An “event” is anything the server does that takes time and has been instrumented so that timing information can be collected. • Tables in the performance_schema database are views or temporary tables that use no persistent on-disk storage. • No memory allocation is done beyond that which occurs during server startup 5
  • 6.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | The Journey : Then and now.. • MySQL 5.5 (1st Release P_S) • Only waits events – Mutex waits – Conditions waits – R/W locks waits – File I/O waits • Setup_(timers/consumers /instruments) tables • Few summary tables • 17 Tables and 218 Instruments • MySQL 5.6 • Statements and stages • Table, Index and network I/O. Table locks • Host Cache • User, account, host • Setup_(actor/objects) • Multiple summary tables • Events’ hierarchy • 52 Tables and 550 Instruments • MySQL 5.7 (DMRs) • Instrumentation: – Transactions – Metadata locks – Prepared statements – Stored programs – Memory usage • User variables • Replication summary tables • 76 Tables and 885 Instruments • … 6
  • 7.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | MySQL performance_schema Database 7
  • 8.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | MySQL 5.6 Performance Schema Tables • setup_% tables • event_% tables – Category • stage • statement • wait – Type • current • history • Summary Tables • Instances tables • Connection tables • Misc Tables – host cache table – performance timers – threads – users – session*attrs 8
  • 9.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Some notes with Using MySQL Workbench • Default SQL Editor with MySQL Workbench is using ‘Safe update mode’ – Edit  Perference • Why care – – With Performance Schema, No KEY – Update setup_% tables may not have ‘key’ on where clause 9
  • 10.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Performance Schema Options …(1) 10
  • 11.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Performance Schema Options …(2) 11
  • 12.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Performance Schema Options …(3) 12
  • 13.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Default P_S setup_consumer • Only a few instrumentation is ON 13
  • 14.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | setup_actor • (HOST, USER, ROLE) default with (‘%’, ‘%’, ’%’) • All foreground threads are monitored. • Update to this table has no change to existing started threads. • Demo 14
  • 15.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Summary Tables 15
  • 16.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Getting statements summary by account (e.g. ‘tpcc’) 16
  • 17.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Why the SQL takes so long to run … 17
  • 18.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | At this moments • We see – How we can enable Performance Schema – What to see (enable what you want to see to reduce the overhead) • e.g. Only the session with the user login – Statement taking too long to run • What about “Wait Time”, “IO Time”, “Thread”, “Internal Stages” 18
  • 19.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | A Better way to look at this by using sys schema • Using MySQL Workbench – The first time clicking the Performance Schema Setup  Install SYS schema • SYS Schema – A set of VIEWs on the Performance Schema – A set of SPs to make things easier • to clean up performance schema tables 19
  • 20.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | 20
  • 21.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | 21
  • 22.
    Copyright © 2014Oracle and/or its affiliates. All rights reserved. | Summary • Using Performance Schema – Data Collection – As a tools – Overhead! Enable what you want to see. • Using SYS Schema – Friendly VIEWs to explore performance data set 22