


[MySQL Database] Interpretation of Chapter 3: Server Performance Analysis (Part 2)
Let me sigh: DBA is really not covered
3.3.3 Usage performance analysis: limited
3.4 Diagnosis of simple and intermittent problems
If the system occasionally pauses, slows queries, or causes shadowing problems, try not to use trial and error methods to solve problems: the risk is high
3.4.1 Single query problem or service problem
Use SHOW GLOBAL STATUS
Higher frequency: 1s/time execution of this command to obtain data, the problem occurs through the counter
Use SHOW PROCESSLIST [Reference] Display which threads are running
Use query log
Enable slow query, set global long_query_time=0, and confirm that all connections adopt the new settings (you may need to reset all connections to take effect)
Pay attention to the logs during the period when the throughput suddenly drops. The query is only written to the slow query log during the completion phase
Good tools get twice the result with half the effort: tcpdump, pt-query-digest, Percona Server
Understand the problems found
Visualize data: gnuplot /R (drawing tool)
gnuplot:
Installation Some commands: Common skills Getting started tutorial 2 Gnuplot Data visualization
Recommendation: Use the first two methods first, which are low-cost and interactively collect data through simple shell scripts or repeatedly executed queries
3.4.2 Obtaining diagnostic data
Is intermittent Problem, try to collect as much data as possible (not just when the problem occurs)
Figure out: 1. There is a way to distinguish when the problem occurs: trigger; 2. Tools to collect diagnostic data
Diagnosis trigger
Error: A lot of diagnostic data is collected during the period when no problem occurs, which is a waste of time (this is not inconsistent with the previous one, read it carefully)
Missed detection: When the problem occurs No data was captured, an opportunity was missed. Before starting collection, confirm that the trigger can truly identify the problem.
Good triggers:
Find some that can work with normal Indicators for comparing thresholds
Choose an appropriate threshold: high enough (not triggered when normal), not too high (not missed when problems occur)
Recommended tool pt-stalk【 Reference】【2】Trigger, set to a certain condition to record and configure the frequency of threshold checks for variables to be monitored
What kind of data is collected
Execution time: Working time and waiting time
Collect all the data that can be collected within the required time period
The reason for the unknown problem: 1 , The server needs to do a lot of work, resulting in a lot of CPU consumption; 2. Waiting for resource release
Collect diagnostic data using different methods to confirm the reason:
1. Analysis report: Confirm whether there are too many Work, tool: tcpdump monitors TCP traffic mode opening and closing, slow query log
2. Wait analysis: confirm whether there is a large number of waits, GDB stack trace information, show processlist, show innodb status to observe threads and transaction status
Interpret the result data
Purpose: 1. Whether the problem really occurred; 2. Whether there is an obvious jump change
Tools:
oprofileUsing the performance counter (performance counter) provided at the CPU hardware level, through counting sampling, it helps us find the "culprit" that occupies the CPU from the process, function, and code levels. Example [Reference]
The opreport command is a method to view the CPU usage from the process and function levels respectively
samples | %| ----------------------------------------------------- 镜像内发生的采样次数 采样次数所占总采样次数的百分比 镜像名称
The opannotate command can display the statistical information of the CPU occupied at the code level
GDB:In Linux application development, the most commonly used debugger is gdb (the object of debugging is an executable file). It can set breakpoints in the program, view variable values, and track the execution process of the program step by step. (data, source code), view memory and stack information. Using these functions of the debugger can easily find non-grammatical errors in the program. [Reference] [Reference] Syntax and examples
3.4.3 A diagnostic case
Intermittent performance problem, with knowledge of MySQL, innodb, GNU/Linux
Clear: 1. What is the problem, describe it clearly; 2. What actions have been taken to solve the problem?
Start: 1. Understand the behavior of the server; 2. Sort out the status parameters of the server and configure the software and hardware environment (pt-summary pt-mysql-summary)
Don’t be distracted by various situations that are too off-topic. Write the questions on a slip of paper. Check whether each crossed out
is a cause or a result? ? ?
Possible reasons why resources become inefficient:
1. Resources are overused and the balance is insufficient; 2. Resources are not correctly matched; 3. Resources Damage or failure
3.5 Other analysis tools
USER_STATISTICS: Some tables measure and audit database activities
strace: Investigate system calls, use Actual time, unpredictability, overhead, oprofileUse spent CPU cycles
Summary:
The most effective way to define performance is response time
If it cannot be measured, it cannot be effectively optimized. Performance optimization work needs to be based on high-quality, comprehensive and complete response time measurement
The best starting point for measurement is an application. Even if the problem lies in the underlying database, it is easier to find the problem with good measurements
Most systems cannot measure completely, and measurements sometimes have wrong results. Find ways to bypass some limitations and be aware of the flaws and uncertainties of the method.
Complete measurements will generate a large amount of data that needs to be analyzed, so you need to use a profiler ( Best tool)
Profiling report: summarizes information, glosses over and throws away a lot of details, won’t tell you what’s missing, can’t be completely relied on
Two time-consuming operations: work or waiting. Almost the profiler can only measure the time spent on work, so waiting for sharing is sometimes a useful supplement, especially when the CPU utilization is low but the work has never been completed.
Optimization and improvement are two different things. When the cost of continued improvement exceeds the benefits, optimization should be stopped
Pay attention to your directness, ideas, and decisions as much as possible Based on data
in a words:First clarify the problem, choose the appropriate technology, make good use of tools, be careful enough, have clear logic and stick to it, don’t put the cause and effect Confused, do not make changes to the system casually before determining the problem
Related articles:
[MySQL Database] Chapter 2 Interpretation: MySQL Benchmark Test
[MySQL Database] Interpretation of Chapter 3: Server Performance Analysis (Part 1)
The above is the detailed content of [MySQL Database] Interpretation of Chapter 3: Server Performance Analysis (Part 2). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
