More Examples of Interpreting Wait Events To Boost System Performance
More Examples of Interpreting Wait Events To Boost System Performance
More Examples of Interpreting Wait Events To Boost System Performance
Session Objectives
Briefly introduce wait events:
Define wait events
Discuss how to use the wait event interface
Idle Events
Sometimes an Oracle process is not busy
simply because it has nothing to do.
In this case the process will be waiting on
an event that we call an idle event.
Idle events are usually not interesting from
the tuning and troubleshooting perspective.
10
12
Timed Statistics
The wait event interface will not collect timing
information unless timed statistics are enabled.
Enable timed statistics dynamically at the instance
or session level:
ALTER SYSTEM SET timed_statistics = TRUE;
ALTER SESSION SET timed_statistics = TRUE;
15
Data Type
-----------VARCHAR2(64)
NUMBER
NUMBER
NUMBER
NUMBER
NUMBER
16
Columns In v$system_event
EVENT: The name of a wait event
TOTAL_WAITS: Total number of times a process has
waited for this event since instance startup
TOTAL_TIMEOUTS: Total number of timeouts while
waiting for this event since instance startup
TIME_WAITED: Total time waited for this wait event by all
processes since startup (in centiseconds)
AVERAGE_WAIT: The average length of a wait for this
event since instance startup (in centiseconds)
TIME_WAITED_MICRO: Same as TIME_WAITED but in
microseconds (Oracle 9i)
17
Sample v$system_event
Query
SQL> SELECT event, time_waited
2
3
4
5
6
FROM
WHERE
v$system_event
event IN ('smon timer',
'SQL*Net message from client',
'db file sequential read',
'log file parallel write');
EVENT
TIME_WAITED
--------------------------------- ----------log file parallel write
159692
db file sequential read
28657
smon timer
130673837
SQL*Net message from client
16528989
18
Data Type
-----------NUMBER
VARCHAR2(64)
NUMBER
NUMBER
NUMBER
NUMBER
NUMBER
NUMBER
19
Columns In v$session_event
SID: The ID of a session (from v$session)
EVENT: The name of a wait event
TOTAL_WAITS: Total number of times this session has waited for
this event
TOTAL_TIMEOUTS: Total number of timeouts while this session
has waited for this event
TIME_WAITED: Total time waited for this event by this session (in
centiseconds)
AVERAGE_WAIT: The average length of a wait for this event in
this session (in centiseconds)
MAX_WAIT: The maximum amount of time the session had to
wait for this event (in centiseconds)
20
Sample v$session_event
Query
SQL> SELECT event, total_waits, time_waited_micro
2 FROM
v$session_event
3 WHERE SID =
4
(SELECT sid FROM v$session
5
WHERE audsid =
6
USERENV ('sessionid') );
EVENT
WAITS TIME_WAITED_MICRO
--------------------------- ----- ----------------db file sequential read
552
2409173
db file scattered read
41
315928
SQL*Net message to client
73
347
SQL*Net message from client
72
3397382712
21
Data Type
-----------NUMBER
VARCHAR2(64)
VARCHAR2(64)
VARCHAR2(64)
VARCHAR2(64)
23
Columns In v$event_name
EVENT#: An internal ID
NAME: The name of a wait event
PARAMETERn: The name of a parameter
associated with the wait event
24
Sample v$event_name
Query
SQL> SELECT *
2 FROM
v$event_name
3 WHERE name = 'db file scattered read';
EVENT# NAME
---------- -----------------------------PARAMETER1
PARAMETER2
PARAMETER3
------------- ------------- ------------95 db file scattered read
file#
block#
blocks
25
Data Type
-----------NUMBER
NUMBER
VARCHAR2(64)
VARCHAR2(64)
NUMBER
RAW(4)
VARCHAR2(64)
NUMBER
RAW(4)
VARCHAR2(64)
NUMBER
RAW(4)
NUMBER
NUMBER
VARCHAR2(19)
26
Columns In v$session_wait
SID: The ID of a session
SEQ#: A number that increments by one on each
new wait
STATE: An indicator of the session status:
WAITING: The session is currently waiting, and details of
the wait event are provided.
WAITED KNOWN TIME: The session is not waiting, but
information about the most recent wait is provided.
WAITED SHORT TIME or WAITED UNKNOWN TIME: The
session is not waiting, but partial information about the
most recent wait is provided.
27
Columns In v$session_wait
(cont.)
EVENT: The name of a wait event
PnTEXT: The name of a parameter associated with the
wait event
Pn: The value of the parameter in decimal form
PnRAW: The value of the parameter in raw form
WAIT_TIME: Length of most recent wait (in
centiseconds) if STATE = WAITED KNOWN TIME
SECONDS_IN_WAIT: How long current wait has been
so far if STATE = WAITING
28
Sample v$session_wait
Query
29
oradebug
dbms_system.set_ev
30
Value of N
Effect
12
=====================
PARSING IN CURSOR #1 len=80 dep=0 uid=502 oct=3 lid=502
tim=2293771931 hv=2293373707 ad='511dca20'
SELECT /*+ FULL */ SUM (LENGTH(notes))
FROM
customer_calls
WHERE status = :x
END OF STMT
PARSE #1:c=0,e=0,p=0,cr=0,cu=0,mis=1,r=0,dep=0,og=0,tim=2293771931
BINDS #1:
bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0
size=24 offset=0
bfp=09717724 bln=22 avl=02 flg=05
value=43
EXEC #1:c=0,e=0,p=0,cr=0,cu=0,mis=0,r=0,dep=0,og=4,tim=2293771931
WAIT #1: nam='SQL*Net message to client' ela= 0 p1=675562835 p2=1 p3=0
WAIT #1: nam='db file scattered read' ela= 3 p1=17 p2=923 p3=8
WAIT #1: nam='db file scattered read' ela= 1 p1=17 p2=931 p3=8
WAIT #1: nam='db file scattered read' ela= 2 p1=17 p2=939 p3=8
WAIT #1: nam='db file sequential read' ela= 0 p1=17 p2=947 p3=1
WAIT #1: nam='db file scattered read' ela= 3 p1=17 p2=1657 p3=8
33
35
Example #1:
Buffer Busy Waits
A magazine publisher has a website that
displays content stored in a database. At
times the website would get bogged down
response time would become poor and the
database server would become extremely
busy (near-zero idle time).
36
Snap Time
Sessions
------- ------------------ -------Begin Snap:
61 11-Dec-02 13:00:52
145
End Snap:
71 11-Dec-02 14:00:26
145
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - Top 5 Wait Events
~~~~~~~~~~~~~~~~~
Wait
% Total
Event
Waits Time (cs) Wt Time
------------------------ ---------- ---------- ------buffer busy waits
1,962,372 1,278,649
50.03
db file sequential read
1,336,870 1,050,878
41.12
db file scattered read
47,717
49,326
1.93
direct path write
8,070
40,574
1.59
latch free
38,220
31,012
1.21
38
39
Understanding the
Buffer Busy Waits Event
SQL> SELECT parameter1, parameter2, parameter3
2 FROM
v$event_name
3 WHERE name = 'buffer busy waits';
PARAMETER1
PARAMETER2
PARAMETER3
------------ ------------ -----------file#
block#
id
SELECT
EVENT
----------------buffer busy waits
buffer busy waits
41
SELECT
FROM
WHERE
AND
42
Reason Code
110
130
220
43
44
SELECT
EVENT
----------------db file sequentia
db file sequentia
db file sequentia
SELECT
FROM
WHERE
AND
Long-Term Problem
Resolution
Convert the LONG column to a CLOB.
Large CLOB data will be stored in a
separate LOB segment.
Row chaining will be reduced or eliminated.
The table segment will be much smaller and
more likely to fit in memory.
49
Short-Term Problem
Resolution
Added index on most columns of
SAMPLES table
Allowed most queries to avoid table segment
50
51
Example #2:
More Buffer Busy Waits,
Plus Latch Contention
A genetic research company stored their
data in Oracle. Applications running
concurrently on many workstations would
fetch raw data, process it, and put the data
back in the database. But throughput
bogged down as they added more
workstations.
54
56
57
#2:
#2:
#2:
#2:
#2:
#2:
#2:
#2:
#2:
#2:
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
nam='buffer
busy
busy
busy
busy
busy
busy
busy
busy
busy
busy
waits'
waits'
waits'
waits'
waits'
waits'
waits'
waits'
waits'
waits'
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
ela=
SELECT
FROM
WHERE
AND
Reason Code
110
130
220
61
The PROCESSING_STATIONS
Table
SQL> SELECT SYSDATE - last_analyzed, blocks,
2
avg_row_len, avg_space, num_rows
3 FROM
user_tables
4 WHERE table_name = 'PROCESSING_STATIONS';
SYSDATEAVG_ AVG_
LAST_ANALYZED BLOCKS ROW_LEN SPACE NUM_ROWS
------------- ------ ------- ----- -------2.132118056
1
62 1686
100
63
64
Lots of Updates!
Workstation #30 updated the
PROCESSING_STATIONS table 500 times
in less than one minute.
If all 100 workstations do similar things:
More than 50,000 updates to one data block
every minute by 100 concurrent sessions!
65
66
Long-Term Problem
Resolution
Modify the application to update the
PROCESSING_STATIONS table less
frequentlyonce per data set or once per
second for larger data sets:
Will reduce updates by over 80%
Buffer busy waits will disappear or dramatically
decrease
67
Short-Term Problem
Resolution
Rebuilt the PROCESSING_STATIONS table
with PCTFREE set to 99:
Oracle reserved 99% of each data block for
future row expansion.
Each row got its own data block.
Each workstation session now updates a
separate data block.
68
The Rebuilt
PROCESSING_STATIONS
Table
SQL> SELECT SYSDATE - last_analyzed, blocks,
2
avg_row_len, avg_space, num_rows
3 FROM
user_tables
4 WHERE table_name = 'PROCESSING_STATIONS';
SYSDATEAVG_ AVG_
LAST_ANALYZED BLOCKS ROW_LEN SPACE NUM_ROWS
------------- ------ ------- ----- -------.130868056
100
62 8014
100
69
Understanding the
Latch Free Event
SQL> SELECT parameter1, parameter2, parameter3
2 FROM
v$event_name
3 WHERE name = 'latch free';
PARAMETER1
PARAMETER2
PARAMETER3
------------ ------------ -----------address
number
tries
#2:
#2:
#2:
#2:
nam='latch
nam='latch
nam='latch
nam='latch
free'
free'
free'
free'
ela=
ela=
ela=
ela=
47004
14629
20652
37737
p1=15113593728
p1=15113593728
p1=15113593728
p1=15113593728
p2=97
p2=97
p2=97
p2=97
p3=0
p3=1
p3=2
p3=3
74
Example #3:
Log File Waits
A data warehouse loader application was
tuned in a test environment until it met user
acceptance. The production server was
larger and more powerful, but the data loads
actually took longer in production than in the
test environment.
76
79
Problem Resolution
Sped up online redo log file performance:
Moved log files to dedicated disks
Spread log files over multiple disks
82
83
Example #4:
Direct Path I/O Waits
Analysts in a customer service unit were
satisfied with the response time when they
queried individual customer orders from their
data warehouse. However, queries involving
summarizations of multiple orders were
unacceptably slow.
84
85
Understanding the
Direct Path I/O Events
SQL> SELECT name, parameter1, parameter2, parameter3
2 FROM
v$event_name
3 WHERE name LIKE 'direct path%';
NAME
----------------direct path read
direct path write
PARAMETER1
----------file number
file number
PARAMETER2
---------first dba
first dba
PARAMETER3
---------block cnt
block cnt
SELECT
EVENT
----------------direct path write
direct path write
89
SELECT
FROM
WHERE
AND
TABLESPACE_NAME
AFN
------------------------------ ---------TEMP
201
90
Problem Resolution
Increased sort_area_size:
Was set to default of 65536
Increased to 10485760 (few concurrent sessions)
93
Example #5:
Database Link Wait Events
A company had five Oracle databases, one
per region. Due to human error, the same
customer transactions would sometimes get
loaded into multiple databases. A report was
built to identify these duplicates, but it took
30 minutes to run.
95
SELECT
FROM
WHERE
ORDER BY
EVENT
TOTAL_WAITS TIME_WAITED
MAX_WAIT
--------------------------- ----------- ----------- ---------SQL*Net message from client
32
4435
2432
SQL*Net message from dblink
1525516
104919
31
SQL*Net message to client
33
0
0
SQL*Net message to dblink
1525516
466
9
db file sequential read
27199
8025
28
latch free
40
5
4
log file sync
1
2
2
97
SELECT
FROM
WHERE
AND
AND
A.name, B.value
v$statname A, v$sesstat B
A.statistic# = 12
B.statistic# = A.statistic#
B.sid = 47;
NAME
VALUE
------------------------------ ---------CPU used by this session
67937
98
100
101
CUSTOMER_XFER_BATCHES
SQL> SELECT blocks, num_rows
2 FROM
user_tables
3 WHERE table_name =
4
'CUSTOMER_XFER_BATCHES';
BLOCKS NUM_ROWS
------ -------21825 1526003
102
104
SELECT
FROM
WHERE
ORDER BY
EVENT
TOTAL_WAITS TIME_WAITED
MAX_WAIT
--------------------------- ----------- ----------- ---------SQL*Net message from client
46
3680
2481
SQL*Net message from dblink
24
31
18
SQL*Net message to client
47
0
0
SQL*Net message to dblink
24
0
0
SQL*Net more data from dbli
5978
1337
13
db file scattered read
3430
675
8
db file sequential read
182
60
2
direct path read
148
233
11
direct path write
920
3572
33
105
SELECT
FROM
WHERE
AND
AND
A.name, B.value
v$statname A, v$sesstat B
A.statistic# = 12
B.statistic# = A.statistic#
B.sid = 49;
NAME
VALUE
------------------------------ ---------CPU used by this session
3227
106
107
Iterative Tuning
Curing one bottleneck often reveals or
creates another, smaller bottleneck.
Repeat the wait event evaluation process
after each change until performance goals
are met.
In this situation, a 95% reduction in runtime
from 31 minutes to 92 seconds still did not
meet the performance goal.
109
110
111
SELECT
FROM
WHERE
ORDER BY
EVENT
TOTAL_WAITS TIME_WAITED
MAX_WAIT
--------------------------- ----------- ----------- ---------SQL*Net message from client
47
442
287
SQL*Net message from dblink
25
25
14
SQL*Net message to client
48
0
0
SQL*Net message to dblink
25
0
0
SQL*Net more data from dbli
6050
1378
26
db file scattered read
3430
945
8
db file sequential read
191
59
1
log file sync
1
3
3
112
SELECT
FROM
WHERE
AND
AND
A.name, B.value
v$statname A, v$sesstat B
A.statistic# = 12
B.statistic# = A.statistic#
B.sid = 46;
NAME
VALUE
------------------------------ ---------CPU used by this session
3296
113
119
Resources from
Database Specialists
The Specialist newsletter
www.dbspecialists.com/specialist.html
Database Rx
dbrx.dbspecialists.com/guest
Provides secure, automated monitoring, alert
notification, and analysis of your Oracle
databases
120
In Conclusion
The wait event interface gives you access to a
detailed accounting of how Oracle processes
spend their time.
Wait events touch all aspects of the Oracle
database server.
The wait event interface will not always give you
the answer to every performance problem, but it
will just about always give you insights that guide
you down the proper path to problem resolution.
121
Contact Information
Roger Schrag
rschrag@dbspecialists.com
Terry Sutton
tsutton@dbspecialists.com
Database Specialists, Inc.
388 Market Street, Suite 400
San Francisco, CA 94111
Tel: 415/344-0500
Web: www.dbspecialists.com
122