Top Banner
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
23
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 20150110 my sql-performanceschema

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

Page 2: 20150110 my sql-performanceschema

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

Page 3: 20150110 my sql-performanceschema

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

Page 4: 20150110 my sql-performanceschema

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?

Page 5: 20150110 my sql-performanceschema

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

Page 6: 20150110 my sql-performanceschema

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

Page 7: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

MySQL performance_schema Database

7

Page 8: 20150110 my sql-performanceschema

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

Page 9: 20150110 my sql-performanceschema

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

Page 10: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Performance Schema Options …(1)

10

Page 11: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Performance Schema Options …(2)

11

Page 12: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Performance Schema Options …(3)

12

Page 13: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Default P_S setup_consumer

• Only a few instrumentation is ON

13

Page 14: 20150110 my sql-performanceschema

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

Page 15: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Summary Tables

15

Page 16: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Getting statements summary by account (e.g. ‘tpcc’)

16

Page 17: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

Why the SQL takes so long to run …

17

Page 18: 20150110 my sql-performanceschema

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

Page 19: 20150110 my sql-performanceschema

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

Page 20: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

20

Page 21: 20150110 my sql-performanceschema

Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |

21

Page 22: 20150110 my sql-performanceschema

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

Page 23: 20150110 my sql-performanceschema