SlideShare a Scribd company logo
1 of 27
Download to read offline
Tracing and Profiling MySQL
Mostly with Linux tools: from strace and gdb to ftrace, bpftrace,
perf and dynamic probes
Valerii Kravchuk, Principal Support Engineer, MariaDB
vkravchuk@gmail.com
1
www.percona.com
Who am I?
Valerii (aka Valeriy) Kravchuk:
● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005-2012
● Principal Support Engineer in Percona, 2012-2016
● Principal Support Engineer in MariaDB Corporation since March 2016
● http://mysqlentomologist.blogspot.com - my blog about MySQL (a lot about
MySQL bugs, but some HowTos as well)
● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about
MySQL (mostly bugs…)
● http://bugs.mysql.com - my personal playground
● @mysqlbugs #bugoftheday
● Community Contributor of the Year 2019
● I like FOSDEM and used to participate at Percona Live conferences...
2
www.percona.com
Sources of tracing and profiling info for MySQL
● Trace files from -debug binaries, optimizer trace files
● (Extended) slow query log (thanks Percona!)
● show [global] status;
● show engine innodb statusG
● show engine innodb mutex;
● InnoDB-related tables in the INFORMATION_SCHEMA
● userstat (Percona Server and other builds)
● show profiles;
● PERFORMANCE_SCHEMA
● Profilers (even simple like pt-pmp or real like perf)
● OS-level tracing and profiling tools
● tcpdump analysis
3
www.percona.com
What is this session about?
● It’s about tracing and profiling MySQL, and mostly some
tools MySQL DBA can use for tracing and profiling in
production on Linux:
○ perf (I think it’s the best and easiest to use now)
○ few words on PMP (pt-pmp)
○ ftrace
○ eBPF and related tools (like bpftrace)
○ … and maybe more...
● Why not about gprof, Callgrind, Massif, dtrace, SystemTap?
● Why not entirely about Performance Schema?
● Performance impact of tracing and profiling
4
www.percona.com
Why not about Performance Schema?
● It may be NOT compiled in (see MySQL from Facebook)
● It may be NOT enabled when server was started (see
MariaDB)
● Specific instruments may not be enabled at startup and
then it’s too late (see Bug #68097)
● Sizing instruments properly (memory used and
performance impact vs details collected) may be
problematic (depends on version also)
● Part of the code or 3rd party plugin may not be
instrumented at all or in enough details (see Bug #83912)
● It does not give you a system-wide profiling, just for
selected parts of MySQL server code
● Other people (including myself) talk and write a lot about it
5
www.percona.com
Not Enough Details in Performance Schema
Samples: 52K of event 'cpu-clock', Event
count (approx.): 13037500000
Overhead Command Shared Object Symbol
43.75% mysqld mysqld [.]
Item_func_mul::int_op
16.97% mysqld mysqld [.]
Item_func_benchmark::val_int
14.10% mysqld mysqld [.]
Item_int::val_int
13.50% mysqld mysqld [.]
Item_func_numhybrid::val_int
...
2.58% mysqld mysqld [.]
Item_func_numhybrid::result_type
...
30 SELECT `benchmark` ( ?, ... * ? )
(13055172.39?)
30 stage/sql/init (51.56?)
30 stage/sql/checking permissions
(2.27?)
30 stage/sql/Opening tables (1.00?)
30 stage/sql/After opening tables
(0.62?)
30 stage/sql/init (9.32?)
30 stage/sql/optimizing (7.41?)
30 stage/sql/executing (13055061.32?)
30 stage/sql/end (3.98?)
30 stage/sql/query end (2.34?)
30 stage/sql/closing tables (1.73?)
30 stage/sql/freeing items (4.22?)
30 stage/sql/cleaning up (1.13?)
● Yes, this is for primitive select benchmark(500000000,2*2) from Bug #39630
● Performance Schema query is like 20 lines long to make it readable
6
www.percona.com
Typical “profiling” query to Performance Schema
● This is how it may look like:
SELECT thread_id, event_id, nesting_event_id, CONCAT( CASE WHEN event_name
LIKE 'stage%' THEN
CONCAT(' ', event_name) WHEN event_name LIKE 'wait%' AND
nesting_event_id IS NOT NULL THEN CONCAT(' ', event_name) ELSE
IF(digest_text IS NOT NULL, SUBSTR(digest_text, 1, 64), event_name) END,
' (',ROUND(timer_wait/1000000000, 2),'ms) ') event
FROM (
(SELECT thread_id,
event_id, event_name, timer_wait, timer_start, nesting_event_id,
digest_text FROM events_statements_history_long)
UNION
(SELECT
thread_id, event_id, event_name, timer_wait, timer_start,
nesting_event_id, NULL FROM events_stages_history_long)
UNION
(SELECT
thread_id, event_id, event_name, timer_wait, timer_start,
nesting_event_id, NULL FROM events_waits_history_long)
) events
ORDER BY thread_id, event_id;
7
www.percona.com
Not Enough Details in Performance Schema
● Now, where the time is spent on “statistics” stage in case
presented in Bug #83912?
| 26 | 379 | NULL | SELECT * FROM `t0` WHERE ID = ? (13072.50ms)
| 26 | 380 | 379 | stage/sql/init (0.05ms)
| 26 | 383 | 379 | stage/sql/checking permissions (0.00ms)
| 26 | 384 | 379 | stage/sql/Opening tables (0.02ms)
| 26 | 386 | 379 | stage/sql/After opening tables (0.00ms)
| 26 | 387 | 379 | stage/sql/System lock (0.00ms)
| 26 | 389 | 379 | stage/sql/Table lock (0.00ms)
| 26 | 391 | 379 | stage/sql/init (0.02ms)
| 26 | 392 | 379 | stage/sql/optimizing (0.01ms)
| 26 | 393 | 379 | stage/sql/statistics (13072.32ms)
| 26 | 396 | 379 | stage/sql/preparing (0.00ms)
| 26 | 397 | 379 | stage/sql/Unlocking tables (0.02ms)
| 26 | 398 | 379 | stage/sql/executing (0.00ms)
| 26 | 399 | 379 | stage/sql/Sending data (0.01ms)
| 26 | 400 | 379 | stage/sql/end (0.00ms)
| 26 | 401 | 379 | stage/sql/query end (0.00ms)
8
www.percona.com
So, what do I suggest?
● Use Linux tracing tools!
● Yes, all that “...strace, and ltrace, kprobes, and tracepoints, and uprobes, and
ftrace, and perf, and eBPF”
● Julia Evans explains and illustrates them all here
● Brendan D. Gregg explains them all with a lot of details and numerous
examples:
9
www.percona.com
Few words on strace
● strace may help MySQL DBA to find out:
● what files are accessed by the mysqld process or utilities, and in what
order
● why some MySQL-related command (silently) fails or hangs
● why some commands end up with permission denied or other errors
● what signals MySQL server and tools get
● what system calls could took a lot of time when something works slow
● when files are opened and closed, and how much data are read
● where the error log and other logs are really located (we can look for
system calls related to writing to stderr, for example)
● how MySQL really works with files, ports and sockets
● See my blog post for more details
● Use in production as a last resort (2 interrupts per system call, even not
those we care about, may leave traced process hanged)
● strace surely slows server down
10
www.percona.com
Few words on DTrace
● DTrace
● If you use Oracle Linux, go for it! Making it work on Fedora 29 took me too
much time to complete for the talk
11
www.percona.com
Few words on SystemTap (stap)
● SystemTap:
●
12
www.percona.com
Few words on pt-pmp (Poor Man’s Profiler)
● https://www.percona.com/doc/percona-toolkit/LATEST/pt-pmp.html
pt-pmp [-i 1] [-s 0] [-b mysqld] [-p pidofmysqld] [-l 0] [-k file] [--version]
● It is based on original idea by Domas, http://poormansprofiler.org/. I use
the awk code from the above to analyse backtraces of all threads.
● When mysqld hangs or is slow, you can get some insight quickly - use
pt-pmp to find out why (or what threads mostly do at the moment). For
example, see Bug #92108 (fixed in 5.7.25+, binlog access vs P_S query),
● Yet another example of how it is used: Bug #78277 - InnoDB deadlock,
thread stuck on kernel calls from transparent page compression, “Open”
● Use in production as a last resort (may hang mysqld, --SIGCONT)
● pt-pmp surely slows server down :) Hints:
○ https://bugs.launchpad.net/percona-toolkit/+bug/1320168 - partial
workaround
○ Use quickstack instead of gdb (check this discussion)
13
www.percona.com
pt-pmp Applied to “statistics” Case of Bug #83912
MariaDB [test]> select * from t0 where id = 15;
+----+------+--------------------+
| id | c1 | c2 |
+----+------+--------------------+
| 15 | 290 | 0.7441205286831786 |
+----+------+--------------------+
1 row in set ( 52.27 sec)
1
select(libc.so.6), os_thread_sleep(os0thread.cc:303), srv_conc_enter_innodb_wi
th_atomics(srv0conc.cc:298),srv_conc_enter_innodb(srv0conc.cc:298),innobase
_srv_conc_enter_innodb(ha_innodb.cc:1906), ha_innobase::index_read(ha_innodb.
cc:1906),handler::index_read_idx_map(handler.cc:5441),handler::ha_index_rea
d_idx_map(handler.cc:2646),join_read_(handler.cc:2646),join_read__table(han
dler.cc:2646), make_join_statistics(sql_select.cc:3935),JOIN::optimize_inner(
sql_select.cc:1366), JOIN::optimize(sql_select.cc:1045), mysql_select(sql_sele
ct.cc:3430),handle_select(sql_select.cc:372),execute_sqlcom_select(sql_pars
e.cc:5896),mysql_execute_command(sql_parse.cc:2971),mysql_parse(sql_parse.c
c:7319),dispatch_command(sql_parse.cc:1488),do_command(sql_parse.cc:1109),d
o_handle_one_connection(sql_connect.cc:1349),handle_one_connection(sql_conn
ect.cc:1261),pfs_spawn_thread(pfs.cc:1860),start_thread(libpthread.so.0),cl
one(libc.so.6)
...
14
www.percona.com
A lot about tracing sources
●
●
15
www.percona.com
A lot about ftrace
● ftrace
● The way you fundamentally interact with ftrace is:
○ Write to files in /sys/kernel/debug/tracing/
○ Read output from files in /sys/kernel/debug/tracing/
●
16
www.percona.com
A lot about eBPF
● eBPF is a tiny language for a VM that can be executed inside Linux Kernel. eBPF instructions can
be JIT-compiled into a native code. eBPF was originally conceived to power tools like tcpdump and
implement programmable network packed dispatch and tracing. Since Linux 4.1, eBPF programs
can be attached to kprobes and later - uprobes, enabling efficient programmable tracing
● Brendan Gregg explained it here:
17
www.percona.com
Few words about bpftrace
●
●
18
www.percona.com
A lot about perf
● If you are interested in details presented nicely...
●
19
www.percona.com
Adding uprobes to MySQL dynamically with perf
● The idea was to add dynamic probe to capture SQL queries
● This was done on Ubuntu 16.04 with recent Percona Server 5.7
● First I had to find out with gdb where is the query (hint: dispatch_command
has com_data parameter):
(gdb) p com_data->com_query.query
$4 = 0x7fb0dba8d021 "select 2"
● Then it’s just as easy as follows:
openxs@ao756:~$ sudo perf probe -x /usr/sbin/mysqld 'dispatch_command
com_data->com_query.query:string'
openxs@ao756:~$ sudo perf record -e 'probe_mysqld:dispatch_command*' -aR
^C[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.676 MB perf.data (3 samples) ]
openxs@ao756:~$ sudo perf script >/tmp/queries.txt
openxs@ao756:~$ sudo perf probe --del dispatch_command
20
www.percona.com
Adding uprobes to MySQL dynamically with perf
● We have queries captured with probe added on previous slide:
openxs@ao756:~$ cat /tmp/queries.txt
mysqld 31340 [001] 3888.849079: probe_mysqld:dispatch_command:
(be9250) query="select 100"
mysqld 31340 [001] 3891.648739: probe_mysqld:dispatch_command:
(be9250) query="select user, host from mysql.user"
mysqld 31340 [001] 3895.890141: probe_mysqld:dispatch_command:
(be9250) query="select 2"
● We can control output format, but basically we see binary, PID, CPU where
uprobe was executed on, timestamp (milliseconds since start of record),
probe and variables with format we specified
●
21
www.percona.com
perf - Success Stories
● perf (sometimes called perf_events or perf tools, originally Performance
Counters for Linux, PCL) is a new performance analyzing tool for Linux,
available from kernel version 2.6.31 (supported by RHEL6 since 2010)
● It is easier to use .and more popular recently for MySQL than older profilers
● Here is the list of some MySQL bugs by Mark Callaghan confirmed by perf:
○ Bug #69236 - "performance regressions for single-threaded workloads, part 2" -
MySQL 5.6 is spending a lot more time in rec_get_offsets_func,
trx_undo_report_row_operation, btr_cur_optimistic_insert. Same in 5.7.8, “Verified”
○ Bug #74325 - “updates to indexed column much slower in 5.7.5” - nice perf outputs
there. It’s about innodb_fill_factor=100 (that leaves 1/16 free space since 5.7.8).
○ Bug #74280 - “covering secondary scans worse than PK scan at high concurrency” -
the mutex contention that isn't visible in P_S output because the block rw-lock isn't
instrumented. Verified regression since 5.7.5 vs 5.6.x. See also:
Bug #74283 - “Non-covering secondary index scans degrade more in 5.7 than 5.6”
○ http://smalldatum.blogspot.com/2014/10/details-on-range-scan-performance.html - on
two bugs above, perf allows to see the difference
22
www.percona.com
perf - Basic Usage
● Check my post, “perf Basics for MySQL Profiling”, for details and references,
but basic minimal steps are:
○ Make sure perf-related packages are installed (perf with RPMs) for your kernel:
sudo apt-get install linux-tools-generic
○ Make sure debug symbols are installed and software is built with -fno-omit-frame-pointer
○ Start data collection for some time using perf record:
sudo perf record -a [-g] [-F99] [-p `pidof mysqld`] sleep 30
Run your problematic load against MySQL server
○ Samples are collected in `pwd`/perf.data by default
○ Process samples and display the profile using perf report:
sudo perf report [-n] [-g] --stdio
● Alternatively, run in foreground and interrupt any time with Ctrl-C:
[root@centos ~]# perf record -ag
^C
● Or run in background and send -SIGINT when done:
[root@centos ~]# perf record -ag &
[1] 2353
[root@centos ~]# kill -sigint 2353
● Let’s see how it works alive… (demo). We’ll see perf top, perf record -g etc
23
www.percona.com
perf - Call Graphs
Use -g option of perf record to get call graphs/backtraces with perf, then:
openxs@ao756:~/dbs/maria10.1$ sudo perf report --stdio
...
31.02% mysqld mysqld [.] Item_func_mul::int_op()
|
--- Item_func_mul::int_op()
|
|--94.56%-- Item_func_hybrid_field_type::val_int()
| Item_func_benchmark::val_int()
| Item::send(Protocol*, String*)
| Protocol::send_result_set_row(List<Item>*)
| select_send::send_data(List<Item>&)
| JOIN::exec_inner()
| JOIN::exec()
| mysql_select(THD*, Item***, TABLE_LIST*, ...
| handle_select(THD*, LEX*, select_result*, unsigned
long)
| execute_sqlcom_select(THD*, TABLE_LIST*)
| mysql_execute_command(THD*)
| mysql_parse(THD*, char*, unsigned int, Parser_state*)
| dispatch_command(enum_server_command, THD*, char*,
...)
| do_command(THD*)
...
24
www.percona.com
Studying Hanging in “statistics” Case(s)
● See my blog post for details and full outputs:
| |--71.70%-- srv_conc_enter_innodb(trx_t*)
| | ha_innobase::index_read(...)
| | handler::index_read_idx_map(...)
| | handler::ha_index_read_idx_map(...)
| | join_read_const(st_join_table*)
| | join_read_const_table(THD*, ...)
| | make_join_statistics(JOIN*, ...)
| | JOIN::optimize_inner()
| | JOIN::optimize()
| | mysql_select(THD*, ...)
...
● We can see that time to do SELECT is mostly spent waiting to enter InnoDB
queue while reading data via index (dive) to get statistics for the optimizer
● We can see where the time is spent by kernel and other processes (-a)
25
www.percona.com
Am I crazy doing these?
● Quite possible, maybe I just have too much free time :)
● Or maybe I do not know how to use Performance Schema properly
● But I am not alone...
● MariaDB developers are interested in adding dynamic probes with perf while
working on RocksDB storage engine performance problems
● People use perf probes for tracing Oracle RDBMS! There is enough
instrumentation there for almost everything, but still...
● Dynamic tracers are proven tools for instrumenting OS calls (probes for
measuring I/O latency at microsecond precision, for example)
● Another topic, more complex but also more exciting, is dynamic tracing of
RDBMS userspace. This topic is of growing interest with modern servers
hosting large amounts of RAM and workloads that are often CPU-bound.
There are no “waits”, but time is still spent somewhere!
● For open source RDBMS like MySQL there is no reason NOT to use
dynamic probes while UDST are not on every other line of the code :)
● eBPF and bpftrace make it even easier and safer to do these in production
26
www.percona.com
Thank you!
Questions and Answers?
Please, report bugs at:
https://bugs.mysql.com
https://jira.mariadb.org
https://jira.percona.com
27

More Related Content

What's hot

Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021Valeriy Kravchuk
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomValeriy Kravchuk
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsValeriy Kravchuk
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Valeriy Kravchuk
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreMariaDB Corporation
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukValeriy Kravchuk
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Valeriy Kravchuk
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)Valeriy Kravchuk
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014FromDual GmbH
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaFromDual GmbH
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeSveta Smirnova
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Antony T Curtis
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMySQLConference
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsJean-François Gagné
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsJean-François Gagné
 
Riding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication StreamRiding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication StreamJean-François Gagné
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsJean-François Gagné
 

What's hot (20)

Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021Linux  /proc filesystem for MySQL DBAs - FOSDEM 2021
Linux /proc filesystem for MySQL DBAs - FOSDEM 2021
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50mins
 
Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013Performance schema in_my_sql_5.6_pluk2013
Performance schema in_my_sql_5.6_pluk2013
 
The New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and moreThe New MariaDB Offering - MariaDB 10, MaxScale and more
The New MariaDB Offering - MariaDB 10, MaxScale and more
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
Dynamic tracing of MariaDB on Linux - problems and solutions (MariaDB Server ...
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
E bpf and dynamic tracing for mariadb db as (mariadb day during fosdem 2020)
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
 
NoSQL with MySQL
NoSQL with MySQLNoSQL with MySQL
NoSQL with MySQL
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
HA with Galera
HA with GaleraHA with Galera
HA with Galera
 
Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)Perl Stored Procedures for MySQL (2009)
Perl Stored Procedures for MySQL (2009)
 
Make Your Life Easier With Maatkit
Make Your Life Easier With MaatkitMake Your Life Easier With Maatkit
Make Your Life Easier With Maatkit
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitationsMySQL/MariaDB Parallel Replication: inventory, use-case and limitations
MySQL/MariaDB Parallel Replication: inventory, use-case and limitations
 
Riding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication StreamRiding the Binlog: an in Deep Dissection of the Replication Stream
Riding the Binlog: an in Deep Dissection of the Replication Stream
 
MySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitationsMySQL Parallel Replication: inventory, use-case and limitations
MySQL Parallel Replication: inventory, use-case and limitations
 

Similar to Tracing MySQL with Linux Tools

Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Fosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFrederic Descamps
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Brian Brazil
 
PostgreSQL Monitoring using modern software stacks
PostgreSQL Monitoring using modern software stacksPostgreSQL Monitoring using modern software stacks
PostgreSQL Monitoring using modern software stacksShowmax Engineering
 
Oracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdfOracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdfAlex446314
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsFromDual GmbH
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2PgTraining
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016Brendan Gregg
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part IIIAlkin Tezuysal
 
Loadays managing my sql with percona toolkit
Loadays managing my sql with percona toolkitLoadays managing my sql with percona toolkit
Loadays managing my sql with percona toolkitFrederic Descamps
 
MariaDB 10.2 New Features
MariaDB 10.2 New FeaturesMariaDB 10.2 New Features
MariaDB 10.2 New FeaturesFromDual GmbH
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangaspgdayrussia
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMayank Prasad
 
Performance Analysis: new tools and concepts from the cloud
Performance Analysis: new tools and concepts from the cloudPerformance Analysis: new tools and concepts from the cloud
Performance Analysis: new tools and concepts from the cloudBrendan Gregg
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기Ji-Woong Choi
 

Similar to Tracing MySQL with Linux Tools (20)

Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Fosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkitFosdem managing my sql with percona toolkit
Fosdem managing my sql with percona toolkit
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)Prometheus and Docker (Docker Galway, November 2015)
Prometheus and Docker (Docker Galway, November 2015)
 
PostgreSQL Monitoring using modern software stacks
PostgreSQL Monitoring using modern software stacksPostgreSQL Monitoring using modern software stacks
PostgreSQL Monitoring using modern software stacks
 
Oracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdfOracle_Patching_Untold_Story_Final_Part2.pdf
Oracle_Patching_Untold_Story_Final_Part2.pdf
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
 
Linux Systems Performance 2016
Linux Systems Performance 2016Linux Systems Performance 2016
Linux Systems Performance 2016
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
 
Loadays managing my sql with percona toolkit
Loadays managing my sql with percona toolkitLoadays managing my sql with percona toolkit
Loadays managing my sql with percona toolkit
 
Lxbrand
LxbrandLxbrand
Lxbrand
 
MariaDB 10.2 New Features
MariaDB 10.2 New FeaturesMariaDB 10.2 New Features
MariaDB 10.2 New Features
 
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki LinnakangasPG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
PG Day'14 Russia, PostgreSQL System Architecture, Heikki Linnakangas
 
MySQL Performance Schema : fossasia
MySQL Performance Schema : fossasiaMySQL Performance Schema : fossasia
MySQL Performance Schema : fossasia
 
Performance Analysis: new tools and concepts from the cloud
Performance Analysis: new tools and concepts from the cloudPerformance Analysis: new tools and concepts from the cloud
Performance Analysis: new tools and concepts from the cloud
 
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
[오픈소스컨설팅] 프로메테우스 모니터링 살펴보고 구성하기
 

Recently uploaded

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Recently uploaded (20)

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

Tracing MySQL with Linux Tools

  • 1. Tracing and Profiling MySQL Mostly with Linux tools: from strace and gdb to ftrace, bpftrace, perf and dynamic probes Valerii Kravchuk, Principal Support Engineer, MariaDB vkravchuk@gmail.com 1
  • 2. www.percona.com Who am I? Valerii (aka Valeriy) Kravchuk: ● MySQL Support Engineer in MySQL AB, Sun and Oracle, 2005-2012 ● Principal Support Engineer in Percona, 2012-2016 ● Principal Support Engineer in MariaDB Corporation since March 2016 ● http://mysqlentomologist.blogspot.com - my blog about MySQL (a lot about MySQL bugs, but some HowTos as well) ● https://www.facebook.com/valerii.kravchuk - my Facebook page, a lot about MySQL (mostly bugs…) ● http://bugs.mysql.com - my personal playground ● @mysqlbugs #bugoftheday ● Community Contributor of the Year 2019 ● I like FOSDEM and used to participate at Percona Live conferences... 2
  • 3. www.percona.com Sources of tracing and profiling info for MySQL ● Trace files from -debug binaries, optimizer trace files ● (Extended) slow query log (thanks Percona!) ● show [global] status; ● show engine innodb statusG ● show engine innodb mutex; ● InnoDB-related tables in the INFORMATION_SCHEMA ● userstat (Percona Server and other builds) ● show profiles; ● PERFORMANCE_SCHEMA ● Profilers (even simple like pt-pmp or real like perf) ● OS-level tracing and profiling tools ● tcpdump analysis 3
  • 4. www.percona.com What is this session about? ● It’s about tracing and profiling MySQL, and mostly some tools MySQL DBA can use for tracing and profiling in production on Linux: ○ perf (I think it’s the best and easiest to use now) ○ few words on PMP (pt-pmp) ○ ftrace ○ eBPF and related tools (like bpftrace) ○ … and maybe more... ● Why not about gprof, Callgrind, Massif, dtrace, SystemTap? ● Why not entirely about Performance Schema? ● Performance impact of tracing and profiling 4
  • 5. www.percona.com Why not about Performance Schema? ● It may be NOT compiled in (see MySQL from Facebook) ● It may be NOT enabled when server was started (see MariaDB) ● Specific instruments may not be enabled at startup and then it’s too late (see Bug #68097) ● Sizing instruments properly (memory used and performance impact vs details collected) may be problematic (depends on version also) ● Part of the code or 3rd party plugin may not be instrumented at all or in enough details (see Bug #83912) ● It does not give you a system-wide profiling, just for selected parts of MySQL server code ● Other people (including myself) talk and write a lot about it 5
  • 6. www.percona.com Not Enough Details in Performance Schema Samples: 52K of event 'cpu-clock', Event count (approx.): 13037500000 Overhead Command Shared Object Symbol 43.75% mysqld mysqld [.] Item_func_mul::int_op 16.97% mysqld mysqld [.] Item_func_benchmark::val_int 14.10% mysqld mysqld [.] Item_int::val_int 13.50% mysqld mysqld [.] Item_func_numhybrid::val_int ... 2.58% mysqld mysqld [.] Item_func_numhybrid::result_type ... 30 SELECT `benchmark` ( ?, ... * ? ) (13055172.39?) 30 stage/sql/init (51.56?) 30 stage/sql/checking permissions (2.27?) 30 stage/sql/Opening tables (1.00?) 30 stage/sql/After opening tables (0.62?) 30 stage/sql/init (9.32?) 30 stage/sql/optimizing (7.41?) 30 stage/sql/executing (13055061.32?) 30 stage/sql/end (3.98?) 30 stage/sql/query end (2.34?) 30 stage/sql/closing tables (1.73?) 30 stage/sql/freeing items (4.22?) 30 stage/sql/cleaning up (1.13?) ● Yes, this is for primitive select benchmark(500000000,2*2) from Bug #39630 ● Performance Schema query is like 20 lines long to make it readable 6
  • 7. www.percona.com Typical “profiling” query to Performance Schema ● This is how it may look like: SELECT thread_id, event_id, nesting_event_id, CONCAT( CASE WHEN event_name LIKE 'stage%' THEN CONCAT(' ', event_name) WHEN event_name LIKE 'wait%' AND nesting_event_id IS NOT NULL THEN CONCAT(' ', event_name) ELSE IF(digest_text IS NOT NULL, SUBSTR(digest_text, 1, 64), event_name) END, ' (',ROUND(timer_wait/1000000000, 2),'ms) ') event FROM ( (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, digest_text FROM events_statements_history_long) UNION (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, NULL FROM events_stages_history_long) UNION (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, NULL FROM events_waits_history_long) ) events ORDER BY thread_id, event_id; 7
  • 8. www.percona.com Not Enough Details in Performance Schema ● Now, where the time is spent on “statistics” stage in case presented in Bug #83912? | 26 | 379 | NULL | SELECT * FROM `t0` WHERE ID = ? (13072.50ms) | 26 | 380 | 379 | stage/sql/init (0.05ms) | 26 | 383 | 379 | stage/sql/checking permissions (0.00ms) | 26 | 384 | 379 | stage/sql/Opening tables (0.02ms) | 26 | 386 | 379 | stage/sql/After opening tables (0.00ms) | 26 | 387 | 379 | stage/sql/System lock (0.00ms) | 26 | 389 | 379 | stage/sql/Table lock (0.00ms) | 26 | 391 | 379 | stage/sql/init (0.02ms) | 26 | 392 | 379 | stage/sql/optimizing (0.01ms) | 26 | 393 | 379 | stage/sql/statistics (13072.32ms) | 26 | 396 | 379 | stage/sql/preparing (0.00ms) | 26 | 397 | 379 | stage/sql/Unlocking tables (0.02ms) | 26 | 398 | 379 | stage/sql/executing (0.00ms) | 26 | 399 | 379 | stage/sql/Sending data (0.01ms) | 26 | 400 | 379 | stage/sql/end (0.00ms) | 26 | 401 | 379 | stage/sql/query end (0.00ms) 8
  • 9. www.percona.com So, what do I suggest? ● Use Linux tracing tools! ● Yes, all that “...strace, and ltrace, kprobes, and tracepoints, and uprobes, and ftrace, and perf, and eBPF” ● Julia Evans explains and illustrates them all here ● Brendan D. Gregg explains them all with a lot of details and numerous examples: 9
  • 10. www.percona.com Few words on strace ● strace may help MySQL DBA to find out: ● what files are accessed by the mysqld process or utilities, and in what order ● why some MySQL-related command (silently) fails or hangs ● why some commands end up with permission denied or other errors ● what signals MySQL server and tools get ● what system calls could took a lot of time when something works slow ● when files are opened and closed, and how much data are read ● where the error log and other logs are really located (we can look for system calls related to writing to stderr, for example) ● how MySQL really works with files, ports and sockets ● See my blog post for more details ● Use in production as a last resort (2 interrupts per system call, even not those we care about, may leave traced process hanged) ● strace surely slows server down 10
  • 11. www.percona.com Few words on DTrace ● DTrace ● If you use Oracle Linux, go for it! Making it work on Fedora 29 took me too much time to complete for the talk 11
  • 12. www.percona.com Few words on SystemTap (stap) ● SystemTap: ● 12
  • 13. www.percona.com Few words on pt-pmp (Poor Man’s Profiler) ● https://www.percona.com/doc/percona-toolkit/LATEST/pt-pmp.html pt-pmp [-i 1] [-s 0] [-b mysqld] [-p pidofmysqld] [-l 0] [-k file] [--version] ● It is based on original idea by Domas, http://poormansprofiler.org/. I use the awk code from the above to analyse backtraces of all threads. ● When mysqld hangs or is slow, you can get some insight quickly - use pt-pmp to find out why (or what threads mostly do at the moment). For example, see Bug #92108 (fixed in 5.7.25+, binlog access vs P_S query), ● Yet another example of how it is used: Bug #78277 - InnoDB deadlock, thread stuck on kernel calls from transparent page compression, “Open” ● Use in production as a last resort (may hang mysqld, --SIGCONT) ● pt-pmp surely slows server down :) Hints: ○ https://bugs.launchpad.net/percona-toolkit/+bug/1320168 - partial workaround ○ Use quickstack instead of gdb (check this discussion) 13
  • 14. www.percona.com pt-pmp Applied to “statistics” Case of Bug #83912 MariaDB [test]> select * from t0 where id = 15; +----+------+--------------------+ | id | c1 | c2 | +----+------+--------------------+ | 15 | 290 | 0.7441205286831786 | +----+------+--------------------+ 1 row in set ( 52.27 sec) 1 select(libc.so.6), os_thread_sleep(os0thread.cc:303), srv_conc_enter_innodb_wi th_atomics(srv0conc.cc:298),srv_conc_enter_innodb(srv0conc.cc:298),innobase _srv_conc_enter_innodb(ha_innodb.cc:1906), ha_innobase::index_read(ha_innodb. cc:1906),handler::index_read_idx_map(handler.cc:5441),handler::ha_index_rea d_idx_map(handler.cc:2646),join_read_(handler.cc:2646),join_read__table(han dler.cc:2646), make_join_statistics(sql_select.cc:3935),JOIN::optimize_inner( sql_select.cc:1366), JOIN::optimize(sql_select.cc:1045), mysql_select(sql_sele ct.cc:3430),handle_select(sql_select.cc:372),execute_sqlcom_select(sql_pars e.cc:5896),mysql_execute_command(sql_parse.cc:2971),mysql_parse(sql_parse.c c:7319),dispatch_command(sql_parse.cc:1488),do_command(sql_parse.cc:1109),d o_handle_one_connection(sql_connect.cc:1349),handle_one_connection(sql_conn ect.cc:1261),pfs_spawn_thread(pfs.cc:1860),start_thread(libpthread.so.0),cl one(libc.so.6) ... 14
  • 15. www.percona.com A lot about tracing sources ● ● 15
  • 16. www.percona.com A lot about ftrace ● ftrace ● The way you fundamentally interact with ftrace is: ○ Write to files in /sys/kernel/debug/tracing/ ○ Read output from files in /sys/kernel/debug/tracing/ ● 16
  • 17. www.percona.com A lot about eBPF ● eBPF is a tiny language for a VM that can be executed inside Linux Kernel. eBPF instructions can be JIT-compiled into a native code. eBPF was originally conceived to power tools like tcpdump and implement programmable network packed dispatch and tracing. Since Linux 4.1, eBPF programs can be attached to kprobes and later - uprobes, enabling efficient programmable tracing ● Brendan Gregg explained it here: 17
  • 18. www.percona.com Few words about bpftrace ● ● 18
  • 19. www.percona.com A lot about perf ● If you are interested in details presented nicely... ● 19
  • 20. www.percona.com Adding uprobes to MySQL dynamically with perf ● The idea was to add dynamic probe to capture SQL queries ● This was done on Ubuntu 16.04 with recent Percona Server 5.7 ● First I had to find out with gdb where is the query (hint: dispatch_command has com_data parameter): (gdb) p com_data->com_query.query $4 = 0x7fb0dba8d021 "select 2" ● Then it’s just as easy as follows: openxs@ao756:~$ sudo perf probe -x /usr/sbin/mysqld 'dispatch_command com_data->com_query.query:string' openxs@ao756:~$ sudo perf record -e 'probe_mysqld:dispatch_command*' -aR ^C[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.676 MB perf.data (3 samples) ] openxs@ao756:~$ sudo perf script >/tmp/queries.txt openxs@ao756:~$ sudo perf probe --del dispatch_command 20
  • 21. www.percona.com Adding uprobes to MySQL dynamically with perf ● We have queries captured with probe added on previous slide: openxs@ao756:~$ cat /tmp/queries.txt mysqld 31340 [001] 3888.849079: probe_mysqld:dispatch_command: (be9250) query="select 100" mysqld 31340 [001] 3891.648739: probe_mysqld:dispatch_command: (be9250) query="select user, host from mysql.user" mysqld 31340 [001] 3895.890141: probe_mysqld:dispatch_command: (be9250) query="select 2" ● We can control output format, but basically we see binary, PID, CPU where uprobe was executed on, timestamp (milliseconds since start of record), probe and variables with format we specified ● 21
  • 22. www.percona.com perf - Success Stories ● perf (sometimes called perf_events or perf tools, originally Performance Counters for Linux, PCL) is a new performance analyzing tool for Linux, available from kernel version 2.6.31 (supported by RHEL6 since 2010) ● It is easier to use .and more popular recently for MySQL than older profilers ● Here is the list of some MySQL bugs by Mark Callaghan confirmed by perf: ○ Bug #69236 - "performance regressions for single-threaded workloads, part 2" - MySQL 5.6 is spending a lot more time in rec_get_offsets_func, trx_undo_report_row_operation, btr_cur_optimistic_insert. Same in 5.7.8, “Verified” ○ Bug #74325 - “updates to indexed column much slower in 5.7.5” - nice perf outputs there. It’s about innodb_fill_factor=100 (that leaves 1/16 free space since 5.7.8). ○ Bug #74280 - “covering secondary scans worse than PK scan at high concurrency” - the mutex contention that isn't visible in P_S output because the block rw-lock isn't instrumented. Verified regression since 5.7.5 vs 5.6.x. See also: Bug #74283 - “Non-covering secondary index scans degrade more in 5.7 than 5.6” ○ http://smalldatum.blogspot.com/2014/10/details-on-range-scan-performance.html - on two bugs above, perf allows to see the difference 22
  • 23. www.percona.com perf - Basic Usage ● Check my post, “perf Basics for MySQL Profiling”, for details and references, but basic minimal steps are: ○ Make sure perf-related packages are installed (perf with RPMs) for your kernel: sudo apt-get install linux-tools-generic ○ Make sure debug symbols are installed and software is built with -fno-omit-frame-pointer ○ Start data collection for some time using perf record: sudo perf record -a [-g] [-F99] [-p `pidof mysqld`] sleep 30 Run your problematic load against MySQL server ○ Samples are collected in `pwd`/perf.data by default ○ Process samples and display the profile using perf report: sudo perf report [-n] [-g] --stdio ● Alternatively, run in foreground and interrupt any time with Ctrl-C: [root@centos ~]# perf record -ag ^C ● Or run in background and send -SIGINT when done: [root@centos ~]# perf record -ag & [1] 2353 [root@centos ~]# kill -sigint 2353 ● Let’s see how it works alive… (demo). We’ll see perf top, perf record -g etc 23
  • 24. www.percona.com perf - Call Graphs Use -g option of perf record to get call graphs/backtraces with perf, then: openxs@ao756:~/dbs/maria10.1$ sudo perf report --stdio ... 31.02% mysqld mysqld [.] Item_func_mul::int_op() | --- Item_func_mul::int_op() | |--94.56%-- Item_func_hybrid_field_type::val_int() | Item_func_benchmark::val_int() | Item::send(Protocol*, String*) | Protocol::send_result_set_row(List<Item>*) | select_send::send_data(List<Item>&) | JOIN::exec_inner() | JOIN::exec() | mysql_select(THD*, Item***, TABLE_LIST*, ... | handle_select(THD*, LEX*, select_result*, unsigned long) | execute_sqlcom_select(THD*, TABLE_LIST*) | mysql_execute_command(THD*) | mysql_parse(THD*, char*, unsigned int, Parser_state*) | dispatch_command(enum_server_command, THD*, char*, ...) | do_command(THD*) ... 24
  • 25. www.percona.com Studying Hanging in “statistics” Case(s) ● See my blog post for details and full outputs: | |--71.70%-- srv_conc_enter_innodb(trx_t*) | | ha_innobase::index_read(...) | | handler::index_read_idx_map(...) | | handler::ha_index_read_idx_map(...) | | join_read_const(st_join_table*) | | join_read_const_table(THD*, ...) | | make_join_statistics(JOIN*, ...) | | JOIN::optimize_inner() | | JOIN::optimize() | | mysql_select(THD*, ...) ... ● We can see that time to do SELECT is mostly spent waiting to enter InnoDB queue while reading data via index (dive) to get statistics for the optimizer ● We can see where the time is spent by kernel and other processes (-a) 25
  • 26. www.percona.com Am I crazy doing these? ● Quite possible, maybe I just have too much free time :) ● Or maybe I do not know how to use Performance Schema properly ● But I am not alone... ● MariaDB developers are interested in adding dynamic probes with perf while working on RocksDB storage engine performance problems ● People use perf probes for tracing Oracle RDBMS! There is enough instrumentation there for almost everything, but still... ● Dynamic tracers are proven tools for instrumenting OS calls (probes for measuring I/O latency at microsecond precision, for example) ● Another topic, more complex but also more exciting, is dynamic tracing of RDBMS userspace. This topic is of growing interest with modern servers hosting large amounts of RAM and workloads that are often CPU-bound. There are no “waits”, but time is still spent somewhere! ● For open source RDBMS like MySQL there is no reason NOT to use dynamic probes while UDST are not on every other line of the code :) ● eBPF and bpftrace make it even easier and safer to do these in production 26
  • 27. www.percona.com Thank you! Questions and Answers? Please, report bugs at: https://bugs.mysql.com https://jira.mariadb.org https://jira.percona.com 27