Session Level Yapp Handout PDF
Session Level Yapp Handout PDF
Bjørn Engsig
bjorn.engsig@oracle.com
Overview
Introduction Tuning possibilities
How is the time spent? – CPU
– wait events
Time based tuning – latches
Wait events – I/O
Using SQL_TRACE Programming
Using ”event 10046” practices
– Cursor handling
– Bind variables
1
Some typical performance
questions
Why is database performance ALWAYS a hot topic?
Why does my application not scale?
Where does my performance problem really come
from?
Can I set a magic init.ora parameter?
– There are in fact some, although not magical ones!
A famous picture
Tuning cost increases in time
Tuning benefit decreases in time
Benefit Cost
Taking a look at tuning cost and
benefit over time from application
design till full production use
Time
Design Development Implementation Production
2
Sources of performance
problems
Using too many resources, such as CPU or disk I/O
– Potential cause of poor response time
(my SQL statement takes too long to execute)
Waiting for others holding a single resource, such
as a latch
– Potential cause of poor scalability
(adding more CPU doesn’t allow me to run more
concurrent users)
– Causes contention for the resource
3
How is the time is spent?
time
4
How is the time is spent?
time
time
5
How is the time is spent?
time
time
6
How is the time spent?
time
time
response time =
Σ time componenti
7
Getting tuning data from your
application
Prepare your application to produce these data
Measure time spent calling Oracle inside your
application
Make Oracle produce timing data with an Oracle
perspective
Measuring time
Time
Application
call Oracle return call
Oracle CPU
an Oracle wait event
Oracle Wait
The more places you can measure time, the better
Oracle can precisely do it with its perspective
– Really done in the server process
8
Oracle CPU time and wait events
SQL_TRACE
9
SQL_TRACE
10
SQL_TRACE data
PARSE #3:c=0,e=199,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,
Event 10046
11
Event 10046 example
12
Let’s combine three slides!
Application
10046
call Oracle return call
Σ
Oracle CPU
an Oracle wait event
Oracle Wait
Σ
response time = time componenti
13
tkprof output example
update rac1 set b=:b1
where
a=:b2
14
What have we learned so far?
15
Tuning possibilities for CPU
??
Oracle CPU
an Oracle wait event
Oracle Wait
16
Tuning possibilities for wait
events
If your largest time component is a wait event
Buffer management events
I/O events
Lock and latching events
SQL*Net events
free buffer waits Waiting for a free DBWR not able to keep up.
buffer to be available − Use asynchronous I/O
− Redistribute files
− Too small buffer cache
17
File I/O events
Event name Description Possible tuning
latch free Waiting for a certain Check latches with high number of
(more details in 10g) latch to become sleeps from v$latch and take
available appropriate steps
18
Tuning latch contention
L a tc h D e s c rip tio n P o s s ib le tu n in g
nam e
s h a re d P ro te c tin g th e s h a re d p o o l. − R e d u c e p a rs in g b y u s in g b in d
pool H e a v ily u s e d d u rin g p a rs in g - in v a ria b le s
p a rtic u la r h a rd p a rs e . N o t u s e d − A v o id h a rd p a rs in g
d u in g e x e c u te − U s e c u rs o r_ s h a rin g
ro w c a c h e P ro te c tin g th e d a ta d ic tio n a ry − A v o id h a rd p a rs in g
in fo rm a tio n , o n ly n e e d e d d u rin g − c u rs o r_ s h a rin g w o rk s w e ll
h a rd p a rs e
cache buffer Protects the hash chains of − Reduce need for buffers
chain cache buffers. Oracle9i and − Often caused by hot blocks, e.g.
later normally doesn’t show index root block
it.
19
SQL*Net events
20
Parsing SQL statements
21
Application coding - category 2
eno = 1234;
parse(“select * from emp where empno=:1”);
bind(“:1”, eno);
execute();
fetch();
22
SQL_TRACE data - recap
PARSE #3:c=0,e=199,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=1,
23
Hard parse (using literals)
2500
Cat. 1, using a
literal
2000
Cat. 2, using soft
parse
1500
Cat. 3, repeating
1000 execute only
500
0
1 3 6 12 24
160
Cat. 2, using soft
140 parse
120 Cat. 3, repeating
100 execute only
80
60
40
20
0
1 3 6 12 24
24
Cheating using
session_cached_cursors
160 Cat. 2, using soft
140 parse
120
Cat. 3, repeating
100 execute only
80
Cat. 2 with
60 session_cached_
40 cursors
20
0
1 3 6 12 24
Using session_cache_cursors
25
Summary
Poor SQL
– Can be caused by the optimizer
– Most often, it is not
Bad database design
– For the purists, everything should be 5th normal form
– For the practical, performing approach, 3½th normal
form is fine☺
Poor application coding practices
– Too much parsing
26
QUESTIONS
ANSWERS
27