1. Performance Schema in
MySQL
Danil Zburivsky
MySQL DBA and Team Lead at Pythian
Tuesday, October 23, 12
2. About myself
• MySQL DBA and Team
Lead at Pythian
• Managing dozens of
customers and
thousands of MySQL
servers
• http://www.pythian.com/
news/author/zburivsky/
• @zburivsky
Tuesday, October 23, 12
4. MySQL is a great database, but
instrumentation sucks
Slow query log SHOW ENGINE
INNODB STATUS
OS STATS
SHOW
PROCESSLIST
Tuesday, October 23, 12
5. I think there is a problem with
database...
Tuesday, October 23, 12
6. I think there is a problem with
database...
• Identify timeframe (use trending tools)
Tuesday, October 23, 12
7. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
Tuesday, October 23, 12
8. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
• Collect more data
Tuesday, October 23, 12
9. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
• Collect more data
• Collect as much data as you can!
Tuesday, October 23, 12
10. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
• Collect more data
• Collect as much data as you can!
• Try to make sense of it
Tuesday, October 23, 12
11. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
• Collect more data
• Collect as much data as you can!
• Try to make sense of it
• Tune settings, SQL, hardware. Did it help?
Tuesday, October 23, 12
12. I think there is a problem with
database...
• Identify timeframe (use trending tools)
• Collect data during incident
• Collect more data
• Collect as much data as you can!
• Try to make sense of it
• Tune settings, SQL, hardware. Did it help?
• I think there is a problem with database...
Tuesday, October 23, 12
13. Tools that might help you
• pt-stalk (http://www.percona.com/doc/
percona-toolkit/2.1/pt-stalk.html)
• innotop (http://code.google.com/p/
innotop/)
• Or you write your own stuff
Tuesday, October 23, 12
14. What do “Big Boys” have?
• Oracle: SQL-traces,
kernel events timings,
tons of books on
performance tuning
• SQL Server: SQL
profiler, Data
Management Views,
Extended Events,tons
of books on
performance tuning
Tuesday, October 23, 12
16. The Idea
• Executing a query breaks down to
hundreds of smaller tasks
• There are background tasks as well
• We want to instrument it all to know
where server is spending time
Tuesday, October 23, 12
17. Implementation
• Instrumentation: measuring when event
begins and ends
• Implemented in MySQL code on server
end storage engine level
• Can be enabled/disabled or customized
Tuesday, October 23, 12
30. Average wait per thread (I)
SELECT e.THREAD_ID, e.EVENT_NAME, MAX(e.AVG_TIMER_WAIT)
FROM events_waits_summary_by_thread_by_event_name e
LEFT JOIN threads t ON t.THREAD_ID = e.THREAD_ID
WHERE event_name LIKE 'wait/synch/mutex/innodb/%'
AND t.NAME='thread/sql/one_connection'
AND AVG_TIMER_WAIT > 0
GROUP BY t.thread_id, e.EVENT_NAME
ORDER BY t.thread_id, MAX(e.AVG_TIMER_WAIT)
Tuesday, October 23, 12
33. Picoseconds, shmicosecond! ps_helper to
rescue!
• http://www.markleith.co.uk/ps_helper/
• Great examples of using
performance_schema
• Useful tools for converting time, bytes,
paths into human readable format
Tuesday, October 23, 12
35. No free lunch: PFS overhead
• Instrumentation doesn’t come for free
• In CPU-bound workloads overhead can be
~15-20%
• In IO-bound — 5%-8%
• Significant improvements in 5.6
Tuesday, October 23, 12
37. What’s new in 5.6?
• performance_schema enabled by default!
• Less overhead: 5%-10% for CPU-bound
workload
• Statements, Stages, Actors and Objects
Tuesday, October 23, 12
38. Actors: filter events by user
(performance_schema) > SELECT * FROM setup_actors;
+------+------+------+
| HOST | USER | ROLE |
+------+------+------+
| % | % | % |
+------+------+------+
1 row in set (0.00 sec)
Tuesday, October 23, 12
39. Objects: filter out events by
database/table
(performance_schema) > SELECT * FROM setup_objects;
+-------------+--------------------+-------------+---------+-------+
| OBJECT_TYPE | OBJECT_SCHEMA | OBJECT_NAME | ENABLED | TIMED |
+-------------+--------------------+-------------+---------+-------+
| TABLE | mysql | % | NO | NO |
| TABLE | performance_schema | % | NO | NO |
| TABLE | information_schema | % | NO | NO |
| TABLE | % | % | YES | YES |
+-------------+--------------------+-------------+---------+-------+
4 rows in set (0.00 sec)
Tuesday, October 23, 12
41. Summary. Pros.
• Provides insight into internal server metric
• Flexible
• Relational model allows to build your own
views on top of this data
Tuesday, October 23, 12
42. Summary. Cons.
• Steep learning curve: not very well
documented
• Overhead for CPU-bound loads can be
significant
Tuesday, October 23, 12