Database Reference
In-Depth Information
Chapter 17
Waits, Enqueues, and Latches
When optimizing Oracle database systems, the SQL statement, its explain plan, adding indexes, or changing the
optimizers access paths, using hints, and so forth are just methods of helping Oracle to perform user operations.
When all these tuned and optimized SQL statements are executed, there are other types of potential bottlenecks such
as contention, concurrency, locking, and resource availability that could cause applications to run slow and provide
slow response times to the users. Contention for resources could be measured or interpreted at the various levels of
the systems processing cycle. Such resources could be lack of CPU, lack of network bandwidth, lack of memory, issues
with the storage subsystem, and so forth. Oracle provides instrumentation into the various categories of resource
utilization levels and provides methods of interpreting them. In this chapter, we look at some of these critical statistics
that help optimize the database.
Latches
Latches are low-level serialization mechanisms used to protect shared data structures in the SGA. 1 A latch is a type
of lock that is very quickly acquired; and when the work is complete, it is freed. Latches are used by Oracle to prevent
multiple processes executing the same piece of code at the same time and to prevent dead locks. Depending on the
type of data structure accessed, Oracle uses different types of latches.
Once a process acquires a latch at a certain level, it cannot subsequently acquire a latch at a level that is equal
to or less than that level. 2 When trying to acquire a latch, if the latch is not available, the process spins on the CPU
for a short while and then it sleeps for a while before trying again. The number of times a process will spin when
trying to acquire a latch before waiting on the CPU and going to sleep is controlled by the _SPIN_COUNT parameter.
This parameter defaults to 2,000. Based on if the latch is obtained, it increments the SPIN_GETS and MISSES counters.
However, if it is not available, it increments the wait counter and tries again. Waiting for latches can be either a short
wait (no-wait) or a long wait (willing-to-wait); most of the latches fall under the willing-to-wait category.
Willing-to-Wait Mode
If the process attempts to get a latch in the willing-to-wait mode and finds out the latch is not available; it would spin
(loop) briefly and try to make the request again until the latch is obtained. The process/session is still in active wait
because from the O/S perspective, the process continues to consume CPU cycles.
1 Metalink Note # 22908.1. “What Are Latches and What Causes Latch Contention.” Accessed at metalink.oracle.com .
2 Ibid.
 
Search WWH ::




Custom Search