当前位置:网站首页>Do you still understand the deadlock handling methods in MySQL performance testing and tuning?
Do you still understand the deadlock handling methods in MySQL performance testing and tuning?
2022-06-24 02:14:00 【Han Han becomes a god silently】
The following is from deadlock detection 、 Deadlock avoidance 、 Deadlock resolution 3 To explore how to MySQL Deadlock problem for performance tuning .
Deadlock detection
adopt SQL Statement to query lock table related information :
(1) Query table opening
SHOW OPEN TABLES WHERE IN_USE> 0
(2) Query the lock status list
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS
(3) Query lock waiting information , among blocking_lock_id Is the transaction that the current transaction is waiting for
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS
(4) Query deadlock log
SHOW ENGINE INNODB STATUS
This statement can only display the latest deadlock , Unable to fully capture all deadlock information in the system .
If you want to log all deadlocks , Need to open innodb_print_all_deadlocks Parameters , Log all deadlocks to errorlog in .
(5) Query lock wait time
SHOW STATUS LIKE '%lock%'
Deadlock avoidance
When a deadlock occurs , It is usually due to lengthy transactions in the program of the project , Or because the isolation level is not set properly .
We need to pay attention to the following points in the use of transactions :
(1) Try to keep things short , Commit the transaction immediately after making a series of associated update operations , To reduce the possibility of deadlock . Especially don't let the relevant MySQL Session suspends uncommitted transactions for a long time .
(2) A lower isolation level is recommended , Such as READ COMMITTED.
(3) Modify multiple tables in the same transaction , Or different rows in a table , Perform operations in the same order each time . In order to make the transaction form a clear lock operation queue and avoid deadlock .
Deadlock resolution
MySQL The database passed deadlock detection (innodb_deadlock_detect) And deadlock timeout (innodb_lock_wait_timeout) These two parameters are used for deadlock resolution .
Deadlock detection (innodb_deadlock_detect): stay MySQL 8.0 in , Added a new dynamic variable innodb_deadlock_detect, Used to control InnoDB Whether to perform deadlock detection .
The default value for this parameter is ON, That is, open deadlock detection . After opening InnoDB When locking, it will detect whether it will cause deadlock after locking , If you lock it , Just roll back the transaction with the lowest cost .
Deadlock timeout (innodb_lock_wait_timeout): This parameter can be used to handle undetectable deadlocks , Or avoid waiting for a long time for a long transaction .
For highly concurrent systems , When a large number of threads wait for the same lock , Deadlock detection may cause performance degradation .
here , If deadlock detection is disabled , Instead, it depends on parameters innodb_lock_wait_timeout It may be more efficient to release transactions that occupy lock resources for a long time .
in other words , When confirming that the deadlock detection function affects the performance of the system and disabling deadlock detection will not have a negative impact , You can try closing innodb_deadlock_detect Options .
in addition , If disabled InnoDB Deadlock detection , The parameters need to be adjusted in time innodb_lock_wait_timeout Value , To meet the actual needs .
The author of this article : Han Han becomes a god silently
Link to this article :https://cloud.tencent.com/developer/column/92828
边栏推荐
- Global and Chinese gallium industry market panoramic survey and investment strategy proposal report 2022-2028
- What if the cloud desktop fails to connect to the server? How to use cloud desktop?
- Grpc: implement grpc proxy
- SAP WM displays the standard report lx09 of TR item
- Tencent Conference - black screen analysis
- How to calculate the trademark registration fee? How much does it cost to register a trademark?
- How to build a cloud game server what needs to be considered to build a cloud game server
- Analysis of ESIM short text matching model
- Embedded hardware development tutorial -- Xilinx vivado HLS case (process description)
- 2021-11-10:o (1) time inserts, deletes and obtains random elements. Implement ra
猜你喜欢

2020 language and intelligent technology competition was launched, and Baidu provided the largest Chinese data set

How to fill in and register e-mail, and open mass mailing software for free

163 mailbox login portal display, enterprise mailbox computer version login portal

Introduction to development model + test model

Leetcode969: pancake sorting (medium, dynamic programming)

If there are enumerations in the entity object, the conversion of enumerations can be carried out with @jsonvalue and @enumvalue annotations

Review of AI hotspots this week: the Gan compression method consumes less than 1/9 of the computing power, and the open source generator turns your photos into hand drawn photos

BIM model example

Stm32g474 infrared receiving based on irtim peripherals

Advanced BOM tool intelligent packaging function
随机推荐
Looking at the future development direction of industrial Internet from the transformation of circulation links of large building materials
Leetcode969: pancake sorting (medium, dynamic programming)
[actual combat] how to realize people nearby through PostGIS
2021-11-10:o (1) time inserts, deletes and obtains random elements. Implement ra
[untitled]
Benchmarking Shopify? Similarities and differences between "two giants" of Chinese e-commerce SAAS and Weimeng
Advanced BOM tool intelligent packaging function
What is a port? The most complete and strongest port number in history, collection!
[expense center] demand & problem feedback week is coming! Feedback wins a good gift!
The new purchased machines with large customized images are slow to enter the system
A review of Nature Neuroscience: dynamic representation in networked nervous system
Cloud recommendation Vol.1: quick start to remote control under f-stack, go modules and 5g!
2020 language and intelligent technology competition was launched, and Baidu provided the largest Chinese data set
Analysis report on development trends and prospects of China's pyrolytic boron nitride (PBN) component industry 2022-2028
SAP mm UB type sto cannot be transferred to vendor consignment inventory?
Global and Chinese gallium industry market panoramic survey and investment strategy proposal report 2022-2028
How to set up a cloud desktop server? What are the advantages of cloud desktop?
How about Tencent cloud game server? Can the cloud game server play games
Network engineers must know the 10 technical points of IPv6. It is recommended to collect them!
LeetCode 931. Descent path min sum