Professional Documents
Culture Documents
Latches
Hamid R. Minoui
Fritz Companies Inc.
NoCOUG May 16, 2001
The Challenge of Tuning
Oracle performance tuning requires a
good understanding of all the components
of a database system and the way they
operate and interact.
This presentation addresses two types of
these components:
Benefit:
– The process is woken up as soon as the latch is freed
Cost:
– Requires protecting a latch wait list data structure
by yet another latch, namely latch wait list latch
– When used extensively, it can result in a
secondary latch contention
Latch Contention
Latch contention has a significant impact on
performance when:
– Enough latches are not available
– A latch is held for a relatively long time
Latch contention can be resolved by increasing
specific init.ora parameters associated with latches
To detect latch contention latch statistics should
be examined
Dynamic Performance Views for
latches
Oracle collects statistics for the activity of
all latches and stores them in the dynamic
performance view V$LATCH.
Latch statistics can be used to find
performance problems associated latch
contentions.
V$LATCH
Each row contains statistics for a specific type of
latch.
Contains summary statistics for both non-parent
and parent latches grouped by latch number
(latch#).
Should be the first point of reference when
investigating a suspecting latch contention.
Understanding the V$LATCH
Statistics
V$LATCH contains information such as:
GETS-Number of successful “willing-to-wait” requests for a
latch
MISSES- Number of times a “willing-to-wait” process had to
spin on the first try
SPIN_GETS - Number of times a latch is obtained after
spinning at least once
SLEEPS- Number of times a “willing-to-wait” process slept
WAITERS_WOKEN- Number of times a wait was awakened
V$LATCH Statistics (2)
WAITS_HOLDING - Number of waits while holding a
different latch
IMMEDIATE_GETS - Number of times obtained
without a wait
IMMEDIATE_MISSES - Number of times failed to get
without a wait
For the entire iterations for a latch request no more
than one gets, misses and spin_gets is recorded
(gets-misses) : Number of times a latch was obtained
without spinning at all
V$LATCHNAME
Holds information about decoded latch names
for the latches shown in V$LATCH
The rows of this view have one-to-one
correspondence to the rows of V$LATCH
Latches willing to wait
Query that shows the number of processes that had to sleep, and the
number of times they had to sleep.
This query is run by UTLESTAT.
Achieved by:
Reduce the frequency of “copying on the redo
allocation latch”.
How ?
Decrease LOG_SMALL_ENTRY_MAX_SIZE parameter
value which is the threshold for number and size of redo
entries to copied to redo allocation latch.
Tuning redo copy latch
Goal:
Reduce contention on available copy latches
Achieved by:
Adding more redo copy latches
How ?
Set LOG_SIMULTANEOUS_COPIES up to
twice the number of CPUs
Cache buffer LRU latch
Controls buffers replacement in the buffer cache
Each LRU latch controls a set of buffers
Each latch should have at least 50 buffers in its set
Contention detected by querying v$latch,
v$session_event and v$system_event
Contention also exists if misses are higher than
3% in v$latch
Tuning LRU latch
Goal:
Reduce cache buffer LRU latch contention
Achieved by:
Having enough latches for the entire buffer cache.
How ?
Set the maximum number of desired LRU latch sets
with DB_BLOCK_LRU_LATCHES up to (number_of
CPU’s)*2
Adjust DB_BLOCK_BUFFERS.
Enqueue latch
This latch is used to protect the enqueue data
structure
To tune:
Set ENQUEUE_RESOURCES to a value greater
than 10
Monitoring Wait Events
Wait events on any latch (latch free wait) are
recorded in WAIT and EVENT dynamic views: