Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shared Pool Waits. #.2 Copyright 2006 Kyle Hailey Shared Pool Waits  Library Cache Latch  Shared Pool Latch  Library Cache Pin  Library Cache Lock.

Similar presentations


Presentation on theme: "Shared Pool Waits. #.2 Copyright 2006 Kyle Hailey Shared Pool Waits  Library Cache Latch  Shared Pool Latch  Library Cache Pin  Library Cache Lock."— Presentation transcript:

1 Shared Pool Waits

2 #.2 Copyright 2006 Kyle Hailey Shared Pool Waits  Library Cache Latch  Shared Pool Latch  Library Cache Pin  Library Cache Lock  Library Cache Load Lock  Row Cache Lock

3 #.3 Copyright 2006 Kyle Hailey Hash Table handle Shared Pool Structure

4 #.4 Copyright 2006 Kyle Hailey Shared Pool Latch  Protects Space Allocation in the Shared Pool  Make sure two users don’t get same chunk of memory

5 #.5 Copyright 2006 Kyle Hailey Bucket sizes 0 < 80 bytes 1 < 144 2 < 272 3 < 528 4 < 1040 5 < 2064 6 < 4112 7< 8208 8 < 16400 9 < 32784 10 bigger Shared Pool Latch 8.1.6 Shared Pool pre 8.1.6 Memory Chunk Buckets

6 #.6 Copyright 2006 Kyle Hailey Shared Pool Free Space Shared Pool Latch covers changes in the lists of free memory chunks Shared Pool Latch

7 #.7 Copyright 2006 Kyle Hailey Get library cache latch Get shared pool latch Search right bucket Find best fit => If lists get long, search gets long Shared Pool Latch

8 #.8 Copyright 2006 Kyle Hailey Shared Pool Free Space 8.1.6+ Shared Pool Latch

9 #.9 Copyright 2006 Kyle Hailey Shared Pool Memory Chunk Buckets 8.1.6 and up 0 16 bytes 1 20 bytes … ( 0-198 only have one chunk size in bucket ) 198 198 808 bytes 199 199 812 to 872 …. ( 199-248 only have 16 possible chunk sizes per bucket ) 2483948 - 4008 249 4012 - 4104 2504108 - 8204 2518204 - 16392 25216396 - 32776 25332780 - 65544 254bigger Shared Pool Latch

10 #.10 Copyright 2006 Kyle Hailey 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 pin lock Heap 1 Child cursor 1 Heap 6 Heap 0

11 #.11 Copyright 2006 Kyle Hailey 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

12 #.12 Copyright 2006 Kyle Hailey library cache lock handle pin lock   #20   P1 = address of object   P2 = address of lock   P3 = mode | namespace   See x$kgllk

13 #.13 Copyright 2006 Kyle Hailey library cache pin  #13  P1 = address of object  P2 = address of lock  P3 = Mode | Namespace  See x$kglpn handle pin lock

14 #.14 Copyright 2006 Kyle Hailey Solutions  Have only one Session compile a the same cursor at a time  Waits – find “competing” Sessions

15 #.15 Copyright 2006 Kyle Hailey SQL: Lib Cache Lock Find the waiters and who blocks them column wevent format a20 column bevent format a20 select waiter.sid waiter, waiter.p1raw wlockp1, waiter.event wevent, blocker_event.sid blocker, blocker_event.event bevent from x$kglpn p, gv$session blocker_session, gv$session_wait waiter, gv$session_wait blocker_event where p.kglpnuse=blocker_session.saddr and p.kglpnhdl=waiter.p1raw and (waiter.event like 'library cache lock' ) and blocker_event.sid=blocker_session.sid order by waiter.p1raw,waiter.sid /

16 #.16 Copyright 2006 Kyle Hailey library cache load lock  #23  Waiting For a Reload by another Session

17 #.17 Copyright 2006 Kyle Hailey 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

18 #.18 Copyright 2006 Kyle Hailey Hash Table handle pin lock Library Cache handle Find and Lock Pin (and Load)

19 #.19 Copyright 2006 Kyle Hailey Child cursor 3 Hash Table handle Cursor (0) pin lock Heap 1 Child cursor 1 Child cursor 2 Heap 6 pin lock Heap 0 pin lock waiters holders Handle Cursor(0) flags Library Cache Structures Library Cache Latch

20 #.20 Copyright 2006 Kyle Hailey Library Cache Latch Contention  Excesive Hard Parsing  Not Sharing SQL – use of Literal Values  Shared Pool too small  Too many invalidations  Excessive Soft Parsing

21 #.21 Copyright 2006 Kyle Hailey Sharing SQL & Literals SQL> @dups PLAN_HASH_VALUE CNT --------------- ---------- 272002086 520 SQL_TEXT --------------------------------------------------- SELECT * FROM dual WHERE dummy=-634891633 SELECT * FROM dual WHERE dummy=1987751014 SELECT * FROM dual WHERE dummy=25965276 SELECT * FROM dual WHERE dummy=32449789 SELECT * FROM dual WHERE dummy=-364632215 SELECT * FROM dual WHERE dummy=-34273351 SELECT * FROM dual WHERE dummy=-699712683 SELECT * FROM dual WHERE dummy=1752437199 SELECT * FROM dual WHERE dummy=-1081512404 select plan_hash_value, plan_hash_value,count(plan_hash_value)fromv$sql group by plan_hash_value, order by count(plan_hash_value) select plan_hash_value, plan_hash_value,count(plan_hash_value)fromv$sql group by 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;

22 #.22 Copyright 2006 Kyle Hailey Cursor Sharing  Bind Variables  Select * from dual where dummy = :var;  Cursor_Sharing  Cursor_sharing = Force Oracle replaces variables with bind variables  Defaults to Exact

23 #.23 Copyright 2006 Kyle Hailey Shared Pool too Small  Reloads means Cursor heaps were kicked out implying shared_pool too small SQL> select namespace, reloads from v$librarycache; from v$librarycache; NAMESPACE RELOADS --------------- ---------- SQL AREA 367 TABLE/PROCEDURE 592 SQL> select namespace, reloads from v$librarycache; from v$librarycache; NAMESPACE RELOADS --------------- ---------- SQL AREA 367 TABLE/PROCEDURE 592

24 #.24 Copyright 2006 Kyle Hailey Invalidations  Changes in dependent objects invalidate cursor FOR 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, invalidations invalidations from v$librarycache; from v$librarycache; NAMESPACE INVALIDATIONS --------------- ------------- SQL AREA 6065 SQL> select namespace, invalidations invalidations from v$librarycache; from v$librarycache; NAMESPACE INVALIDATIONS --------------- ------------- SQL AREA 6065

25 #.25 Copyright 2006 Kyle Hailey Re-Executing a Cursor 1.Libray Cache latch 2.Locks 3.Pins pin lock Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory lock = Latch Soft Parsing

26 #.26 Copyright 2006 Kyle Hailey Session Cached Cursors Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory lock = Latch pin Session_cached_cursor: If Opening/Closing keeps locked in Memory

27 #.27 Copyright 2006 Kyle Hailey Session Cached Cursors FOR i IN 1..30000 LOOP FOR 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 LOOP FOR 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=0 Latch Gets ----- ---- library cache lock 120,028 library cache 180,074 library cache pin 60,048 Session_cached_cursors=20 library cache lock 4 library cache 60,061 library cache pin 60,048

28 #.28 Copyright 2006 Kyle Hailey Cursor Space for Time Execute 1Execute 2Execute 3Execute 4Execute 5 Cursor Memory Cursor_space_for_time=true : if open and re-executing – keeps cursor pinned (Cursor already locked because cursor is kept open) = Latch pin lock OpenCursor CloseCursor

29 #.29 Copyright 2006 Kyle Hailey Cursor Space For Time FOR 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 THEN IF 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 LOOP rc:=dbms_sql.execute(l_cursor); rc:=dbms_sql.execute(l_cursor); IF DBMS_SQL.FETCH_ROWS (l_cursor) < 0 THEN IF 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=false Latch Gets ----- ---- library cache lock 35 library cache 60,096 library cache pin 60,044 Cursor_space_for_time=true library cache lock 30 library cache 85 library cache pin 42

30 #.30 Copyright 2006 Kyle Hailey Efficient Lock and Pinning  Reduce use of latches  Improve throughput  Improve Concurrency ***

31 #.31 Copyright 2006 Kyle Hailey 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;

32 #.32 Copyright 2006 Kyle Hailey Summary  Shared Pool Latch  Shard pool too small or too much hard pasing  Loading Same Cursor  Library Cache Pin  Library Cache Lock  Library Cache Load Lock  Library Cache Latch  Too much hard or soft parsing  Row Cache Lock

33 #.33 Copyright 2006 Kyle Hailey Library Cache Latch Solutions  Share Cursors  Use bind variables  User cursor_sharing=force  Avoid invalidations and reloads  Size shared_pool large enough  Avoid changing dependent objects  Soft Parsing  Session_cached_cursors =20 : keep across open/close  Cursor_space_for_time=true : keep pinned across executes  hold_cursor=true : used in precompilers


Download ppt "Shared Pool Waits. #.2 Copyright 2006 Kyle Hailey Shared Pool Waits  Library Cache Latch  Shared Pool Latch  Library Cache Pin  Library Cache Lock."

Similar presentations


Ads by Google