当前位置:网站首页>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
边栏推荐
- Leetcode problem solving notes for slow ploughing of stupid cattle (dynamic update...)
- Use cloudflare to defend against DDoS for free
- Easycvr connects with Huawei IVS platform to query the foreign domain list interface definition and use sharing
- What is a region name? Can a territory name be used for trademark registration?
- Does the cloud game server only provide one player? Cloud game server defense capability
- Using nginscript as a file distribution service with permission
- Make standardized tools in the cloud native era to realize efficient cloud R & D workflow
- What is a private VLAN? Eight part essay with pictures and texts.
- Kubesphere upgrade & enable plug-ins after installation
- Easycvr's use of Huawei IVS query directory shared information list interface
猜你喜欢

Advanced BOM tool intelligent packaging function

Introduction to development model + test model

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

Leetcode969: pancake sorting (medium, dynamic programming)

Stm32g474 infrared receiving based on irtim peripherals

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

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

layer 3 switch

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

BIM model example
随机推荐
Live broadcast of the double 11 King bombing! Must buy good things introduction, come on~
Is a trademark domain name useful? How long does it take to register a domain name?
Global and Chinese dealox industry development status and demand trend forecast report 2022-2028
What are the general contents of the enterprise website construction scheme
SAP WM displays the standard report lx09 of TR item
What is a private VLAN? Eight part essay with pictures and texts.
Measurement model 𞓜 pre determined variable # time Fe
2021-11-10:o (1) time inserts, deletes and obtains random elements. Implement ra
Is the trademark registered domain name legal? How do trademarks register domain names?
How to set up a cloud desktop server? What are the advantages of cloud desktop?
What is raid? 2000 words can explain RAID 0, 1, 5 and 10 thoroughly, and collect!
[Tencent cloud double 12 audio and video communication special session] from 9 yuan for Q4 counter attack artifact, SMS and security (New) package!
Thorough and thorough analysis of factory method mode
Fulleventlogview does not display some event ID contents
Cloud game cannot select a server cloud game server fees
How does the education industry realize the TRTC interactive classroom apaas solution under the "double reduction policy"?
WordPress site quickly integrates Tencent's digital identity management and control platform CIAM to realize login authentication without development
Designing complex messaging systems using bridging patterns
Xmlmap port practice - X12 to CSV
Analysis report on market development trends and innovation strategies of China's iron and steel industry 2022-2028