Professional Documents
Culture Documents
Deep Dive
Mark Leith
Senior Software Development Manager
MySQL Enterprise Tools, Oracle
Program Agenda
1
Installation
Tracing Routines
Summary Views
Program Agenda
1
Installation
Tracing Routines
Summary Views
You are :
Using 5.1?
Using 5.5?
Using 5.6?
Using 5.7?
A Performance Schema user?
A Sys Schema user?
Program Agenda
1
Installation
Tracing Routines
Summary Views
+-----+---------------+-------+
+-------------+---------------+
| db
| sys_version | mysql_version |
+-----+---------------+-------+
+-------------+---------------+
| 1.5.0
| 5.7.9
+-------------+---------------+
| object_type
| count |
|
1 |
1 |
| sys | TRIGGER
2 |
| sys | FUNCTION
21 |
| sys | PROCEDURE
26 |
| sys | VIEW
100 |
+-----+---------------+-------+
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
10
Program Agenda
1
Installation
Tracing Routines
Summary Views
format_time
format_bytes
format_path
format_statement
extract_table_from_file_name
extract_schema_from_file_name
ps_is_account_enabled
ps_is_consumer_enabled
ps_is_instrument_default_enabled
ps_is_instrument_default_timed
ps_is_thread_instrumented
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
12
format_time() function
mysql> select format_time(23849723429) as time
-> union select format_time(8327423749233)
-> union select format_time(83274237492335);
+-------------+
| time
|
+-------------+
| 23.85 ms
|
| 8.33 s
|
| 00:01:23.27 |
+-------------+
format_bytes() function
mysql> select format_bytes(23423) as bytes
-> union select format_bytes(23432423)
-> union select format_bytes(42839479283)
-> union select format_bytes(2293848203489);
+-----------+
| bytes
|
+-----------+
| 22.87 KiB |
| 22.35 MiB |
| 39.90 GiB |
| 2.09 TiB |
+-----------+
Program Agenda
1
Installation
Tracing Routines
Summary Views
ps_trace_thread
ps_trace_statement_digest
ps_thread_trx_info
ps_thread_stack
ps_statement_avg_latency_histogram
diagnostics
17
ps_trace_statement_digest procedure
ps_trace_statement_digest() analyses live traffic looking for
certain statement digest for a period of time
Captures statistics on each matching statement it finds
Returns a report of the captured stats
An overall summary
A break down for the longest running example
An EXPLAIN (if the statement is not truncated)
ps_trace_statement_digest procedure
ps_trace_statement_digest() parameters
in_digest
The statement digest to analyse
How long to run analysis for
in_runtime
How often to snapshot data
in_interval
in_start_fresh
Whether to truncate P_S tables first
in_auto_enable Whether to auto enable required config
sys.ps_thread_trx_info(<thread_id>)
SELECT sys.ps_thread_trx_info(48) as trx_info\G
*************************** 1. row ***************************
trx_info: [
{
"time": "790.70 us",
"state": "COMMITTED",
"mode": "READ WRITE",
"autocommitted": "NO",
"gtid": "AUTOMATIC",
"isolation": "REPEATABLE READ",
"statements_executed": [
{
"sql_text": "INSERT INTO info VALUES (1, 'foo')",
"time": "471.02 us",
"schema": "trx",
"rows_examined": 0,
"rows_affected": 1,
"rows_sent": 0,
"tmp_tables": 0,
"tmp_disk_tables": 0,
"sort_rows": 0,
"sort_merge_passes": 0
},
...
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
Pass in thread id
ps_trace_thread procedure
ps_trace_thread() monitors a specific thread for a period
Captures as much information on the thread activity as possible
Returns a dot formatted file, that can graph the event hierarchy
http://en.wikipedia.org/wiki/DOT_(graph_description_language)
ps_trace_thread procedure
ps_trace_thread parameters
The thread to analyse
in_thread_id
in_outfile
The file to dump the data to (INTO OUTFILE)
How long to run analysis for
in_max_runtime
in_interval
How often to snapshot for data
in_start_fresh
Whether to truncate P_S tables first
in_auto_setup
Whether to auto enable required config
in_debug
Whether to also print debug info (source info)
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
MySQL 5.7
Procedures
Transactions
Statements
Stages
Waits
Program Agenda
1
Installation
Tracing Routines
Summary Views
user_summary
user_summary_by_file_io
user_summary_by_file_io_type
user_summary_by_stages
user_summary_by_statement_latency
user_summary_by_statement_type
host_summary
host_summary_by_file_io
host_summary_by_file_io_type
host_summary_by_stages
host_summary_by_statement_latency
host_summary_by_statement_type
37
user_summary view
mysql> select * from user_summary\G
*************************** 1. row ***************************
user: mark
statements: 3072
statement_latency: 1.77 s
statement_avg_latency: 575.29 us
table_scans: 7
file_ios: 20043
file_io_latency: 346.79 ms
current_connections: 1
total_connections: 1
MySQL 5.7
unique_hosts: 1
current_memory: 515.81 KiB
total_memory_allocated: 30.69 MiB
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
user_summary_by_file_io_type view
mysql> select * from user_summary_by_file_io_type;
+------+--------------------------------------+---------+-------------+-------------+
| user | event_name
| total
| latency
| max_latency |
+------+--------------------------------------+---------+-------------+-------------+
| mark | wait/io/file/myisam/dfile
|
19540 | 215.20 ms
| 120.79 ms
|
| mark | wait/io/file/myisam/kfile
|
501 | 131.58 ms
| 57.74 ms
|
| mark | wait/io/file/sql/dbopt
|
2 | 17.29 us
| 9.17 us
|
| root | wait/io/file/innodb/innodb_log_file | 2079432 | 00:28:27.62 | 1.30 s
|
| root | wait/io/file/myisam/kfile
| 5195927 | 00:17:07.33 | 1.17 s
|
| root | wait/io/file/myisam/dfile
| 1533813 | 00:07:27.59 | 1.18 s
|
| root | wait/io/file/sql/binlog
| 3517008 | 00:03:07.34 | 1.42 s
|
| root | wait/io/file/innodb/innodb_data_file |
20720 | 00:02:37.81 | 492.23 ms
|
| root | wait/io/file/sql/FRM
|
41412 | 3.17 s
| 80.43 ms
|
| root | wait/io/file/sql/dbopt
| 110993 | 1.23 s
| 63.27 ms
|
user_summary_by_statement_latency view
mysql> select * from user_summary_by_statement_latency\G
*************************** 1. row ***************************
user: mark
total: 176
total_latency: 1.26 s
max_latency: 583.33 ms
lock_latency: 216.95 ms
rows_sent: 311
rows_examined: 307
rows_affected: 0
full_scans: 7
user_summary_by_statement_type view
mysql> select * from user_summary_by_statement_type\G
*************************** 1. row ***************************
user: mark
statement: commit
total: 2463190
total_latency: 13.33h
max_latency: 12.18 s
lock_latency: 0 ps
rows_sent: 0
rows_examined: 0
rows_affected: 0
full_scans: 0
IO Summary Views
IO by current threads
Global summaries by file and
class, aggregating by bytes or
latency
Stream of last file IO events in
raw form
io_by_thread_by_latency
io_global_by_file_by_bytes
io_global_by_file_by_latency
io_global_by_wait_by_bytes
io_global_by_wait_by_latency
42
io_by_thread_by_latency view
mysql> select * from io_by_thread_by_latency\G
*************************** 1. row ***************************
user: main
total: 1193
total_latency: 136.45 ms
min_latency: 731.38 ns
avg_latency: 269.99 us
max_latency: 20.72 ms
thread_id: 1
processlist_id: NULL
*************************** 2. row ***************************
user: root@localhost
total: 533
total_latency: 53.81 ms
min_latency: 780.39 ns
avg_latency: 8.41 ms
max_latency: 25.06 ms
thread_id: 23
processlist_id: 4
io_global_by_file_by_latency view
mysql> select * from io_global_by_file_by_latency limit 1\G
*************************** 1. row ***************************
file: @@datadir/ibdata1
total: 1395714
total_latency: 00:28:53.06
count_read: 1006
read_latency: 4.51 s
count_write: 1326529
write_latency: 33.39 s
count_misc: 68179
misc_latency: 00:28:15.16
latest_file_io view
mysql> select * from latest_file_io;
+-----------------------------+----------------------------------+-----------+-----------+-----------+
| thread
| file
| latency
| operation | requested |
+-----------------------------+----------------------------------+-----------+-----------+-----------+
| root@localhost:63153:179371 | @@datadir/ib_logfile1
| 7.16 us
| lock
| NULL
|
| root@localhost:63153:179371 | @@datadir/ib_logfile1
| 6.16 us
| write
| 1.50 KiB |
| root@localhost:63153:179371 | @@datadir/ib_logfile1
| 14.36 ms | sync
| NULL
|
| root@localhost:63153:179371 | @@datadir/cerberus-bin.000012
| 28.25 us | write
| 905 bytes |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 15.25 us | write
| 1.00 KiB |
| root@localhost:57487:3
| @@datadir/cerberus-bin.000012
| 32.12 us | read
| 905 bytes |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 6.65 us
| write
| 1.00 KiB |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 213.32 us | sync
| NULL
|
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 17.27 us | write
| 1.00 KiB |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 286.01 us | sync
| NULL
|
| root@localhost:63177:179394 | @@datadir/cerberus-bin.000012
| 18.77 us | write
| 601 bytes |
| root@localhost:57487:3
| @@datadir/cerberus-bin.000012
| 7.55 us
| read
| 601 bytes |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 10.67 us | write
| 1.00 KiB |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 200.28 us | sync
| NULL
|
| root@localhost:63177:179394 | @@datadir/cerberus-bin.000012
| 12.91 us | write
| 601 bytes |
| root@localhost:57487:3
| @@datadir/cerberus-bin.000012
| 6.47 us
| read
| 601 bytes |
| root@localhost:63177:179394 | @@datadir/ib_logfile1
| 9.22 us
| write
| 1.50 KiB |
Object overview
Table usage statistics
Index usage statistics
Following show users only
schema_index_statistics
schema_object_overview
schema_table_statistics
schema_table_statistics_with_buffer
schema_tables_with_full_table_scans
schema_unused_indexes
46
schema_table_statistics view
mysql> select * from schema_table_statistics limit 1\G
*************************** 1. row ***************************
table_schema: mem__quan
table_name: normalized_statements_by_server_by_schema_data
total_latency: 00:55:07.80
rows_fetched: 239685
fetch_latency: 17.10 s
io_read_requests: 20639
rows_inserted: 1102895
io_read: 324.94 MiB
insert_latency: 00:52:18.10
io_read_latency: 00:03:04.10
rows_updated: 55910
io_write_requests: 1965973
update_latency: 00:02:28.62
io_write: 40.36 GiB
rows_deleted: 17899
io_write_latency: 25.46 s
delete_latency: 3.98 s
io_misc_requests: 18217
io_misc_latency: 00:14:06.02
schema_index_statistics view
mysql> select * from schema_index_statistics limit 1\G
*************************** 1. row ***************************
table_schema: mem__inventory
table_name: mysqlconnectionconfiguration
index_name: PRIMARY
rows_selected: 131399
select_latency: 00:07:05.03
rows_inserted: 0
insert_latency: 0 ps
rows_updated: 41608
update_latency: 21.96 s
rows_deleted: 0
delete_latency: 0 ps
schema_tables_with_full_table_scans view
mysql> select * from schema_tables_with_full_table_scans limit 10;
+--------------------+--------------------------------+-------------------+-----------+
| object_schema
| object_name
| rows_full_scanned | latency
|
+--------------------+--------------------------------+-------------------+-----------+
| mem30__instruments | fsstatistics
|
10207042 | 13.10 s
|
| mem30__instruments | preparedstatementapidata
|
436428 | 973.27 ms |
| mem30__instruments | mysqlprocessactivity
|
411702 | 282.07 ms |
| mem30__instruments | querycachequeriesincachedata
|
374011 | 767.15 ms |
| mem30__instruments | rowaccessesdata
|
322321 | 1.55 s
|
| mem30__instruments | connectionsmaxdata
|
301242 | 857.63 ms |
| mem30__instruments | innodbdatadictionarymemorydata |
292564 | 495.38 ms |
| mem30__instruments | innodbbufferpooldata
|
277112 | 1.95 s
|
| mem30__instruments | avgrowaccessesdata
|
269236 | 1.25 s
|
| mem30__instruments | innodbrowdetailsdata
|
248208 | 653.25 ms |
+--------------------+--------------------------------+-------------------+-----------+
schema_unused_indexes view
mysql> select * from schema_unused_indexes limit 10;
+--------------------+-----------------------------------+--------------------+
| object_schema
| object_name
| index_name
|
+--------------------+-----------------------------------+--------------------+
| mem30__bean_config | plists
| path
|
| mem30__config
| group_selections
| name
|
| mem30__config
| notification_groups
| name
|
| mem30__config
| user_form_defaults
| FKC1AEF1F9E7EE2CFB |
| mem30__enterprise | whats_new_entries
| entryId
|
| mem30__events
| action_logs
| policyId
|
| mem30__events
| action_logs
| eventId
|
| mem30__events
| action_logs
| ts
|
| mem30__events
| advisor_scopes_advisorcategoryids | FKF0CB0DB962CAB4
|
| mem30__events
| advisor_scopes_advisorclassids
| FK650AF1BF962CAB4 |
+--------------------+-----------------------------------+--------------------+
You should ensure you have representative time frame before taking any actions!
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
wait_classes_global_by_avg_latency
wait_classes_global_by_latency
waits_by_host_by_latency
waits_by_user_by_latency
waits_global_by_latency
51
waits_global_by_latency view
mysql> select * from waits_global_by_latency limit 10;
+--------------------------------------+----------+---------------+-------------+-------------+
| events
| total
| total_latency | avg_latency | max_latency |
+--------------------------------------+----------+---------------+-------------+-------------+
| wait/io/table/sql/handler
| 24196659 | 1.75h
| 259.72 us
| 2.29 s
|
| wait/io/file/innodb/innodb_data_file | 5964255 | 1.36h
| 822.01 us
| 1.49 s
|
| wait/io/file/innodb/innodb_log_file | 2272647 | 00:36:41.37
| 968.64 us
| 1.30 s
|
| wait/io/file/myisam/kfile
| 5463587 | 00:18:14.16
| 200.26 us
| 1.17 s
|
| wait/io/file/myisam/dfile
| 1715187 | 00:08:00.18
| 279.96 us
| 1.18 s
|
| wait/io/file/sql/binlog
| 3722079 | 00:03:23.71
| 54.73 us
| 1.42 s
|
| wait/lock/table/sql/handler
| 10074274 | 00:01:56.63
| 11.58 us
| 186.90 ms
|
| wait/io/socket/sql/client_connection | 3879827 | 25.36 s
| 6.54 us
| 219.25 ms
|
| wait/io/file/sql/FRM
|
43994 | 3.27 s
| 74.35 us
| 80.43 ms
|
| wait/io/file/sql/dbopt
|
116765 | 1.29 s
| 11.03 us
| 63.27 ms
|
+--------------------------------------+----------+---------------+-------------+-------------+
InnoDB only instance, this MyISAM IO is all temporary tables, focus tuning there!
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
waits_by_user_by_latency view
mysql> select * from waits_by_user_by_latency;
+------+--------------------------------------+----------+---------------+-------------+-------------+
| user | event
| total
| total_latency | avg_latency | max_latency |
+------+--------------------------------------+----------+---------------+-------------+-------------+
| mark | wait/io/file/myisam/dfile
|
19540 | 215.20 ms
| 11.01 us
| 120.79 ms
|
| mark | wait/io/file/myisam/kfile
|
501 | 131.58 ms
| 262.63 us
| 57.74 ms
|
| mark | wait/io/file/sql/dbopt
|
2 | 17.29 us
| 8.64 us
| 9.17 us
|
| root | wait/io/table/sql/handler
| 24189319 | 1.74h
| 258.77 us
| 2.29 s
|
| root | wait/io/file/innodb/innodb_log_file | 2162650 | 00:30:52.87
| 856.76 us
| 1.30 s
|
| root | wait/io/file/myisam/kfile
| 5460992 | 00:18:12.83
| 200.11 us
| 1.17 s
|
| root | wait/io/file/myisam/dfile
| 1694624 | 00:07:59.50
| 282.95 us
| 1.18 s
|
| root | wait/io/file/sql/binlog
| 3711637 | 00:03:23.16
| 54.74 us
| 1.42 s
|
| root | wait/io/file/innodb/innodb_data_file |
22577 | 00:03:05.73
| 8.23 ms
| 492.23 ms
|
| root | wait/lock/table/sql/handler
| 10069000 | 00:01:56.59
| 11.58 us
| 186.90 ms
|
schema_table_lock_waits
innodb_lock_waits
54
sys.schema_table_lock_waits
mysql> select * from sys.schema_table_lock_waits\G
*************************** 1. row ***************************
object_schema: test
object_name: t
waiting_thread_id: 43
waiting_pid: 21
waiting_account: msandbox@localhost
waiting_lock_type: SHARED_UPGRADABLE
waiting_lock_duration: TRANSACTION
waiting_query: alter table test.t add foo int
waiting_query_secs: 988
waiting_query_rows_affected: 0
waiting_query_rows_examined: 0
blocking_thread_id: 42
blocking_pid: 20
blocking_account: msandbox@localhost
blocking_lock_type: SHARED_NO_READ_WRITE
blocking_lock_duration: TRANSACTION
sql_kill_blocking_query: KILL QUERY 20
sql_kill_blocking_connection: KILL 20
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
sys.innodb_lock_waits
mysql> SELECT * FROM sys.innodb_lock_waits\G
*************************** 1. row ***************************
wait_started: 2014-11-11 13:39:20
wait_age: 00:00:07
wait_age_secs: 7
blocking_query:
locked_table: `db1`.`t1`
blocking_lock_id:
locked_index: PRIMARY
blocking_lock_mode:
locked_type: RECORD
blocking_trx_started:
waiting_trx_id: 867158
blocking_trx_age:
waiting_trx_started: 2014-11-11 13:39:15 blocking_trx_rows_locked:
waiting_trx_age: 00:00:12
blocking_trx_rows_modified:
waiting_trx_rows_locked: 0
sql_kill_blocking_query:
waiting_trx_rows_modified: 0
sql_kill_blocking_connection:
waiting_pid: 3
waiting_query: UPDATE t1 SET val = val + 1 WHERE id = 2
waiting_lock_id: 867158:2363:3:3
waiting_lock_mode: X
blocking_trx_id: 867157
blocking_pid: 4
...
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
statement_analysis
statements_with_errors_or_warnings
statements_with_full_table_scans
statements_with_runtimes_in_95th_p
ercentile
statements_with_sorting
statements_with_temp_tables
57
statement_analysis view
mysql> select * from statement_analysis limit 2\G
*************************** 1. row ***************************
query: INSERT INTO `mem30__quan` . `n ... nDuration` = IF ( VALUES ( ...
db: mem
full_scan:
exec_count: 4657
err_count: 0
warn_count: 0
total_latency: 00:03:57.40
max_latency: 10.54 s
avg_latency: 50.98 ms
tmp_tables: 0
lock_latency: 00:03:00.93
tmp_disk_tables: 0
rows_sent: 0
rows_sorted: 0
rows_sent_avg: 0
sort_merge_passes: 0
rows_examined: 0
digest: b98bfe333642e8e4e72c73515810d865
rows_examined_avg: 0
first_seen: 2014-09-24 11:27:01
rows_affected: 4794
last_seen: 2014-09-24 11:53:00
rows_affected_avg: 1
statements_with_errors_or_warnings view
mysql> select * from statements_with_errors_or_warnings limit 1\G
*************************** 1. row ***************************
query: CREATE TEMPORARY TABLE IF NOT ... _logs` ( `id` INT8 NOT NULL )
db: mem
exec_count: 1725
errors: 1725
error_pct: 100.0000
warnings: 0
warning_pct: 0.0000
first_seen: 2014-05-20 10:42:32
last_seen: 2014-05-21 18:39:22
digest: 51fb979dbc3910a6294c7cdabd7839c3
statements_with_temp_tables view
mysql> select * from statements_with_temp_tables limit 1\G
*************************** 1. row ***************************
query: SELECT * FROM ( SELECT `digest ... ` ,
`sum_no_index_used` AS ...
db: mysql
exec_count: 68
total_latency: 2.31 s
memory_tmp_tables: 476
disk_tmp_tables: 204
avg_tmp_tables_per_query: 7
tmp_tables_to_disk_pct: 43
first_seen: 2014-09-24 11:26:18
last_seen: 2014-09-24 12:33:00
digest: 50761c6a1818824328745d8a136b9ed6
statements_with_full_table_scans view
mysql> select * from statements_with_full_table_scans limit 1\G
*************************** 1. row ***************************
query: SELECT `pojotimese0_` . `id` A ...
ty_timeseries` `pojotimese0_`
db: mem
exec_count: 1
total_latency: 940.89 us
no_index_used_count: 1
no_good_index_used_count: 0
no_index_used_pct: 100
rows_sent: 116
rows_examined: 116
rows_sent_avg: 116
rows_examined_avg: 116
first_seen: 2014-09-24 11:25:03
last_seen: 2014-09-24 11:25:03
digest: f81b5ce10baee9be754cf35fd245a516
Copyright 2014, Oracle and/or its affiliates. All rights reserved. |
Miscellaneous Views
Better SHOW PROCESSLIST
No mutex contention
Live statistics for query
processlist
session
metrics
Consolidated metrics
62
sys.metrics
performance_schema.global_status
mysql> select * from sys.metrics limit 199, 10;
+-----------------------------+----------------+--------------------------------------+---------+
| Variable_name
| Variable_value | Type
| Enabled |
+-----------------------------+----------------+--------------------------------------+---------+
| tc_log_page_waits
| 0
| Global Status
| YES
|
| threads_cached
| 7
| Global Status
| YES
|
| threads_connected
| 3
| Global Status
| YES
|
| threads_created
| 10
| Global Status
| YES
|
| threads_running
| 3
| Global Status
| YES
|
| uptime
| 275689
| Global Status
| YES
|
| uptime_since_flush_status
| 275689
| Global Status
| YES
|
| adaptive_hash_pages_added
| 0
| InnoDB Metrics - adaptive_hash_index | NO
|
| adaptive_hash_pages_removed | 0
| InnoDB Metrics - adaptive_hash_index | NO
|
| adaptive_hash_rows_added
| 0
| InnoDB Metrics - adaptive_hash_index | NO
|
+-----------------------------+----------------+--------------------------------------+---------+
information_schema.innodb_metrics