Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata.

Similar presentations


Presentation on theme: "Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata."— Presentation transcript:

1 Lock Tuning

2 Overview

3 Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata The catalog can easily become a hot spot and therefore a bottleneck The lesson is: avoid updates to the system catalog during heavy system activity, especially if you are using dynamic SQL © Dennis Shasha, Philippe Bonnet 2001

4 Think about partitioning Problem: insert a collection records into history file or security file, or log file –Time dependent insertion –Last page of the file may become a concurrency bottleneck Solution: partition insertions to the file across different pages and possibly different disks –Set up many insertion points and insert into them randomly –Set up a clustering index based on some attribute that is not correlated with the time of insertion. –Hash the time of insertion and use that as the clustering key. © Dennis Shasha, Philippe Bonnet 2001

5 Multiple insertion points and page locking “sequential” a clustered index defined on an attribute whose value increases (or even decreases) with time “Nonsequential” denotes that independent of time © Dennis Shasha, Philippe Bonnet 2001

6 Multiple insertion points and row locking Row locking avoids contention between successive insertions © Dennis Shasha, Philippe Bonnet 2001

7 Circumventing hot spots A hot spot is a piece of data that is accessed by many transactions and is updated by some. Hot spots cause bottlenecks because each updating transaction must complete before any other transaction can obtain a lock on the hot data item. Solution –Use partitioning to eliminate it –Access the hot spot as late as possible in the transaction –Use special database management facilities © Dennis Shasha, Philippe Bonnet 2001

8 2 - Tuning the Guts © Dennis Shasha, Philippe Bonnet 2001 8 Logical Bottleneck: Sequential Key generation Consider an application in which one needs a sequential number to act as a key in a table, e.g. invoice numbers for bills. Ad hoc approach: a separate table holding the last invoice number. Fetch and update that number on each insert transaction. –The last invoice number becomes a bottleneck due to two-phase locking Counter approach: use facility such as Sequence (Oracle)/Identity(SQL Server).

9 © Dennis Shasha, Philippe Bonnet 2001 Latches and Locks Locks are used for concurrency control –Is held until commit the transaction –Requests for locks are queued Priority queue –Lock data structure Locking mode, lock granularity, transaction id. Lock table Latches are used for mutual exclusion –A latch is released immediately after access –Requests for latch succeeds or fails Active wait (spinning) on latches on multiple CPU. –Single location in memory Test and set for latch manipulation

10 © Dennis Shasha, Philippe Bonnet 2001 Counter Facility -- data Settings: –default isolation level: READ COMMITTED; Empty tables –Dual Xeon (550MHz,512Kb), 1Gb RAM, Internal RAID controller from Adaptec (80Mb), 4x18Gb drives (10000RPM), Windows 2000. accounts( number, branchnum, balance); create clustered index c on accounts(number); counter ( nextkey ); insert into counter values (1);

11 © Dennis Shasha, Philippe Bonnet 2001 Counter Facility -- transactions No Concurrent Transactions: –System [100 000 inserts, N threads] SQL Server 7 (uses Identity column) insert into accounts values (94496,2789); Oracle 8i insert into accounts values (seq.nextval,94496,2789); –Ad-hoc [100 000 inserts, N threads] begin transaction NextKey:=select nextkey from counter; update counter set nextkey = NextKey+1; commit transaction begin transaction insert into accounts values(NextKey,?,?); commit transaction

12 © Dennis Shasha, Philippe Bonnet 2001 Avoid Bottlenecks: Counters System generated counter (system) much better than a counter managed as an attribute value within a table (ad hoc). Counters may miss ids, however which is tolerable in many real apps

13 summary


Download ppt "Lock Tuning. Overview Data definition language (DDL) statements are considered harmful DDL is the language used to access and manipulate catalog or metadata."

Similar presentations


Ads by Google