Download presentation
Presentation is loading. Please wait.
Published byEdwin Julian Townsend Modified over 9 years ago
2
MySQL Performance Schema New enhancements in MySQL 5.7 Mayank Prasad Principal Member Technical Staff Oracle, MySQL October 1, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
3
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. 3
4
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 3 4 5 6 4
5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 3 4 5 6 5
6
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Why Performance Schema? System Low throughput? ? 6 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?
7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | History and Origin “The Performance Schema is a mechanism to give user an insight of what is happening behind the scenes when MySQL server is running.” Development was started by Marc Alff in 2008. He is Chief Architect and Lead of Performance Schema Team (Christopher Powers and me) at Oracle-MySQL. Introduced in MySQL 5.5. New storage engine : Performance Schema New Database : performance_schema Statistics stored in tables (hard-coded DDLs). Non-persistent data. SQL user interface. 7
8
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | MySQL 5.7 Performance Schema : Design MySQL Server MySQL Server Instrumentation points (P_S hooks) P_S Internal Buffers P_S Storage Engine Storage Engine Interface Statistics Report Fetch Data SQL Query Collect Data Store Data P_S Tables 8
9
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 3 4 5 6 9
10
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | The Journey : Then and now.. MySQL 5.5 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 … 10
11
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 4 3 5 6 11
12
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Transaction Instrumentation Exposes all aspects of Transactions within server Implicit vs Explicit Quantitative (counts, timing) and Qualitative (isolation level) statistics Aggregated across several dimensions (user, account, session etc.) Statements to non-transactional tables are ignored (MyISAM) 12
13
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Transaction Instrumentation (cont.) Transactions stats at runtime * Units in PICOSECONDs EVENTS_TRANSACTIONS_SUMMARY_BY_THREAD_ BY_EVENT_NAME THREAD_ID23 EVENT_NAMETransaction COUNT_STAR3 SUM_TIMER_WAIT18558993066000* …… COUNT_READ_WRITE3 SUM_TIMER_READ_WRITE18558993066000* …… EVENTS_TRANSACTIONS_CURRENT THREAD_ID23 EVENT_ID11 EVENT_NAMETransaction STATECOMMITTED TIMER_WAIT22073180000* ACCESS_MODEREAD WRITE ISOLATION LEVELREPEATABLE READ AUTOCOMMITNO 13
14
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Event Hierarchy Session Transaction Statement* Stage ( closing tables, preparing, optimizing) Wait (sync, lock, i/o) Wait (sync, lock, i/o) * Transactional tables only. 14
15
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Event Hierarchy (cont.) An example START TRANSACTION; INSERT INTO test.t1 VALUES(‘3’); COMMIT; START TRANSACTION; INSERT INTO test.t1 VALUES(‘3’); COMMIT; 15
16
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Event Hierarchy (cont.) An example START TRANSACTION; INSERT INTO test.t1 VALUES(‘3’); COMMIT; START TRANSACTION; INSERT INTO test.t1 VALUES(‘3’); COMMIT; 16
17
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Metadata Locks Instrumentation METADATA_LOCKS OBJECT_TYPE:TABLE OBJECT_SCHEMA:test OBJECT_NAME:tab1 LOCK_TYPE:SHARED_READ LOCK_DURATION:TRANSACTION LOCK_STATUS:GRANTED OWNER_THREAD_ID:23 OWNER_EVENT_ID:41 17 wait/lock/metadata/sql/mdl What are MDLs? Exposes metadata lock dependencies between session. Which session holds MDL Which session waiting MDL Lock request status – PENDING, GRANTED, KILLED, TIMEDOUT
18
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Stored Programs Instrumentation New objects types in setup_objects. – PROCEDURE – FUNCTION – TRIGGER – EVENT Can be configured individually. Nesting is maintained. Triggers, Events, Functions, Procedures OBJECT_ TYPES OBJECT_ SCHEMA OBJECT_ NAME ENABLEDTIMED TABLEtesttab1YESNO PROCEDUREtestproc1NO TRIGGERdb1trg1YES FUNCTION%NO EVENT%NO SETUP_OBJECTS 18
19
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Stored Programs Instrumentation (contd..) Example : create trigger test.trg before insert on test.tab1 for each row insert into test.tab2 values ('2'); create procedure test.proc () BEGIN select count(*) from test.tab1; insert into test.tab1 values('123'); END call test.proc(); create trigger test.trg before insert on test.tab1 for each row insert into test.tab2 values ('2'); create procedure test.proc () BEGIN select count(*) from test.tab1; insert into test.tab1 values('123'); END call test.proc(); EVENTS_STATEMENTS_SUMMARY_BY_PROGRAM OBJECT_TYPE OBJECT_ SCHEMA OBJECT_ NAME COUNT_ STAR SUM_TIMER_ WAIT COUNT_ STATEMENT SUM_STATEMENTS_ WAIT SUM_ ERRORS SUM_ROWS_ AFFECTED PROCEDUREtestproc12123375900022112678600001 TRIGGERtesttrg120012010001197650500001 19
20
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Stored Programs Instrumentation (contd..) Example : (Nesting) 20 EVENTS_STATEMENTS_HISTORY EVENT_ID461 SQL_TEXTinsert into d1.tab1 values('123') OBJECT_TYPEPROCEDURE OBJECT_NAMEproc NESTING_EVENT_ID442 EVENTS_STATEMENTS_HISTORY EVENT_ID469 SQL_TEXTinsert into d1.tab2 values ('2') OBJECT_TYPETRIGGER OBJECT_NAMEtrg NESTING_EVENT_ID461
21
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Prepared Statements Instrumentation What are Prepared Statements? Exposes Prepared Statements in use by server. Covers – PREPARE – mysql_stmt_prepare() SQLCOM_PREPARE, COM_STMT_PREPARE 21
22
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Prepared Statements Instrumentation (contd.) Example prepare stmt1 from “select * from employee where emp_id=?”; Set @emp_id=12345; execute stmt1 USING @emp_id; prepare stmt1 from “select * from employee where emp_id=?”; Set @emp_id=12345; execute stmt1 USING @emp_id; EVENTS_STATEMENTS_HISTORY_LONG THREAD_ID: 20 EVENT_ID: 4 EVENT_NAME: statement/sql/prepare_sql SQL_TEXT: prepare stmt1 from "select * from employee where emp_id=?’;" … PREPARED_STATEMENTS_INSTANCES STATEMENT_ID: 1 STATEMENT_NAME: stmt1 SQL_TEXT: select * from employee where emp_id=? OWNER_THREAD_ID: 20 OWNER_EVENT_ID: 4 OWNER_OBJECT_TYPE: NULL OWNER_OBJECT_NAME: NULL COUNT_EXECUTE: 1 22
23
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | User Variables Exposes user-defined variables Max name limit 64 USER_VARIABLES_BY_THREAD Set @var_1=12345; -------- Set @var_2=67890; Set @var_1=12345; -------- Set @var_2=67890; USER_VARIABLES_BY_THREAD THREAD_IDVARIABLE_NAMEVARIABLE_VALUE 23var_112345 24var_267890 23
24
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Memory Usage Instrumentation Aspects covered : – Memory size – Operation Count (1M bytes once vs. 1 byte 1M times) – Low/high watermarks (spikes) Aggregation – Type of memory (various cache, internal buffers) – Thread/account/user/host Memory behavior of code/choice of design Who is taking what, how much and how many times. 24
25
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Memory Usages Instrumentation (contd..) MEMORY_SUMMARY_GLOBAL_BY_EVENT_NAME EVENT_NAMEmemory/sql/TABLE COUNT_ALLOC1381 COUNT_FREE924 SUM_NUMBER_OF_BYTES_ALLOC2059873 SUM_NUMBER_OF_BYTES_FREE1407432 CURRENT_COUNT_USED457 HIGH_COUNT_USED461 CURRENT_NUMBER_OF_BYTES_USED652441 HIGH_NUMBER_OF_BYTES_USED669269 Say : T1 : 1MB-2MB T2 : 10MB-12MB Together : 11MB - 14MB 25
26
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Replication Summary Tables Tables for replication statistics 26 SHOW SLAVE STATUS (Limitations) – Lots of information packed together – No logical division of information – No cherry picking (difficult for automation) – Difficult to scale (more new fields) Why Performance Schema Tables? – SQL Interface. Fetch what is required – Split logically into different tables – Easier to extend
27
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Replication Summary Tables Tables for replication statistics 27 Replication status Connection InformationExecute Information Connection Configuration Connection Status Execute Configuration Execute Status Coordinator/SQL Thread Worker Thread replication_connection _configuration replication_connection _status replication_execute_status _by_coordinator replication_execute_status _by_worker replication_execute _status replication_execute _configuration
28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Replication Summary Tables Tables for replication statistics TableInformation replication_connection_configuration(Host, Port, User etc.) replication_connection_status(Server UUID, Receiver thread ID, Service State etc.) replication_execute_configuration(Desired Delay) replication_execute_status(Remaining Delay) replication_execute_status_by_coordinator(Thread Id, Service State, Last Error info.) replication_execute_status_by_worker(WID, WTID, Service State, Last error Info.) 28
29
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 3 5 4 6 29
30
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Configuration Build Startup – Configuration file – Command line [mysqld] performance_schema_consumers_event_waits_history = ON. performance_schema_events_waits_history_size = 1000. performance_schema_instruments=‘statement/sql/% = COUNTED’ [mysqld] performance_schema_consumers_event_waits_history = ON. performance_schema_events_waits_history_size = 1000. performance_schema_instruments=‘statement/sql/% = COUNTED’ --performance_schema_consumers_event_waits_history = ON. --performance_schema_events_waits_history_size = 1000 --performance_schema_consumers_event_waits_history = ON. --performance_schema_events_waits_history_size = 1000 cmake. -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DDISABLE_PSI_MUTEX=1 30
31
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Configuration (contd..) Runtime Auto tune (value=-1) – Use heuristics to compute Max number of objects (mutex, rwlocks, files, sockets, threads etc.) Memory for statistical data (history, history_long, digest etc.) NOT ALL VARIABLES ARE AUTO TUNED. – Aligned with server tuning Use hints from server variables update setup_consumers set ENABLED=‘NO’ where NAME=‘global_instrumentation’;. update setup_instruments set ENABLED=‘YES’ where NAME=‘statement/sql/%’; update setup_consumers set ENABLED=‘NO’ where NAME=‘global_instrumentation’;. update setup_instruments set ENABLED=‘YES’ where NAME=‘statement/sql/%’; 31 max_connections table_open_cache table_definition_cache open_files_limit
32
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 3 4 6 5 32
33
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | An Example Lets say thread, with thread id T0, is trying to alter a table tab1 and is hung. Now, what T0 is waiting for – LOCK_STATUS=PENDING and OBJECT_NAME=‘tab1’ Lets see who has taken MDL on table tab1. – Thread T1 (column OWNER_THREAD_ID) is holding MDL. Is T1 waiting for some MDL? SELECT * FROM metadata_locks WHERE THREAD_ID = T0; SELECT * FROM metadata_locks WHERE OBJECT_NAME=‘tab1’, LOCK_STATUS=GRANTED; SELECT * FROM metadata_locks WHERE OWNER_THREAD_ID = T1, LOCK_STATUS=PENDING; Diagnose a stuck session 33
34
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | An Example (contd…) If T1 is not waiting for a MDL, then ? What T1 is waiting for – Say T1 is waiting for mutex_A (column OBJECT_INSTANCE_BEGIN) Lets see who has taken this mutex_A – Ok, so thread T2 is holding mutex_A (column LOCKED_BY_THREAD_ID) Find out what thread t2 is waiting for SELECT * FROM events_waits_current WHERE THREAD_ID = T1; SELECT * FROM mutex_instances WHERE OBJECT_INSTANCE_BEGIN = mutex_A; SELECT * FROM events_waits_current WHERE THREAD_ID = T2; Diagnose a stuck session 34
35
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Need and Origin The Journey : Then and now … New in MySQL-5.7 (DMRs) Configuration An example Q&A 1 2 4 5 6 3 35
36
Thank You! Q&A ? Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
37
MySQL sys Schema and Performance Sessions Session by Mark Lieth on MySQL sys Schema. – 12:45 PM - 1:30 PM - Moscone South – 250 Session by Dimitri on Performance and Scalability. – 2:00 PM - 2:45 PM - Moscone South - 252 37
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.