Deep dive into Query Performance �
Peter Zaitsev,
Founder at Percona
10 June 2023
©2023 Percona | Confidential
© Percona
2
©2023 Percona | Confidential
Database is a Black Box
© Percona
3
©2023 Percona | Confidential
Meaning
© Percona
4
You can connect to the Database Service Point, Quickly
Run Queries you need to run
©2023 Percona | Confidential
Queries
5
Run them without errors
1
Run them with correct results
2
Run them with required response time
3
©2023 Percona | Confidential
Performance
Performance is about Response Time you get for your Queries
© Percona
6
©2023 Percona | Confidential
Great design is not only about Performance
© Percona
7
©2023 Percona | Confidential
Response Time - Database View
“I see database responds to queries in 5ms in average”
© Percona
8
©2023 Percona | Confidential
Response Time – Business View
All Users have outstanding performance experience with all their application interactions
© Percona
9
©2023 Percona | Confidential
Downtime
Very Bad Performance is indistinguishable from downtime
© Percona
10
©2023 Percona | Confidential
Forget averages
There once lived a man who tried to cross a river, in average one meter deep
© Percona
11
©2023 Percona | Confidential
© Percona
12
©2023 Percona | Confidential
Percentile
© Percona
13
99 percentile does not translate in 99% users having great performance
If every user interaction has 10 database queries
User in average has 10 interactions
Roughly 50% of session will have query with p99 response time
©2023 Percona | Confidential
Errors
© Percona
14
©2023 Percona | Confidential
Over Time
15
LOOK AT RESPONSE TIME TRENDS OVER TIME
MINOR SLOWDOWN OFTEN HAPPENS BEFORE POOR PERFORMANCE “DOWNTIME”
PERFORMANCE CAN BE WORSE AT CERTAIN TIMES – BACKUPS, BATCH JOBS, MAINTENANCE
©2023 Percona | Confidential
© Percona
16
©2023 Percona | Confidential
Database or Application ?
© Percona
17
©2023 Percona | Confidential
Response Time – Business View
All Users have outstanding performance experience with all their application interactions
© Percona
18
©2023 Percona | Confidential
Enhancing Query Meta Data
SQL Commenter project by Google
© Percona
19
©2023 Percona | Confidential
Query Meta Data Possibilities
20
Actual User/Tenant
Application/Functionality
Version Information (A/B Testing)
Responsible Engineer/Team
©2023 Percona | Confidential
Query
© Percona
21
©2023 Percona | Confidential
Schema and Database
© Percona
22
©2023 Percona | Confidential
Database view in Percona Monitoring and Management
© Percona
23
©2023 Percona | Confidential
Table/�Collection
© Percona
24
©2023 Percona | Confidential
Database User
© Percona
25
IDENTIFY SERVICE/APPLICATION
FIND HUMAN TROUBLE MAKERS WITH INTERACTIVE ACCESS
©2023 Percona | Confidential
© Percona
26
©2023 Percona | Confidential
Database Host
© Percona
27
Sharded environments often have multiple hosts handling the same traffic
Yet Problems often can be limited to some hosts
Data/Traffic Balance, configuration, invisible differences
©2023 Percona | Confidential
Database Instances
28
©2023 Percona | Confidential
App Server/�Web Server/�Service Instance
29
You may expect all instances of the same type causing same even load
It may not be the case
Code versions, configuration, load balancer behavior, security incidents
©2023 Percona | Confidential
Client Hosts
30
©2023 Percona | Confidential
Custom Tags
31
Assign custom tags to database instances if you can
Instance Type
Database Version
Configuration
©2023 Percona | Confidential
Query Plan
© Percona
32
©2023 Percona | Confidential
Where Response Time Comes From ?
33
Data Crunching/CPU
Waits on CPU Availability
Disk IO
Row Locks
Contention
Network
©2023 Percona | Confidential
Other Things to Consider
© Percona
34
©2023 Percona | Confidential
“Bad Queries” vs Victims
© Percona
35
©2023 Percona | Confidential
Do not forget currently running queries
© Percona
36
©2023 Percona | Confidential
Do not Ignore “Invisible”
© Percona
37
©2023 Percona | Confidential
Avoid Biased Sampling
38
“Let’s Look only on slow queries”
Focus on Outliers
Likely to ignore queries causing most load, typical impact
©2023 Percona | Confidential
© Percona
39
©2023 Percona | Confidential
Thank you, Let’s Connect!
https://www.linkedin.com/in/peterzaitsev/
https://twitter.com/PeterZaitsev