Shared Pool Waits. #.2 Copyright 2006 Kyle Hailey Shared Pool Waits Library Cache Latch Shared...
-
Upload
eleanor-conley -
Category
Documents
-
view
229 -
download
3
Transcript of Shared Pool Waits. #.2 Copyright 2006 Kyle Hailey Shared Pool Waits Library Cache Latch Shared...
Shared Pool Waits
Copyright 2006 Kyle Hailey
#.2
Shared Pool Waits
Library Cache Latch Shared Pool Latch Library Cache Pin Library Cache Lock Library Cache Load Lock Row Cache Lock
Copyright 2006 Kyle Hailey
#.3
Hash Table
handlehandle
handle handlehandle
handle handlehandle
handle
handlehandle
handle
handle
Shared Pool Structure
Copyright 2006 Kyle Hailey
#.4
Shared Pool Latch
Protects Space Allocation in the Shared Pool Make sure two users don’t get same chunk of
memory
Copyright 2006 Kyle Hailey
#.5
Bucket sizes 0 < 80 bytes1 < 1442 < 2723 < 5284 < 10405 < 20646 < 41127 < 82088 < 164009 < 3278410 bigger
Shared Pool Latch 8.1.6
Shared Pool pre 8.1.6Memory Chunk Buckets
Copyright 2006 Kyle Hailey
#.6
Shared Pool Free Space
Shared Pool Latch covers changes in the lists of free memory chunks
Shared Pool Latch
Copyright 2006 Kyle Hailey
#.7
•Get library cache latch
•Get shared pool latch
•Search right bucket
•Find best fit
=> If lists get long, search gets long
Shared Pool Latch
Copyright 2006 Kyle Hailey
#.8
Shared Pool Free Space 8.1.6+
Shared Pool Latch
Shared Pool Latch
Copyright 2006 Kyle Hailey
#.9
Shared Pool
Memory Chunk Buckets 8.1.6 and up0 16 bytes1 20 bytes … (0-198 only have one chunk size in bucket)198 808 bytes199 812 to 872…. (199-248 only have 16 possible chunk sizes per bucket)248 3948 - 4008249 4012 - 4104250 4108 - 8204251 8204 - 16392252 16396 - 32776253 32780 - 65544254 bigger
Shared Pool Latch
Copyright 2006 Kyle Hailey
#.10
library cache pin and locks
Locks control access, protects handle Pins guarentees coherency, protects heaps To Access to a cursor
Lock handle Locking is the way of locating
Pin Pinning loads any necessary heaps Guarenteed to stay in memory until pin is released
handle handle handle
pin
pin
lock
lock
Heap 1
Child cursor 1Heap 6
Heap 0
Copyright 2006 Kyle Hailey
#.11
library cache lock and pins
Contention when Sessions try to load/compile same SQL at same time
Locks and Pins are usually in share mode unless modifications are being made
Copyright 2006 Kyle Hailey
#.12
library cache lock
handle handle handle
pin
pin
lock
lock
#20 P1 = address of object P2 = address of lock P3 = mode | namespace See x$kgllk
Copyright 2006 Kyle Hailey
#.13
library cache pin #13 P1 = address of object P2 = address of lock P3 = Mode | Namespace See x$kglpn
handle handle handle
pin
pin
lock
lock
Copyright 2006 Kyle Hailey
#.14
Solutions
Have only one Session compile a the same cursor at a time
Waits – find “competing” Sessions
Copyright 2006 Kyle Hailey
#.15
SQL: Lib Cache Lock Find the waiters and who blocks them
column wevent format a20column bevent format a20select waiter.sid waiter, waiter.p1raw wlockp1, waiter.event wevent, blocker_event.sid blocker, blocker_event.event beventfrom x$kglpn p, gv$session blocker_session, gv$session_wait waiter, gv$session_wait blocker_eventwhere p.kglpnuse=blocker_session.saddr and p.kglpnhdl=waiter.p1raw and (waiter.event like 'library cache lock' ) and blocker_event.sid=blocker_session.sidorder by waiter.p1raw,waiter.sid/
Copyright 2006 Kyle Hailey
#.16
library cache load lock
#23 Waiting For a Reload by another Session
Copyright 2006 Kyle Hailey
#.17
Library Cache Latch
Protects changes in Library Cache Library Locks are not atomic
Thus need library cache latch
Broken out into library cache pin allocation library cache lock allocation library cache lock library cache library cache pin library cache load lock
Copyright 2006 Kyle Hailey
#.18
Hash Table
handle
pin
pin
lock
lock
Library Cache
handle
Find and LockFind and Lock
Pin (and Load)Pin (and Load)
Copyright 2006 Kyle Hailey
#.19
Child cursor 3
Hash Table
handle handle handle
Cursor (0)
pin
pin
lock
lock
Heap 1
Child cursor 1
Child cursor 2
Heap 6
pin
pin
lock
lock
Heap 0
pin
pin
lock
lock
waiters
holders
Handle
Cursor(0)
flags
Library Cache Structures
Library Cache Latch
Copyright 2006 Kyle Hailey
#.20
Library Cache Latch Contention
Excesive Hard ParsingNot Sharing SQL – use of Literal ValuesShared Pool too smallToo many invalidations
Excessive Soft Parsing
Copyright 2006 Kyle Hailey
#.21
Sharing SQL & Literals
SQL> @dups
PLAN_HASH_VALUE CNT--------------- ---------- 272002086 520
SQL_TEXT---------------------------------------------------SELECT * FROM dual WHERE dummy=-634891633SELECT * FROM dual WHERE dummy=1987751014SELECT * FROM dual WHERE dummy=25965276SELECT * FROM dual WHERE dummy=32449789SELECT * FROM dual WHERE dummy=-364632215SELECT * FROM dual WHERE dummy=-34273351SELECT * FROM dual WHERE dummy=-699712683SELECT * FROM dual WHERE dummy=1752437199SELECT * FROM dual WHERE dummy=-1081512404
select select plan_hash_value,plan_hash_value,count(plan_hash_value)count(plan_hash_value)
from from v$sql v$sql
group by plan_hash_value,group by plan_hash_value,order by count(plan_hash_value)order by count(plan_hash_value)
select select plan_hash_value,plan_hash_value,count(plan_hash_value)count(plan_hash_value)
from from v$sql v$sql
group by plan_hash_value,group by plan_hash_value,order by count(plan_hash_value)order by count(plan_hash_value)
select sql_text from v$sql where plan_hash_value = 272002086 and rownum < 10;
select sql_text from v$sql where plan_hash_value = 272002086 and rownum < 10;
Copyright 2006 Kyle Hailey
#.22
Cursor Sharing
Bind VariablesSelect * from dual where dummy = :var;
Cursor_SharingCursor_sharing = Force
Oracle replaces variables with bind variables
Defaults to Exact
Copyright 2006 Kyle Hailey
#.23
Shared Pool too Small
Reloads means Cursor heaps were kicked out implying shared_pool too small
SQL> select namespace, reloadsSQL> select namespace, reloads
from v$librarycache;from v$librarycache;
NAMESPACE RELOADS NAMESPACE RELOADS
--------------- ------------------------- ----------
SQL AREA 367SQL AREA 367
TABLE/PROCEDURE 592TABLE/PROCEDURE 592
SQL> select namespace, reloadsSQL> select namespace, reloads
from v$librarycache;from v$librarycache;
NAMESPACE RELOADS NAMESPACE RELOADS
--------------- ------------------------- ----------
SQL AREA 367SQL AREA 367
TABLE/PROCEDURE 592TABLE/PROCEDURE 592
Copyright 2006 Kyle Hailey
#.24
Invalidations
Changes in dependent objects invalidate cursorFOR i IN 1..3000 LOOP
l_cursor:=dbms_sql.open_cursor;
dbms_sql.parse(l_cursor,
'SELECT * FROM toto',dbms_sql.native);
execute immediate 'analyze table toto compute statistics';
dbms_sql.close_cursor(l_cursor);
END LOOP;
SQL> select namespace,SQL> select namespace,
invalidations invalidations
from v$librarycache;from v$librarycache;NAMESPACE INVALIDATIONSNAMESPACE INVALIDATIONS--------------- ---------------------------- -------------SQL AREA 6065SQL AREA 6065
SQL> select namespace,SQL> select namespace,
invalidations invalidations
from v$librarycache;from v$librarycache;NAMESPACE INVALIDATIONSNAMESPACE INVALIDATIONS--------------- ---------------------------- -------------SQL AREA 6065SQL AREA 6065
Copyright 2006 Kyle Hailey
#.25
Re-Executing a Cursor Re-Executing a Cursor
1.1. Libray Cache latch Libray Cache latch 2.2. LocksLocks3.3. PinsPins
pin pin pin pin pin
lock
Execute 1 Execute 2 Execute 3 Execute 4 Execute 5
Cursor MemoryCursor Memory
locklock lock lock
= Latch= Latch
Soft Parsing
Copyright 2006 Kyle Hailey
#.26
Session Cached Cursors
Execute 1 Execute 2 Execute 3 Execute 4 Execute 5
Cursor MemoryCursor Memory
lock
= Latch= Latch
pin pin pin pin pin
Session_cached_cursor:Session_cached_cursor:
If Opening/Closing keeps locked in MemoryIf Opening/Closing keeps locked in Memory
Copyright 2006 Kyle Hailey
#.27
Session Cached Cursors
FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP l_cursor:=dbms_sql.open_cursor;l_cursor:=dbms_sql.open_cursor; dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native);dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.close_cursor(l_cursor);dbms_sql.close_cursor(l_cursor); END LOOP;END LOOP;
FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP l_cursor:=dbms_sql.open_cursor;l_cursor:=dbms_sql.open_cursor; dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native);dbms_sql.parse(l_cursor,'SELECT * FROM dual’,dbms_sql.native); dbms_sql.close_cursor(l_cursor);dbms_sql.close_cursor(l_cursor); END LOOP;END LOOP;
Session_cached_cursors=0Session_cached_cursors=0
Latch Gets Latch Gets ----- ---- ----- ---- library cache lock 120,028 library cache lock 120,028 library cache 180,074 library cache 180,074 library cache pin 60,048library cache pin 60,048
Session_cached_cursors=20Session_cached_cursors=20
library cache lock 4 library cache lock 4 library cache 60,061 library cache 60,061 library cache pin 60,048library cache pin 60,048
Copyright 2006 Kyle Hailey
#.28
Cursor Space for Time
Execute 1 Execute 2 Execute 3 Execute 4 Execute 5
Cursor MemoryCursor Memory
Cursor_space_for_time=true :Cursor_space_for_time=true :
if open and re-executing – keeps cursor pinnedif open and re-executing – keeps cursor pinned
(Cursor already locked because cursor is kept open)(Cursor already locked because cursor is kept open)
= Latch= Latch
pin
lock
OpenOpenCursorCursor
CloseCloseCursorCursor
Copyright 2006 Kyle Hailey
#.29
Cursor Space For Time
FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP rc:=dbms_sql.execute(l_cursor);rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THENIF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt);DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); end if;end if;
FOR i IN 1..30000 LOOPFOR i IN 1..30000 LOOP rc:=dbms_sql.execute(l_cursor);rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THENIF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt);DBMS_SQL.COLUMN_VALUE (l_cursor, 1, cnt); end if;end if;
Cursor_space_for_time=falseCursor_space_for_time=false
Latch Gets Latch Gets ----- ---- ----- ---- library cache lock 35library cache lock 35library cache 60,096library cache 60,096library cache pin 60,044library cache pin 60,044
Cursor_space_for_time=trueCursor_space_for_time=true
library cache lock 30library cache lock 30library cache 85library cache 85library cache pin 42library cache pin 42
Copyright 2006 Kyle Hailey
#.30
Efficient Lock and Pinning
Reduce use of latches Improve throughput Improve Concurrency ***
Copyright 2006 Kyle Hailey
#.31
row cache lock : args
P1 = cache# P2 = Lock Mode Held P3 = Lock Mode Requested
select parameter as “name”
from v$rowcache
where cache# = P1;
select parameter as “name”
from v$rowcache
where cache# = P1;
Copyright 2006 Kyle Hailey
#.32
Summary
Shared Pool LatchShard pool too small or too much hard pasing
Loading Same CursorLibrary Cache PinLibrary Cache LockLibrary Cache Load Lock
Library Cache LatchToo much hard or soft parsing
Row Cache Lock
Copyright 2006 Kyle Hailey
#.33
Library Cache Latch Solutions Share Cursors
Use bind variablesUser cursor_sharing=force
Avoid invalidations and reloadsSize shared_pool large enoughAvoid changing dependent objects
Soft ParsingSession_cached_cursors =20 : keep across open/closeCursor_space_for_time=true : keep pinned across executeshold_cursor=true : used in precompilers