Latch and Mutex Contention

advertisement
Chapter 16
Latch and Mutex Contention
1
Architecture Overview of Latches







2
Protect Oracle’s SGA
Prevent two processes from updating same area of SGA
Required to add new blocks of data to buffer cache
“Lock” the buffers while they are being accessed
Modified data written to latch protected redo buffer
Each latch usually protects a group of blocks
Can protect thousands of rows or dozens of SQL
statements
Gets, Spins, and Sleeps

Terminology of how Oracle obtains a latch
–
–
–
–
–

Sessions awake either:
–
3
“Spinlock” - # of times tried before giving up
“Spins” - # of requests before sleeping
“Latch Get” – each attempt to obtain a latch
“Latch Miss” – each failed attempt to obtain a latch
“Latch Sleep” – sleeping after spinning on a latch
–
Automatically after a period of time
When a latch becomes available
Mutexes







4
Similar to latches
Operates in more fundamental OS calls
Have lower memory & CPU overhead than latch
More in quantity than latches
Protects smaller number of objects
Also use spinlock algorithm
Unlike latches, can be held in shared mode
Latch / Mutex Contention




Done via wait interface & time model
Information found in V$SYSTEM_EVENT
Latch sleeps recorded, latch misses are not
Have their own wait event
–
–

Also see
–
–
5
Latch: cache buffers chains
Library cache: mutex X
–
V$LATCH to see latch waits
ASH or AWR reports
V$SQL (CONCURRENCY_WAIT_TIME column)
Library Cache Mutex Waits

New SQL statements:
–
–

Caused by excessive hard parsing SQL
–
–

–
6
Failure to use bind variables
Shows as “library cache: mutex X” event
In V$SQL
–

Are most common reason to obtain mutex
Are also highest reason for “misses” in cache
View FORCE_MATCHING_SIGNATURE column
Shows identical SQL NOT using bind variables
Set CURSOR_SHARING=FORCE or SIMILAR
Library Cache Mutex Waits

New SQL statements:
–
–

Caused by excessive hard parsing SQL
–
–

–
7
Failure to use bind variables
Shows as “library cache: mutex X” event
In V$SQL
–

Are most common reason to obtain mutex
Are also highest reason for “misses” in cache
View FORCE_MATCHING_SIGNATURE column
Shows identical SQL NOT using bind variables
Set CURSOR_SHARING=FORCE or SIMILAR
Other Considerations






8
Watch for Library Cache Pins
Shared Pool Latch contention
Periodically flush the shared pool
Set shared pool to minimum value (if using
automatic SGA management)
Pin objects in memory
Set the _SPIN_COUNT parameter
Cache Buffers Chains Latch



Needed to access block from buffer cache
Contention occurs with high logical read rate
Reduce contention by tuning SQL
–
–


9
Turn unselective SQL to selective SQL
Proper index usage
See V$LATCH_CHILDREN for details
See X$BH (as ‘SYS’ user)
Other Latches to Watch








10

Row cache objects latch
Cache Buffers LRU chain latch
Simulator LRU latch
Redo allocation latch
Session allocation latch
Process allocation latch
KKS stats latch
In memory undo latch
Result cache: Latch
Download