SlideShare a Scribd company logo
Linux /proc filesystem for
MySQL DBAs
Sampling /proc content for troubleshooting
Valerii Kravchuk, Principal Support Engineer, MariaDB
vkravchuk@gmail.com
1
www.percona.com
Who am I and What Do I Do?
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 MariaDB and
MySQL (including some HowTos, not just bugs marketing)
● https://www.facebook.com/valerii.kravchuk - my Facebook page
● http://bugs.mysql.com - used to be my personal playground
● @mysqlbugs #bugoftheday - links to interesting MySQL bugs, few per week
● MySQL Community Contributor of the Year 2019
● I speak about MySQL and MariaDB in public. Some slides from previous talks
are here and there…
● “I solve problems”, “I drink and I know things”
2
www.percona.com
Disclaimers
● Since September, 2012 I act as an Independent Consultant
providing services to different companies
● All views, ideas, conclusions, statements and approaches
in my presentations and blog posts are mine and may not
be shared by any of my previous, current and future
employees, customers and partners
● All examples are either based on public information or are
truly fictional and has nothing to do with any real persons or
companies. Any similarities are pure coincidence :)
● The information presented is true to the best of my
knowledge
3
www.percona.com
Sources of information on mysqld in production
● Extended slow query log
● show [global] status; show engine innodb statusG
● InnoDB-related tables and different plugins in the
INFORMATION_SCHEMA
● userstat - per user, client, table or index
● show profiles;
● PERFORMANCE_SCHEMA
● OS-level tracing and profiling tools:
○ /proc filesystem and related utilities
○ ftrace
○ Profilers, simple like pt-pmp or real like perf
○ eBPF and related tools, bpftrace
● tcpdump analysis
4
www.percona.com
What is this session about?
● It’s about troubleshooting tools and approaches based on
/proc sampling (like 0x.tools by Tanel Poder or ad hoc
scripts), that allow to monitor individual thread level activity
in MySQL server on Linux, like thread states, currently
executing system calls and kernel wait locations…
● … and few other useful /proc files and features
○ Why not about Performance Schema?
○ Why not about perf?
○ Why not about eBPF, bcc tools and bpftrace?
● Performance impact of the off-CPU profiling, availability on
production servers (still not running kernels 5.x.y)
5
www.percona.com
Linux /proc filesystem basics
● The proc filesystem is a pseudo-filesystem which provides an
interface to kernel data structures. It is commonly mounted at /proc:
openxs@ao756:~$ mount | grep '/proc'
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
openxs@ao756:~$ sudo ls -F /proc/30580
attr/ cpuset limits net/ projid_map stat
autogroup cwd@ loginuid ns/ root@ statm
auxv environ map_files/ numa_maps sched status
cgroup exe@ maps oom_adj schedstat syscall
clear_refs fd/ mem oom_score sessionid task/
cmdline fdinfo/ mountinfo oom_score_adj setgroups timers
comm gid_map mounts pagemap smaps uid_map
coredump_filter io mountstats personality stack wchan
● See also:
○ man 5 proc
○ My blog post about /proc basics
6
www.percona.com
How to identify threads of the mysqld process?
● MySQL server is a multi-threaded process:
"The MySQL Server (mysqld) executes as a single OS process, with
multiple threads executing concurrent activities. MySQL does not have its
own thread implementation, but relies on the thread implementation of the
underlying OS."
● In MySQL 5.7+ use performance_schema.threads:
mysql> select thread_id, thread_os_id, name from
performance_schema.threads where type = 'BACKGROUND';
+-----------+--------------+----------------------------------------+
| thread_id | thread_os_id | name |
+-----------+--------------+----------------------------------------+
| 1 | 30580 | thread/sql/main |
| 2 | 30581 | thread/sql/thread_timer_notifier |
| 3 | 30582 | thread/innodb/io_ibuf_thread
...
| 13 | 30592 | thread/innodb/page_cleaner_thread |
| 14 | 30593 | thread/innodb/buf_lru_manager_thread |
...
● See my blog post for more details
7
www.percona.com
Poor man’s threads monitoring with shell scripts
● Consider this simple loop to check something for every thread of MySQL:
openxs@ao756:~$ for dir in `ls /proc/$(pidof mysqld)/task`
> do
> echo -n $dir': '
> 2>/dev/null sudo strings /proc/$dir/wchan
> done
...
2393: 2394: futex_wait_queue_me
2488: futex_wait_queue_me
30580: poll_schedule_timeout
30581: do_sigtimedwait
...
30591: read_events
30592: futex_wait_queue_me
30593: hrtimer_nanosleep
...
31000: jbd2_log_wait_commit
...
● See my blog post for more details
8
www.percona.com
Something more advanced? 0x.tools!
● 0x.tools. - a useful set of programs to access, summarize and record /proc
details created and recently shared by famous Tanel Poder
● Get them from GitHub:
git clone https://github.com/tanelpoder/0xtools
cd 0xtools/
make
sudo make install
● You need python (2!), gcc and make
● xcapture - low-overhead thread state sampler based on reading /proc files.
Can run continuously and save captured data into .csv files
● psn - shows current top thread activity by sampling /proc files
● schedlat - shows CPU scheduling latency for the given PID as a % of runtime
● run_xcapture.sh - a simple “daemon” script for keeping xcapture running
● run_xcpu.sh - low-frequency continuous stack sampling for threads on CPU
(using perf)
● Check my blog post for more details.
9
www.percona.com
0x.tools: process snapper (psn) in action
● Let’s check what we can get from psn while sysbench load is running:
openxs@ao756:~/git/0xtools$ sudo psn -p `pidof mysqld` -G kstack
Linux Process Snapper v0.18 by Tanel Poder [https://0x.tools]
Sampling /proc/stat, stack for 5 seconds... finished.
...
samples | avg_threads | comm | state | kstack
...
101 | 1.01 | (mysqld) | Disk (Uninterruptible) |
entry_SYSCALL_64_fastpath()->SyS_fsync()->do_fsync()->vfs_fsync_range()->ext4_
sync_file()->jbd2_complete_transaction()->jbd2_log_wait_commit()
...
15 | 0.15 | (mysqld) | Running (ON CPU) |
int_ret_from_sys_call()->syscall_return_slowpath()->exit_to_usermode_loop()
11 | 0.11 | (mysqld) | Disk (Uninterruptible) |
entry_SYSCALL_64_fastpath()->SyS_fsync()->do_fsync()->vfs_fsync_range()->ext4_
sync_file()->blkdev_issue_flush()->submit_bio_wait()
...
● Check my blog post for more details.
10
www.percona.com
Generic thread states on Linux
● You may be wondering why we care about kernel stacks, wait
channels etc, how this may help?
● I’ll use a chart of generic thread states presented by Brendan Gregg
here:
11
www.percona.com
Classification of performance issues
● As Brendan Gregg pointed out, performance issues can be categorized into
one of two types:
● On-CPU: where threads are spending time running on CPU
● Off-CPU: where time is spent waiting while blocked on I/O, locks, timers,
paging/swapping, etc.
● Different approaches to the analysis are used, depending on the type:
a. CPU Sampling - checking stack traces on all CPUs at a certain rate and
summarizing to understand where CPU cycles are mostly spent. See perf -F99 ...
b. Application Tracing - application functions are instrumented to collect timestamps
when they begin and end, so that the time spent in functions can be calculated..
This is what Performance Schema provides for MySQL server.
c. Off-CPU Tracing - only the kernel functions that switch the thread off-CPU are
traced, along with timestamps and user-land stack traces. This is possible (but
hard) with perf tracing and is usually done with eBPF-based bcc tools and
bpftrace that can summarize data in kernel space on the fly.
d. Off-CPU Sampling - sampling to capture blocked stack traces from threads that
are not running on-CPU. This is what we can do by checking /proc content once in
a while, with ad hoc scripts or 0x.tools: xcapture or psn.
12
www.percona.com
Brendan Gregg on Off-CPU sampling
● As Brendan Gregg pointed out, before eBPF made the
overhead of Off-CPU tracing acceptable for some cases:
“At one point I wrote a simple wall-time kernel-stack profiler called
proc-profiler.pl, which sampled /proc/PID/stack for a given PID. It worked
well enough. I'm not the first to hack up such a wall-time profiler either,
see poormansprofiler and Tanel Poder's quick'n'dirty troubleshooting.”
● This is exactly what I am suggesting to do here, and what
xcapture and psn tools allow to do easily, per thread.
13
Performance impact of /proc sampling vs bcc tools
vs perf for off-CPU analysis
● Consider MySQL 8.0.22 started with --no-defaults running sysbench (I/O
bound) test on Q8300 @ 2.50GHz Fedora 31 box:
[openxs@fc31 ~]$ sysbench oltp_read_write --db-driver=mysql --tables=5
--table-size=100000 --mysql-user=root ... --threads=32 --time=80
--report-interval=10 run
● I’ve executed it without tracing or sampling, and with the following
(compatible?) off-CPU data collections working for 60 seconds:
[openxs@fc31 ~]$ sudo psn -d 60 --sample-hz 99 -p `pidof mysqld` -G kstack
-o /tmp/psnstacks
[openxs@fc31 ~]$ sudo xcapture -c kstack -o /tmp
[openxs@fc31 ~]$ sudo /usr/share/bcc/tools/offcputime -K -f 60 -p `pidof
mysqld` > /tmp/stacks.txt
WARNING: 5 stack traces lost and could not be displayed.
[openxs@fc31 tmp]$ sudo perf record -g -F 1 -a -- sleep 60
[ perf record: Captured and wrote 1.254 MB perf.data (83 samples) ]
● QPS: 1720 | 1676 (97%) | 1727 (100%) | 1614 (93%) | 1490 (86%)
● More realistic benchmarks and detailed blog post are yet to come
14
What we can get from stacks: Flame Graphs
● http://www.brendangregg.com/flamegraphs.html
● Flame graphs are a visualization (as .svg file to be checked in
browser) of profiled software, allowing the most frequent code-paths to
be identified quickly and accurately.
● The x-axis shows the stack profile population, sorted alphabetically (it
is not the passage of time), and the y-axis shows stack depth. Each
rectangle represents a stack frame. The wider a frame is, the more
often it was present in the stacks.
● Off-CPU Flame Graphs ← tracing file I/O, block I/O or scheduler
● https://github.com/brendangregg/FlameGraph + perf + ... or bcc
tools like offcputime.py
● Can we we try to build off-CPU flame graph from samples of kernel
stacks?
15
Flame Graph based on off-CPU sampling
● Created based on these steps (while oltp_read_write.lua was running):
openxs@ao756:~$ sudo psn -d 60 -G kstack | grep -v Running | awk -F| '{
print $3, $5, $1 }' | sed 's/->/;/g' | grep '^.(' | sed 's/(//g' | sed
's/)//g' | awk '{ print $1";"$2, $3 }' > /tmp/psnstacks.txt
openxs@ao756:~$ git/FlameGraph/flamegraph.pl --color=io --title="Off-CPU
Time Flame Grapg based on proc sampling" --countname=hits <
/tmp/psnstacks.txt > ~/Documents/psn1.svg
16
www.percona.com
Problems of /proc sampling:
● root/sudo access is required for many interesting files
● Storing and processing of the information collected:
○ Data can be presented as .csv files and loaded into the
database
○ Kernel stacks can be processed for presentation as
off-CPU flame graphs
○ Other options?
● Writing ad hoc shell scripts (0x.tools is one of answers)
● How to get both on-CPU and off-CPU sampling in a
unified low impact manner? Any options other than bcc
tools or bpftrace?
17
www.percona.com
Q & A
● Thank you!
● Please, report bugs to https://bugs.mysql.com!
18
Ad

More Related Content

What's hot (20)

Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1
Valerii Kravchuk
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
Valerii Kravchuk
 
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Valerii Kravchuk
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)
Valeriy 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
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50mins
Valeriy Kravchuk
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
How to use KASAN to debug memory corruption in OpenStack environment- (2)
How to use KASAN to debug memory corruption in OpenStack environment- (2)How to use KASAN to debug memory corruption in OpenStack environment- (2)
How to use KASAN to debug memory corruption in OpenStack environment- (2)
Gavin Guo
 
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Gavin Guo
 
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
Valeriy Kravchuk
 
Writing Nginx Modules
Writing Nginx ModulesWriting Nginx Modules
Writing Nginx Modules
Marian Marinov
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQL
Henning Jacobs
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsSoftware Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and Flamegraphs
Isuru Perera
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Gavin Guo
 
2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins general
Roland Bouman
 
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
 
1. MySql plugins
1. MySql plugins1. MySql plugins
1. MySql plugins
Roland Bouman
 
Kernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Kernel Recipes 2019 - RCU in 2019 - Joel FernandesKernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Kernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Anne Nicolas
 
Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010
Roland Bouman
 
Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1Tracing and profiling my sql (percona live europe 2019) draft_1
Tracing and profiling my sql (percona live europe 2019) draft_1
Valerii Kravchuk
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
Valerii Kravchuk
 
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Valerii Kravchuk
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)
Valeriy 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
 
Mysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50minsMysql 56-experiences-bugs-solutions-50mins
Mysql 56-experiences-bugs-solutions-50mins
Valeriy Kravchuk
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 
How to use KASAN to debug memory corruption in OpenStack environment- (2)
How to use KASAN to debug memory corruption in OpenStack environment- (2)How to use KASAN to debug memory corruption in OpenStack environment- (2)
How to use KASAN to debug memory corruption in OpenStack environment- (2)
Gavin Guo
 
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Migrating KSM page causes the VM lock up as the KSM page merging list is too ...
Gavin Guo
 
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
Valeriy Kravchuk
 
GOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQLGOTO 2013: Why Zalando trusts in PostgreSQL
GOTO 2013: Why Zalando trusts in PostgreSQL
Henning Jacobs
 
Software Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and FlamegraphsSoftware Profiling: Java Performance, Profiling and Flamegraphs
Software Profiling: Java Performance, Profiling and Flamegraphs
Isuru Perera
 
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Spectre(v1%2 fv2%2fv4) v.s. meltdown(v3)
Gavin Guo
 
2. writing MySql plugins general
2. writing MySql plugins   general2. writing MySql plugins   general
2. writing MySql plugins general
Roland Bouman
 
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
 
Kernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Kernel Recipes 2019 - RCU in 2019 - Joel FernandesKernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Kernel Recipes 2019 - RCU in 2019 - Joel Fernandes
Anne Nicolas
 
Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010Optimizing mysql stored routines uc2010
Optimizing mysql stored routines uc2010
Roland Bouman
 

Similar to Linux /proc filesystem for MySQL DBAs - FOSDEM 2021 (20)

PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
FromDual GmbH
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
FromDual GmbH
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
Creating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just WorksCreating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
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
Frederic Descamps
 
Summer of Fuzz: macOS
Summer of Fuzz: macOSSummer of Fuzz: macOS
Summer of Fuzz: macOS
Jeremy Brown
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Lenz Grimmer
 
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
Frederic Descamps
 
Testing Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with SherlockTesting Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with Sherlock
ScyllaDB
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
Brendan Gregg
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
BITS
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
Sysdig
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
Dave Stokes
 
Troubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer PerspectiveTroubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer Perspective
Marcelo Altmann
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
Gábor Nyers
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 Performance
MYXPLAIN
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
Sveta Smirnova
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
FromDual GmbH
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
FromDual GmbH
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
Creating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just WorksCreating a Benchmarking Infrastructure That Just Works
Creating a Benchmarking Infrastructure That Just Works
Tim Callaghan
 
Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2Oracle to Postgres Migration - part 2
Oracle to Postgres Migration - part 2
PgTraining
 
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
Frederic Descamps
 
Summer of Fuzz: macOS
Summer of Fuzz: macOSSummer of Fuzz: macOS
Summer of Fuzz: macOS
Jeremy Brown
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Making MySQL Administration a Breeze - A look into a MySQL DBA's toolchest
Lenz Grimmer
 
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
Frederic Descamps
 
Testing Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with SherlockTesting Persistent Storage Performance in Kubernetes with Sherlock
Testing Persistent Storage Performance in Kubernetes with Sherlock
ScyllaDB
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
Brendan Gregg
 
BITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and InstallationBITS: Introduction to MySQL - Introduction and Installation
BITS: Introduction to MySQL - Introduction and Installation
BITS
 
Designing Tracing Tools
Designing Tracing ToolsDesigning Tracing Tools
Designing Tracing Tools
Sysdig
 
MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015MySQL Utilities -- PyTexas 2015
MySQL Utilities -- PyTexas 2015
Dave Stokes
 
Troubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer PerspectiveTroubleshooting MySQL from a MySQL Developer Perspective
Troubleshooting MySQL from a MySQL Developer Perspective
Marcelo Altmann
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
Gábor Nyers
 
Docker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12xDocker and-containers-for-development-and-deployment-scale12x
Docker and-containers-for-development-and-deployment-scale12x
rkr10
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 Performance
MYXPLAIN
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
Sveta Smirnova
 
Ad

Recently uploaded (20)

Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Cryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptxCryptocurrency Exchange Script like Binance.pptx
Cryptocurrency Exchange Script like Binance.pptx
riyageorge2024
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Odoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education ProcessOdoo ERP for Education Management to Streamline Your Education Process
Odoo ERP for Education Management to Streamline Your Education Process
iVenture Team LLP
 
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
🌱 Green Grafana 🌱 Essentials_ Data, Visualizations and Plugins.pdf
Imma Valls Bernaus
 
Full Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest VersionFull Cracked Resolume Arena Latest Version
Full Cracked Resolume Arena Latest Version
jonesmichealj2
 
Innovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at allInnovative Approaches to Software Dev no good at all
Innovative Approaches to Software Dev no good at all
ayeshakanwal75
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
PRTG Network Monitor Crack Latest Version & Serial Key 2025 [100% Working]
saimabibi60507
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game DevelopmentBest Practices for Collaborating with 3D Artists in Mobile Game Development
Best Practices for Collaborating with 3D Artists in Mobile Game Development
Juego Studios
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Creating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdfCreating Automated Tests with AI - Cory House - Applitools.pdf
Creating Automated Tests with AI - Cory House - Applitools.pdf
Applitools
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Ad

Linux /proc filesystem for MySQL DBAs - FOSDEM 2021

  • 1. Linux /proc filesystem for MySQL DBAs Sampling /proc content for troubleshooting Valerii Kravchuk, Principal Support Engineer, MariaDB [email protected] 1
  • 2. www.percona.com Who am I and What Do I Do? 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 MariaDB and MySQL (including some HowTos, not just bugs marketing) ● https://www.facebook.com/valerii.kravchuk - my Facebook page ● http://bugs.mysql.com - used to be my personal playground ● @mysqlbugs #bugoftheday - links to interesting MySQL bugs, few per week ● MySQL Community Contributor of the Year 2019 ● I speak about MySQL and MariaDB in public. Some slides from previous talks are here and there… ● “I solve problems”, “I drink and I know things” 2
  • 3. www.percona.com Disclaimers ● Since September, 2012 I act as an Independent Consultant providing services to different companies ● All views, ideas, conclusions, statements and approaches in my presentations and blog posts are mine and may not be shared by any of my previous, current and future employees, customers and partners ● All examples are either based on public information or are truly fictional and has nothing to do with any real persons or companies. Any similarities are pure coincidence :) ● The information presented is true to the best of my knowledge 3
  • 4. www.percona.com Sources of information on mysqld in production ● Extended slow query log ● show [global] status; show engine innodb statusG ● InnoDB-related tables and different plugins in the INFORMATION_SCHEMA ● userstat - per user, client, table or index ● show profiles; ● PERFORMANCE_SCHEMA ● OS-level tracing and profiling tools: ○ /proc filesystem and related utilities ○ ftrace ○ Profilers, simple like pt-pmp or real like perf ○ eBPF and related tools, bpftrace ● tcpdump analysis 4
  • 5. www.percona.com What is this session about? ● It’s about troubleshooting tools and approaches based on /proc sampling (like 0x.tools by Tanel Poder or ad hoc scripts), that allow to monitor individual thread level activity in MySQL server on Linux, like thread states, currently executing system calls and kernel wait locations… ● … and few other useful /proc files and features ○ Why not about Performance Schema? ○ Why not about perf? ○ Why not about eBPF, bcc tools and bpftrace? ● Performance impact of the off-CPU profiling, availability on production servers (still not running kernels 5.x.y) 5
  • 6. www.percona.com Linux /proc filesystem basics ● The proc filesystem is a pseudo-filesystem which provides an interface to kernel data structures. It is commonly mounted at /proc: openxs@ao756:~$ mount | grep '/proc' proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) openxs@ao756:~$ sudo ls -F /proc/30580 attr/ cpuset limits net/ projid_map stat autogroup cwd@ loginuid ns/ root@ statm auxv environ map_files/ numa_maps sched status cgroup exe@ maps oom_adj schedstat syscall clear_refs fd/ mem oom_score sessionid task/ cmdline fdinfo/ mountinfo oom_score_adj setgroups timers comm gid_map mounts pagemap smaps uid_map coredump_filter io mountstats personality stack wchan ● See also: ○ man 5 proc ○ My blog post about /proc basics 6
  • 7. www.percona.com How to identify threads of the mysqld process? ● MySQL server is a multi-threaded process: "The MySQL Server (mysqld) executes as a single OS process, with multiple threads executing concurrent activities. MySQL does not have its own thread implementation, but relies on the thread implementation of the underlying OS." ● In MySQL 5.7+ use performance_schema.threads: mysql> select thread_id, thread_os_id, name from performance_schema.threads where type = 'BACKGROUND'; +-----------+--------------+----------------------------------------+ | thread_id | thread_os_id | name | +-----------+--------------+----------------------------------------+ | 1 | 30580 | thread/sql/main | | 2 | 30581 | thread/sql/thread_timer_notifier | | 3 | 30582 | thread/innodb/io_ibuf_thread ... | 13 | 30592 | thread/innodb/page_cleaner_thread | | 14 | 30593 | thread/innodb/buf_lru_manager_thread | ... ● See my blog post for more details 7
  • 8. www.percona.com Poor man’s threads monitoring with shell scripts ● Consider this simple loop to check something for every thread of MySQL: openxs@ao756:~$ for dir in `ls /proc/$(pidof mysqld)/task` > do > echo -n $dir': ' > 2>/dev/null sudo strings /proc/$dir/wchan > done ... 2393: 2394: futex_wait_queue_me 2488: futex_wait_queue_me 30580: poll_schedule_timeout 30581: do_sigtimedwait ... 30591: read_events 30592: futex_wait_queue_me 30593: hrtimer_nanosleep ... 31000: jbd2_log_wait_commit ... ● See my blog post for more details 8
  • 9. www.percona.com Something more advanced? 0x.tools! ● 0x.tools. - a useful set of programs to access, summarize and record /proc details created and recently shared by famous Tanel Poder ● Get them from GitHub: git clone https://github.com/tanelpoder/0xtools cd 0xtools/ make sudo make install ● You need python (2!), gcc and make ● xcapture - low-overhead thread state sampler based on reading /proc files. Can run continuously and save captured data into .csv files ● psn - shows current top thread activity by sampling /proc files ● schedlat - shows CPU scheduling latency for the given PID as a % of runtime ● run_xcapture.sh - a simple “daemon” script for keeping xcapture running ● run_xcpu.sh - low-frequency continuous stack sampling for threads on CPU (using perf) ● Check my blog post for more details. 9
  • 10. www.percona.com 0x.tools: process snapper (psn) in action ● Let’s check what we can get from psn while sysbench load is running: openxs@ao756:~/git/0xtools$ sudo psn -p `pidof mysqld` -G kstack Linux Process Snapper v0.18 by Tanel Poder [https://0x.tools] Sampling /proc/stat, stack for 5 seconds... finished. ... samples | avg_threads | comm | state | kstack ... 101 | 1.01 | (mysqld) | Disk (Uninterruptible) | entry_SYSCALL_64_fastpath()->SyS_fsync()->do_fsync()->vfs_fsync_range()->ext4_ sync_file()->jbd2_complete_transaction()->jbd2_log_wait_commit() ... 15 | 0.15 | (mysqld) | Running (ON CPU) | int_ret_from_sys_call()->syscall_return_slowpath()->exit_to_usermode_loop() 11 | 0.11 | (mysqld) | Disk (Uninterruptible) | entry_SYSCALL_64_fastpath()->SyS_fsync()->do_fsync()->vfs_fsync_range()->ext4_ sync_file()->blkdev_issue_flush()->submit_bio_wait() ... ● Check my blog post for more details. 10
  • 11. www.percona.com Generic thread states on Linux ● You may be wondering why we care about kernel stacks, wait channels etc, how this may help? ● I’ll use a chart of generic thread states presented by Brendan Gregg here: 11
  • 12. www.percona.com Classification of performance issues ● As Brendan Gregg pointed out, performance issues can be categorized into one of two types: ● On-CPU: where threads are spending time running on CPU ● Off-CPU: where time is spent waiting while blocked on I/O, locks, timers, paging/swapping, etc. ● Different approaches to the analysis are used, depending on the type: a. CPU Sampling - checking stack traces on all CPUs at a certain rate and summarizing to understand where CPU cycles are mostly spent. See perf -F99 ... b. Application Tracing - application functions are instrumented to collect timestamps when they begin and end, so that the time spent in functions can be calculated.. This is what Performance Schema provides for MySQL server. c. Off-CPU Tracing - only the kernel functions that switch the thread off-CPU are traced, along with timestamps and user-land stack traces. This is possible (but hard) with perf tracing and is usually done with eBPF-based bcc tools and bpftrace that can summarize data in kernel space on the fly. d. Off-CPU Sampling - sampling to capture blocked stack traces from threads that are not running on-CPU. This is what we can do by checking /proc content once in a while, with ad hoc scripts or 0x.tools: xcapture or psn. 12
  • 13. www.percona.com Brendan Gregg on Off-CPU sampling ● As Brendan Gregg pointed out, before eBPF made the overhead of Off-CPU tracing acceptable for some cases: “At one point I wrote a simple wall-time kernel-stack profiler called proc-profiler.pl, which sampled /proc/PID/stack for a given PID. It worked well enough. I'm not the first to hack up such a wall-time profiler either, see poormansprofiler and Tanel Poder's quick'n'dirty troubleshooting.” ● This is exactly what I am suggesting to do here, and what xcapture and psn tools allow to do easily, per thread. 13
  • 14. Performance impact of /proc sampling vs bcc tools vs perf for off-CPU analysis ● Consider MySQL 8.0.22 started with --no-defaults running sysbench (I/O bound) test on Q8300 @ 2.50GHz Fedora 31 box: [openxs@fc31 ~]$ sysbench oltp_read_write --db-driver=mysql --tables=5 --table-size=100000 --mysql-user=root ... --threads=32 --time=80 --report-interval=10 run ● I’ve executed it without tracing or sampling, and with the following (compatible?) off-CPU data collections working for 60 seconds: [openxs@fc31 ~]$ sudo psn -d 60 --sample-hz 99 -p `pidof mysqld` -G kstack -o /tmp/psnstacks [openxs@fc31 ~]$ sudo xcapture -c kstack -o /tmp [openxs@fc31 ~]$ sudo /usr/share/bcc/tools/offcputime -K -f 60 -p `pidof mysqld` > /tmp/stacks.txt WARNING: 5 stack traces lost and could not be displayed. [openxs@fc31 tmp]$ sudo perf record -g -F 1 -a -- sleep 60 [ perf record: Captured and wrote 1.254 MB perf.data (83 samples) ] ● QPS: 1720 | 1676 (97%) | 1727 (100%) | 1614 (93%) | 1490 (86%) ● More realistic benchmarks and detailed blog post are yet to come 14
  • 15. What we can get from stacks: Flame Graphs ● http://www.brendangregg.com/flamegraphs.html ● Flame graphs are a visualization (as .svg file to be checked in browser) of profiled software, allowing the most frequent code-paths to be identified quickly and accurately. ● The x-axis shows the stack profile population, sorted alphabetically (it is not the passage of time), and the y-axis shows stack depth. Each rectangle represents a stack frame. The wider a frame is, the more often it was present in the stacks. ● Off-CPU Flame Graphs ← tracing file I/O, block I/O or scheduler ● https://github.com/brendangregg/FlameGraph + perf + ... or bcc tools like offcputime.py ● Can we we try to build off-CPU flame graph from samples of kernel stacks? 15
  • 16. Flame Graph based on off-CPU sampling ● Created based on these steps (while oltp_read_write.lua was running): openxs@ao756:~$ sudo psn -d 60 -G kstack | grep -v Running | awk -F| '{ print $3, $5, $1 }' | sed 's/->/;/g' | grep '^.(' | sed 's/(//g' | sed 's/)//g' | awk '{ print $1";"$2, $3 }' > /tmp/psnstacks.txt openxs@ao756:~$ git/FlameGraph/flamegraph.pl --color=io --title="Off-CPU Time Flame Grapg based on proc sampling" --countname=hits < /tmp/psnstacks.txt > ~/Documents/psn1.svg 16
  • 17. www.percona.com Problems of /proc sampling: ● root/sudo access is required for many interesting files ● Storing and processing of the information collected: ○ Data can be presented as .csv files and loaded into the database ○ Kernel stacks can be processed for presentation as off-CPU flame graphs ○ Other options? ● Writing ad hoc shell scripts (0x.tools is one of answers) ● How to get both on-CPU and off-CPU sampling in a unified low impact manner? Any options other than bcc tools or bpftrace? 17
  • 18. www.percona.com Q & A ● Thank you! ● Please, report bugs to https://bugs.mysql.com! 18