3. History of Performance Schema
•
•
•
•
First version: in MySQL 5.5
17 tables
Useful mostly for developers of MySQL code
Tools for
– Mutexes
– Locks
• Required good knowledge of MySQL code
4. Kinds of tables
• Settings
– _setup
– _instances
• Events
– events_waits_
• Digests
• History
• Other
5. Version 5.6 turned its face to DBA
• More features
• 52 tables
• New tables, very useful
for DBA
• Knowledge of MySQL
source code is not a
requirement anymore
*That's me talking at Devconf 2012 about how I am,
as MySQL Support engineer,
is happy with new features in Performance Schema
*
6. Tables for DBA
• events_statements_*
• events_stages_*
• Connection
12. event_stages_*
• Same information which you see in table
INFORMATION_SCHEMA.PROCESSLIST or SHOW
PROCESSLIST output
–
–
–
–
init
executing
Opening tables
...
• Replacement of SHOW PROFILE
• Only server-level
• No information from storage engine in this table!
13. event_stages_*:
«Sending data» for more than 10 seconds
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
mysql> select events_stages_history_long.event_name,
sql_text,
events_stages_history_long.timer_wait/1000000000000
wait_s from events_stages_history_long join
events_statements_history_long on
(events_stages_history_long.nesting_event_id =
events_statements_history_long.event_id) where
events_stages_history_long.EVENT_NAME like '%Sending
data' and rows_sent < 10000000 and
events_stages_history_long.timer_wait > 10*1000000000000
order by events_stages_history_long.timer_wait descG
************************ 1. row ************************
event_name: stage/sql/Sending data
sql_text: insert into test.t2 select * from test.t2
wait_s: 243.5235
1 rows in set (0.01 sec)
14. event_stages_*:
other operations which can run slow
• Everything, related to temporary tables
– EVENT_NAME LIKE 'stage/sql/%tmp%'
• Everything, related to locks
– EVENT_NAME LIKE 'stage/sql/%lock%'
• Everything in state «Waiting for»
– EVENT_NAME LIKE 'stage/%/Waiting for%'
• Frequently met issues (from my Support experience)
–
–
–
–
–
EVENT_NAME='stage/sql/end'
EVENT_NAME='stage/sql/freeing items'
EVENT_NAME='stage/sql/Sending data'
EVENT_NAME='stage/sql/cleaning up'
EVENT_NAME='stage/sql/closing tables'
21. Connection Attribute Tables: foreigners prohibited!
●
●
●
●
●
●
●
●
●
●
●
mysql> select PROCESSLIST_ID as PID, ATTR_NAME,
ATTR_VALUE from session_account_connect_attrs where
attr_name='program_name';
++++
| PID | ATTR_NAME | ATTR_VALUE |
++++
| 9 | program_name | mysql |
| 13 | program_name | Devconf2013 |
++++
2 rows in set (0.00 sec)
22. Connection Attribute Tables: foreigners prohibited!
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
mysql> select PROCESSLIST_ID as PID, ATTR_NAME,
ATTR_VALUE from session_account_connect_attrs where
attr_name='program_name' union select PROCESSLIST_ID as
PID, 'program_name' as ATTR_NAME,
sum(if(attr_name='program_name', 1, 0)) as ATTR_VALUE
from session_account_connect_attrs group by
processlist_id having(ATTR_VALUE=0);
++++
| PID | ATTR_NAME | ATTR_VALUE |
++++
| 9 | program_name | mysql |
| 13 | program_name | Devconf2013 |
| 21 | program_name | 0 |
++++
3 rows in set (0.01 sec)
23. host_cache
• Content of DNS cache
• Errors from
–
–
–
–
Name server
Connection
Authentication
max_connect_errors, max_user_errors, etc.
• Your first assistant in case of connection issue
24. threads
• Two kinds of THREADS
– Background
– Foreground
• Fields
– THREAD_ID
• Internal thread id
– PROCESSLIST_ID
• id, observable in the SHOW PROCESSLIST output
– NAME
• Instrument
– PARENT_THREAD_ID
• Internal id of the parent thread
– PROCESSLIST_*
• Only for для FOREGROUND threads
36. Which kind of events can we examine?
• setup_instruments.NAME
– wait/io/file
• Operations with files
– wait/io/socket
– wait/io/table/sql/handler
– wait/lock/table/sql/handler
– wait/synch/cond
• InnoDB, MyISAM, sql
– wait/synch/mutex
• sql, mysys, storage engines
– wait/synch/rwlock/
• sql, InnoDB, MyISAM
37. ps_helper
• All VIEWs work for MySQL 5.5
–
–
–
–
–
–
–
latest_file_io
top_io_by_file
top_io_by_thread
top_global_consumers_by_avg_latency
top_global_consumers_by_total_latency
top_global_io_consumers_by_latency
top_global_io_consumers_by_bytes_usage
• There are few views for 5.6 which use digest tables
38. *_instances tables
• file_instances
– Opened files
• socket_instances
– Connections
• cond_instances
• rwlock_instances
– select * from rwlock_instances where
READ_LOCKED_BY_COUNT > 0;
– select * from rwlock_instances where
WRITE_LOCKED_BY_THREAD_ID > 0;
• mutex_instances
– LOCKED_BY_THREAD_ID
40. Digests: events_stages_summary_*
• events_stages_summary_by_account_by_event_name
– Helps to find an account which performs problematic queries
• events_stages_summary_by_host_by_event_name
• events_stages_summary_by_user_by_event_name
– Same, but sorted by host and user name
• events_stages_summary_by_thread_by_event_name
– Easy to find out what makes troubles on your server right now
– Since statistics is saved for some time you can find it and after the
problem stopped to show up
• events_stages_summary_by_global_by_event_name
– Global stats by event name
– Does not indicate user, host, account and thread
46. Performance: version 5.5
• Performance Schema is OFF by default
• Noticeable performance issues
– Up to 7% in case of RO load
– Up to 20% in case of RW load
– Numbers based on tests by Dimitri Kravtchuk
(http://dimitrik.free.fr/blog/archives/2010/05/mysql-performance-using-performance-schema.html )
• No performance loss if turned off
47. Performance: version 5.6
• Performance Schema is ON by default
• Performance loss can happen, but not big
– Not more than 5% for most setups, likely near 0
– Maximum up to 10% in case if all instrumentations are turned ON
– Numbers based on tests by Dimitri Kravtchuk
(http://dimitrik.free.fr/blog/archives/2012/06/mysql-performance-pfs-overhead-in-56.html)
• global_instrumentation
– Minimal overhead
• Detailed instrumentation
– Noticeable overhead
• History tables
– minimal overhead
48. How P_S uses OS and hardware resources
• Memory
–
–
–
–
Allocated at the server startup
Freed when MySQL server is stopped
Uses arrays instead of linked lists
mysql> show engine performance_schema status;
++++
| Type | Name | Status |
++++
...
| performance_schema | performance_schema.memory | 68024616 |
++++
• CPU
– Depends from number of instruments
– More instruments — higher load
50. What, where and when to setup
• At compile time
• At the server startup
– Options in my.cnf
– All options are static
• Runtime
– setup_* tables
• What can you tune?
– Look for tables documentation
51. Configuration options
• performance_schema = ON|OFF
– Is it On or Off?
• performance_schema_%_size
– Size of history tables
– Size of instrumented objects
• performance_schema_max_%_classes
– Maximum number of cond|fle|io|% instruments
• performance_schema_max_%_instances
– Maximum number of cond|fle|io|% objects
52. Configuration options
• performance_schema_consumer_TABLE_NAME
– performance_schema_consumer_events_stages_current
– performance_schema_consumer_events_waits_current
– ...
• Turns instrumentations On of Off
– OFF, FALSE, 0
– ON, TRUE, 1
• setup_consumers table
– update setup_consumers set enabled='no'
where name='events_stages_current';
53. Tables setup_actors and setup_objects
• setup_actors
–
–
–
–
Which user threads to monitor
DELETE , then INSERT
UPDATE not allowed
insert into setup_actors values('%', 'sveta', '%');
• Only for user sveta
• setup_objects
– Which objects to monitor
– update setup_objects set enabled='no'
where object_schema='%';
– insert into setup_objects values
('TABLE', 'test', 't1', 'YES', 'YES');
54. •
•
•
•
setup_instruments table
Detailed setup of instruments
549 instruments in the standard distribution*
update setup_instruments set enabled='no';
update setup_instruments set enabled='yes'
where name like 'statement%';
*Written at June, 2013. Subject to change.
56. What happens inside Performance Schema?
●
●
●
●
●
●
●
●
●
●
mysql> show global status like 'perf%';
++
+
| Variable_name | Value
|
++
+
| Performance_schema_accounts_lost | 0
|
| Performance_schema_cond_classes_lost | 0
|
| Performance_schema_cond_instances_lost | 0
|
| Performance_schema_digest_lost | 0
|
...
●
●
If Value is not null — your *_size options are too small
57. •
•
•
•
•
What happens inside Performance Schema?
SHOW ENGINE PERFORMANCE_SCHEMA STATUS;
Contains information about memory usage
Table_name.attribute
(Internal_buffer).attribute
*.size, *.row_size
– Not-configurable, for example, size of a table row
• *.count, *.row_count
– Configurable with help of options
• *.memory
– size * count
– events_waits_history_long.memory
– performance_schema.memory
58. Where to find information?
• http://www.markleith.co.uk/ps_helper/
• http://www.drdobbs.com/database/detailed-profiling-of-sql-activity-in-my/240154959
• http://marcalff.blogspot.ru
• http://dimitrik.free.fr/blog/
• http://dev.mysql.com/doc/refman/5.6/en/performance-schema.html
59. Conclusion
• Performance schema — wonderful tool for a DBA
when she needs to troubleshoot performance issue
• You can configure it online: without server restart
• Allows very detailed setup
• Always tune it for your own needs!
• Don't instrument everything: use it for operations you
are interested in only
62. The preceding 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.