05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

14<br />

CHAPTER 1 ■ DEVELOPING SUCCESSFUL ORACLE APPLICATIONS<br />

LATCH.child cursor hash table 35 80,023 79,988<br />

LATCH.shared pool 50,455 162,577 112,122<br />

LATCH.library cache 110,524 250,510 139,986<br />

Run1 latches total versus runs -- difference <strong>and</strong> pct<br />

Run1 Run2 Diff Pct<br />

407,973 889,287 481,314 45.88%<br />

PL/SQL procedure successfully completed.<br />

■Note It is to be expected that you see somewhat different values in your testing. I would be surprised if<br />

you got exactly the same values for all numbers, especially the latching numbers. You should, however, see<br />

similar numbers, assuming you are using <strong>Oracle</strong>9i Release 2 on Linux, as I was here. In all releases, I would<br />

expect the number of latches used to hard parse to be higher than those for soft parsing each insert, or<br />

parsing the insert once <strong>and</strong> executing it over <strong>and</strong> over. Running the preceding test in <strong>Oracle</strong> 10g Release 1<br />

on the same machine produced results such that the elapsed time of the bind variable approach was onetenth<br />

of the non–bind variable approach, <strong>and</strong> the amount of latches taken was 17 percent. This was due to<br />

two factors, one being that 10g is a new release <strong>and</strong> some internal algorithms changed. The other was due<br />

to an improved way dynamic SQL is processed in PL/SQL in 10g.<br />

You can see that there were only four hard parses with the bind variable approach, but<br />

over 10,000 hard parses without bind variables (once for each of the inserts). But that is just<br />

the tip of the iceberg. You can see here that twice as many “latches” were used in the non–bind<br />

variable approach than when using bind variables. This is because in order to modify this<br />

shared structure, <strong>Oracle</strong> must take care to allow only one process in at a time (it is very bad if<br />

two processes or threads attempt to update the same in-memory data structure simultaneously—corruption<br />

would abound). So, <strong>Oracle</strong> employs a latching mechanism, a lightweight<br />

locking device, to serialize access. Don’t be fooled by the word “lightweight”—these are serialization<br />

devices, allowing one-at-a-time, short duration access to a data structure. The latches<br />

overused by the hard-parsing implementation are among the most used latches out there. The<br />

latch into the shared pool <strong>and</strong> the latch for the library cache are big-time latches; they’re the<br />

ones that people compete for frequently. What that means is that as we increase the number<br />

of users attempting to hard-parse statements simultaneously, our performance problem will<br />

get progressively worse over time. The more people parsing, the more people fighting for the<br />

right to latch the shared pool, the longer the queues, the longer the wait.<br />

■Note In 9i <strong>and</strong> above on machines with more than one processor, the shared pool may be divided into<br />

multiple subpools, each protected by its own latch. This permits increased scalability for applications that do<br />

not use bind variables, but it does not make the latching problem go away by any means.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!