SlideShare a Scribd company logo
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Martin Klier
Senior DBA
Klug GmbH integrierte Systeme
San Francisco, Sept 30th, 2012
Resolving Child Cursor Issues
Resulting In Mutex Waits
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Introduction
•Oracle Parsing, Child Cursors
•Mutexes, Waits and Reasons
•Issues, Quick Fixes and Solutions
•Summary, Acknowledgements, Q&A session
Agenda
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Martin Klier (martin.klier@klug-is.de)
•Senior DBA for at
•Focus on Performance, Tuning and High Availability
•Linux since 1997, Oracle since 2003
•Weblog: http://www.usn-it.de
Speaker
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Klug GmbH integrierte Systeme (http://www.klug-is.de)
92552 Teunz, GERMANY
•Specialist leading in complex intralogistical solutions
•Planning and design of automated intralogistics systems,
focus on software and system control / PLC
•>300 successful major projects in Europe, America, Asia
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
iWACS®
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Introduction
•Oracle Parsing, Child Cursors
•Mutexes, Waits and Reasons
•Issues, Quick Fixes and Solutions
•Summary, Acknowledgements, Q&A session
Agenda
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Parsing
Optimization
(Hard Parse)
Execution
Soft Parse
Shared Pool
0 or 1 child
SQL
Cursor Sharing
Insert cursor
+ single child
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Parsing
Execution
Shared Pool
1 or n children
SQL
Adaptive
Cursor Sharing I
Cardinality
Feedback
Soft Parse
Bind Mismatch
or ~62
other Reasons
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
64 Reasons for not re-using an existing child cursor
•Optimizer mode change (ALL_ROWS, FIRST_ROWS)
•NLS- and user identity trouble,
•Outline mismatch, Cardinality feedback (wanted)
•Bind mismatch (many sub-reasons, most unwanted)
•...
Parsing
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Parsing
Optimization
(Hard Parse)
Execution
“Harder“
Soft Parse
(choose
child cursor)
Shared Pool
>1 children
SQL
Adaptive
Cursor Sharing II
one more
child cursor
one more
child cursor
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Parsing
“Hard” - “Soft” - “Harder Soft”
Parent Cursor
<bind aware>
Child Cursor
Child Cursor
Child Cursor
SQL
Peeking
New Child Cursor CBOMutex X
Cursor
Mutex S
#
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Introduction
•Oracle Parsing, Child Cursors
•Mutexes, Waits and Reasons
•Issues, Quick Fixes and Solutions
•Summary, Acknowledgements, Q&A session
Agenda
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Mutex
Example:
Simultaneously
removing two nodes
from a singly linked list
(picture from Wikipedia)
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Mutex
•“Mutual Exclusion”
= Fine-grained serialization structure
•It's just like a latch, but smaller, lighter, faster
•Introduced in 10g R2
•managed by KGX (Kernel Generic Mutex Module)
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
LC object
(Cursor)
Session 1
Session 2
Sleep = Wait
S2 spinning on M.
M
S1 holding Mutex
= Mutex Contention
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
What are Wait Events (on Mutexes)?
•Somebody requests a Mutex
•Can not get it by spinning
•And thus, sleeps
•Sleeping is recorded as wait time
•Spinning is not recorded as wait-, but as CPU time
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
cursor: mutex X
Wants: Exclusive mode on Mutex of Parent / Child
To:
•Build a new Child Cursor
•Capture SQL bind data (peek)
•Modify cursor-related statistics
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
cursor: mutex S
Wants: Shared mode on Mutex of Parent / Child
To:
•Change the reference count (“in flux”)
= “new guy is interested / spinning”
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
cursor: pin X
Wants: Exclusively pin a P/C cursor in cache
To:
•Create the cursor
•Alter the cursor
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
cursor: pin S
Wants: Pin a P/C cursor in shared mode
To:
•Use (execute) the cursor
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Waits
cursor: pin S wait on X
Wants: Pin a P/C cursor in shared mode
but sb. already has it in exclusive mode
To:
•Use (execute) the cursor
•When sb. is altering the cursor (e.g. due to DDL)
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Introduction
•Oracle Parsing, Child Cursors
•Mutexes, Waits and Reasons
•Issues, Quick Fixes and Solutions
•Summary, Acknowledgements, Q&A session
Agenda
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Simple - cursor: pin S
•Caused by massively parsing one SQL_ID
=> Hot Spot Object in Library Cache
•Diagnosis: Oracle Wait Interface
•(Half) solution: Diversify SQL_ID (not randomize!)
select /* WebServer4 */ something from table;
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Issues
Provocation of a
cursor: pin S wait situation
•Tightly looping one SQL
1,000,000 times
•in 20 threads
➔
Overcrowding the cursor's pin mutex
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Complex - cursor: mutex S/X
•Root-caused by invalidated child cursor(s)
=> Too many cursor objects in Library Cache
•Diagnosis:
•Oracle Wait Interface
•10046 Level 12 session trace (=sql_trace event)
•v$sql_shared_cursor plus cursortrace [296377.1]
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
One example reason for cursor: mutex S/X
Application uses jdbc setter methods
improperly on INTEGER column (=2)
•setNUMBER(2) => Bind Var. is NUMBER
•setNULL(2) => Bind Var. is VARCHAR2
Issues
= BIND MISMATCH
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
10046 Level 12 trace for cursor: mutex S/X
Trace 1:
Bind#2
>> oacdty=01 mxl=32(04) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000010 frm=01 csi=873 siz=0 off=168
kxsbbbfp=1118e1cd8 bln=32 avl=00 flg=01
Trace 2:
Bind#2
>> oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00
oacflg=03 fl2=1000000 frm=01 csi=873 siz=0 off=168
kxsbbbfp=110977db8 bln=22 avl=02 flg=01
value=99
Issues
in 30 columns
= 2^30 times
BIND MISMATCH
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
One Quick Fix for cursor: mutex S/X
System is loaded with heavy mutex waits
due to high number of cursors (=version count)
=> frequently flush this cursor with
dbms_shared_pool.purge
(look out for new parsing issues = CPU)
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
One solution for cursor: mutex S/X
Application uses jdbc setter methods
now properly on INTEGER column (=2)
•setNUMBER(2) => Bind Var. is NUMBER
•setNULL(2, java.sql.Types.INTEGER)
=> Bind Var. is NUMBER
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Issues
Provocation of a
cursor: mutex S/X wait situation
•Generating 64 child cursors
for one SQL_ID
•Accessing them 20x parallel
➔
Delay to create new children (X)
➔
Delay to select good child (S)
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Similar Problem with CHAR binds
•Bind buffers are size 32, 128, 2000 or 4000 bytes
•Changing CHAR bind length invalidates
•Reason BIND_LENGTH_UPGRADEABLE
= 4^n cursor versions
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Heavy - Oracle internal pitfalls I
•11g “features” like
MOS: “Its important to note that cursor obsoletion code was removed in
version 11.
That means we no longer obsolete a parent cursor when it reaches
1024 child cursors [as we did in 10g.]”
•Workaround
Enhancement Patch 10187168 introduces parameter
“_cursor_obsolete_threshold”
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Heavy - Oracle internal pitfalls II
•DB Bugs like 10157392 + 12939876
(fixed in 12.1, backported to 11.2.0.3)
Memory leak: increasing number of child cursors over time, especially if
the shared pool is under load.
•DB Bug 9591812 (fixed in 12.1)
Wrong wait events in 11.2 ("cursor: mutex S" instead of "cursor: mutex X")
Official MOS workaround:
Be cautious when interpreting S mode mutex / pin waits....
Issues
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
•Introduction
•Oracle Parsing, Child Cursors
•Mutexes, Waits and Reasons
•Issues, Quick Fixes and Solutions
•Summary, Acknowledgements, Q&A session
Agenda
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
My suggestions for “cursor: mutex S/X” casualties
•Check how the application does handle bind variables
Avoid BIND MISMATCH at (nearly) any cost
•Reduce the number of cursor versions below 100
More will lead to overhead
•Look for matching Oracle bugs in your RDBMS release
•Upgrade to 11.2.0.3 or higher
11.2.0.2 is worst version for cursor issues IMHO
I suggest...
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
More resources on this topic
•MOS Documents
1356828.1; 1377998.1; 296377.1
•Põder, Tanel
Presentation: “Oracle Latch and Mutex Contention Troubleshooting”
•Shallahamer, Craig
Book: “Oracle Performance Firefighting”
(ISBN 978-0-9841023-0-3)
•Nikolaev, Andrey
Blog entries: “Mutex waits. Part 1 + 2”
Read on...
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Thank you very much
for your attention!
Martin Klier
Senior DBA
Klug GmbH integrierte Systeme
San Francisco, Sept 30th, 2012
Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits
Thank you
Many people have helped with suggestions, supplying
test cases or taking daily work off me during
preparation and travel phase. Guys, you are top!
My special thanks to:
My boss and company, for endorsement
Two special customers, for interested patience
An ex-colleague, for The Code
One guy from OR, who made it possible.

More Related Content

Similar to Resolving Child Cursor Issues Resulting In Mutex Waits

Job Shop Scheduling with Setup Times Release times and Deadlines
Job Shop Scheduling with Setup Times  Release times and DeadlinesJob Shop Scheduling with Setup Times  Release times and Deadlines
Job Shop Scheduling with Setup Times Release times and DeadlinesAlkis Vazacopoulos
 
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid Cloud
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid CloudGartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid Cloud
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid CloudSingleStore
 
Rolf huisman programming quantum computers in dot net using q#
Rolf huisman   programming quantum computers in dot net using q#Rolf huisman   programming quantum computers in dot net using q#
Rolf huisman programming quantum computers in dot net using q#Rolf Huisman
 
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...South Tyrol Free Software Conference
 
SAIMA Session - Salesforce performance considerations
SAIMA Session - Salesforce performance considerationsSAIMA Session - Salesforce performance considerations
SAIMA Session - Salesforce performance considerationsMeera R Nair
 
Fuzzy Control meets Software Engineering
Fuzzy Control meets Software EngineeringFuzzy Control meets Software Engineering
Fuzzy Control meets Software EngineeringPooyan Jamshidi
 
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch TablesGUSS
 
#Virtualdreamin Meera_Nar_Salesforce_performance_considerations
#Virtualdreamin Meera_Nar_Salesforce_performance_considerations#Virtualdreamin Meera_Nar_Salesforce_performance_considerations
#Virtualdreamin Meera_Nar_Salesforce_performance_considerationsMeera R Nair
 

Similar to Resolving Child Cursor Issues Resulting In Mutex Waits (8)

Job Shop Scheduling with Setup Times Release times and Deadlines
Job Shop Scheduling with Setup Times  Release times and DeadlinesJob Shop Scheduling with Setup Times  Release times and Deadlines
Job Shop Scheduling with Setup Times Release times and Deadlines
 
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid Cloud
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid CloudGartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid Cloud
Gartner Catalyst 2017: The Data Warehouse Blueprint for ML, AI, and Hybrid Cloud
 
Rolf huisman programming quantum computers in dot net using q#
Rolf huisman   programming quantum computers in dot net using q#Rolf huisman   programming quantum computers in dot net using q#
Rolf huisman programming quantum computers in dot net using q#
 
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...
SFScon 21 - Matteo Camilli - Performance assessment of microservices with str...
 
SAIMA Session - Salesforce performance considerations
SAIMA Session - Salesforce performance considerationsSAIMA Session - Salesforce performance considerations
SAIMA Session - Salesforce performance considerations
 
Fuzzy Control meets Software Engineering
Fuzzy Control meets Software EngineeringFuzzy Control meets Software Engineering
Fuzzy Control meets Software Engineering
 
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables
[JSS2015] Nouveautés SQL Server 2016:Sécurité,Temporal & Stretch Tables
 
#Virtualdreamin Meera_Nar_Salesforce_performance_considerations
#Virtualdreamin Meera_Nar_Salesforce_performance_considerations#Virtualdreamin Meera_Nar_Salesforce_performance_considerations
#Virtualdreamin Meera_Nar_Salesforce_performance_considerations
 

Recently uploaded

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationZilliz
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaRTTS
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxDavid Michel
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Product School
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCzechDreamin
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Julian Hyde
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 

Recently uploaded (20)

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 

Resolving Child Cursor Issues Resulting In Mutex Waits

  • 1. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Martin Klier Senior DBA Klug GmbH integrierte Systeme San Francisco, Sept 30th, 2012 Resolving Child Cursor Issues Resulting In Mutex Waits
  • 2. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Introduction •Oracle Parsing, Child Cursors •Mutexes, Waits and Reasons •Issues, Quick Fixes and Solutions •Summary, Acknowledgements, Q&A session Agenda
  • 3. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Martin Klier (martin.klier@klug-is.de) •Senior DBA for at •Focus on Performance, Tuning and High Availability •Linux since 1997, Oracle since 2003 •Weblog: http://www.usn-it.de Speaker
  • 4. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Klug GmbH integrierte Systeme (http://www.klug-is.de) 92552 Teunz, GERMANY •Specialist leading in complex intralogistical solutions •Planning and design of automated intralogistics systems, focus on software and system control / PLC •>300 successful major projects in Europe, America, Asia
  • 5. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits iWACS®
  • 6. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Introduction •Oracle Parsing, Child Cursors •Mutexes, Waits and Reasons •Issues, Quick Fixes and Solutions •Summary, Acknowledgements, Q&A session Agenda
  • 7. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Parsing Optimization (Hard Parse) Execution Soft Parse Shared Pool 0 or 1 child SQL Cursor Sharing Insert cursor + single child
  • 8. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Parsing Execution Shared Pool 1 or n children SQL Adaptive Cursor Sharing I Cardinality Feedback Soft Parse Bind Mismatch or ~62 other Reasons
  • 9. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits 64 Reasons for not re-using an existing child cursor •Optimizer mode change (ALL_ROWS, FIRST_ROWS) •NLS- and user identity trouble, •Outline mismatch, Cardinality feedback (wanted) •Bind mismatch (many sub-reasons, most unwanted) •... Parsing
  • 10. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Parsing Optimization (Hard Parse) Execution “Harder“ Soft Parse (choose child cursor) Shared Pool >1 children SQL Adaptive Cursor Sharing II one more child cursor one more child cursor
  • 11. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Parsing “Hard” - “Soft” - “Harder Soft” Parent Cursor <bind aware> Child Cursor Child Cursor Child Cursor SQL Peeking New Child Cursor CBOMutex X Cursor Mutex S #
  • 12. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Introduction •Oracle Parsing, Child Cursors •Mutexes, Waits and Reasons •Issues, Quick Fixes and Solutions •Summary, Acknowledgements, Q&A session Agenda
  • 13. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Mutex Example: Simultaneously removing two nodes from a singly linked list (picture from Wikipedia)
  • 14. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Mutex •“Mutual Exclusion” = Fine-grained serialization structure •It's just like a latch, but smaller, lighter, faster •Introduced in 10g R2 •managed by KGX (Kernel Generic Mutex Module)
  • 15. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits LC object (Cursor) Session 1 Session 2 Sleep = Wait S2 spinning on M. M S1 holding Mutex = Mutex Contention
  • 16. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits What are Wait Events (on Mutexes)? •Somebody requests a Mutex •Can not get it by spinning •And thus, sleeps •Sleeping is recorded as wait time •Spinning is not recorded as wait-, but as CPU time
  • 17. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits cursor: mutex X Wants: Exclusive mode on Mutex of Parent / Child To: •Build a new Child Cursor •Capture SQL bind data (peek) •Modify cursor-related statistics
  • 18. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits cursor: mutex S Wants: Shared mode on Mutex of Parent / Child To: •Change the reference count (“in flux”) = “new guy is interested / spinning”
  • 19. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits cursor: pin X Wants: Exclusively pin a P/C cursor in cache To: •Create the cursor •Alter the cursor
  • 20. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits cursor: pin S Wants: Pin a P/C cursor in shared mode To: •Use (execute) the cursor
  • 21. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Waits cursor: pin S wait on X Wants: Pin a P/C cursor in shared mode but sb. already has it in exclusive mode To: •Use (execute) the cursor •When sb. is altering the cursor (e.g. due to DDL)
  • 22. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Introduction •Oracle Parsing, Child Cursors •Mutexes, Waits and Reasons •Issues, Quick Fixes and Solutions •Summary, Acknowledgements, Q&A session Agenda
  • 23. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Simple - cursor: pin S •Caused by massively parsing one SQL_ID => Hot Spot Object in Library Cache •Diagnosis: Oracle Wait Interface •(Half) solution: Diversify SQL_ID (not randomize!) select /* WebServer4 */ something from table; Issues
  • 24. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Issues Provocation of a cursor: pin S wait situation •Tightly looping one SQL 1,000,000 times •in 20 threads ➔ Overcrowding the cursor's pin mutex
  • 25. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Complex - cursor: mutex S/X •Root-caused by invalidated child cursor(s) => Too many cursor objects in Library Cache •Diagnosis: •Oracle Wait Interface •10046 Level 12 session trace (=sql_trace event) •v$sql_shared_cursor plus cursortrace [296377.1] Issues
  • 26. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits One example reason for cursor: mutex S/X Application uses jdbc setter methods improperly on INTEGER column (=2) •setNUMBER(2) => Bind Var. is NUMBER •setNULL(2) => Bind Var. is VARCHAR2 Issues = BIND MISMATCH
  • 27. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits 10046 Level 12 trace for cursor: mutex S/X Trace 1: Bind#2 >> oacdty=01 mxl=32(04) mxlc=00 mal=00 scl=00 pre=00 oacflg=03 fl2=1000010 frm=01 csi=873 siz=0 off=168 kxsbbbfp=1118e1cd8 bln=32 avl=00 flg=01 Trace 2: Bind#2 >> oacdty=02 mxl=22(22) mxlc=00 mal=00 scl=00 pre=00 oacflg=03 fl2=1000000 frm=01 csi=873 siz=0 off=168 kxsbbbfp=110977db8 bln=22 avl=02 flg=01 value=99 Issues in 30 columns = 2^30 times BIND MISMATCH
  • 28. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits One Quick Fix for cursor: mutex S/X System is loaded with heavy mutex waits due to high number of cursors (=version count) => frequently flush this cursor with dbms_shared_pool.purge (look out for new parsing issues = CPU) Issues
  • 29. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits One solution for cursor: mutex S/X Application uses jdbc setter methods now properly on INTEGER column (=2) •setNUMBER(2) => Bind Var. is NUMBER •setNULL(2, java.sql.Types.INTEGER) => Bind Var. is NUMBER Issues
  • 30. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Issues Provocation of a cursor: mutex S/X wait situation •Generating 64 child cursors for one SQL_ID •Accessing them 20x parallel ➔ Delay to create new children (X) ➔ Delay to select good child (S)
  • 31. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Similar Problem with CHAR binds •Bind buffers are size 32, 128, 2000 or 4000 bytes •Changing CHAR bind length invalidates •Reason BIND_LENGTH_UPGRADEABLE = 4^n cursor versions Issues
  • 32. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Heavy - Oracle internal pitfalls I •11g “features” like MOS: “Its important to note that cursor obsoletion code was removed in version 11. That means we no longer obsolete a parent cursor when it reaches 1024 child cursors [as we did in 10g.]” •Workaround Enhancement Patch 10187168 introduces parameter “_cursor_obsolete_threshold” Issues
  • 33. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Heavy - Oracle internal pitfalls II •DB Bugs like 10157392 + 12939876 (fixed in 12.1, backported to 11.2.0.3) Memory leak: increasing number of child cursors over time, especially if the shared pool is under load. •DB Bug 9591812 (fixed in 12.1) Wrong wait events in 11.2 ("cursor: mutex S" instead of "cursor: mutex X") Official MOS workaround: Be cautious when interpreting S mode mutex / pin waits.... Issues
  • 34. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits •Introduction •Oracle Parsing, Child Cursors •Mutexes, Waits and Reasons •Issues, Quick Fixes and Solutions •Summary, Acknowledgements, Q&A session Agenda
  • 35. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits My suggestions for “cursor: mutex S/X” casualties •Check how the application does handle bind variables Avoid BIND MISMATCH at (nearly) any cost •Reduce the number of cursor versions below 100 More will lead to overhead •Look for matching Oracle bugs in your RDBMS release •Upgrade to 11.2.0.3 or higher 11.2.0.2 is worst version for cursor issues IMHO I suggest...
  • 36. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits More resources on this topic •MOS Documents 1356828.1; 1377998.1; 296377.1 •Põder, Tanel Presentation: “Oracle Latch and Mutex Contention Troubleshooting” •Shallahamer, Craig Book: “Oracle Performance Firefighting” (ISBN 978-0-9841023-0-3) •Nikolaev, Andrey Blog entries: “Mutex waits. Part 1 + 2” Read on...
  • 37. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Thank you very much for your attention! Martin Klier Senior DBA Klug GmbH integrierte Systeme San Francisco, Sept 30th, 2012
  • 38. Martin Klier – Resolving Child Cursor Issues Resulting In Mutex Waits Thank you Many people have helped with suggestions, supplying test cases or taking daily work off me during preparation and travel phase. Guys, you are top! My special thanks to: My boss and company, for endorsement Two special customers, for interested patience An ex-colleague, for The Code One guy from OR, who made it possible.