Docsity

Concurrency Control for Transactions: Locking Performance and Avoiding Thrashing, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download Concurrency Control for Transactions: Locking Performance and Avoiding Thrashing and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

8. Concurrency Control

for Transactions

Part Two

Transaction Processing

Outline

  1. A Model for Concurrency Control2. Serializability Theory3. Synchronization Requirements for Recoverability4. Two-Phase Locking5. Implementing Two-Phase Locking6. Locking Performance7. Multigranularity Locking (revisited)8. Hot Spot Techniques9. Query-Update Techniques10. Phantoms11. Shared Disk Systems12. B-Trees13. Tree locking     

Conversions in MS SQL Server

-^

Update-lock prevents lock conversion deadlock.^ –

Conflicts with other update and write locks, but notwith read locks.

Only on pages and rows (not tables)

-^

You get an update lock by using the UPDLOCKhint in the FROM clause

Select Foo.AFrom Foo (UPDLOCK)Where Foo.B = 7

Blocking and Lock Thrashing

Throughput

High^ Low

of Active Txns

Low

High

  • The locking performance problem is too much delay

due to blocking^ – little delay until locks are saturated– then major delay, due to the locking bottleneck– thrashing - the point where throughput decreases with

increasing load

thrashing

Avoiding Thrashing

-^

If over 30% of active transactions are blocked,then the system is (nearly) thrashingso reduce the number of active transactions

-^

Timeout-based deadlock detection mistakes^ –

They happen due to long lock delays

So the system is probably close to thrashing

So if deadlock detection rate is too high (over 2%)reduce the number of active transactions

Interesting Sidelights

-^

By getting all locks before transaction Start, youcan increase throughput at the thrashing pointbecause blocked transactions hold no locks^ –

But it assumes you get exactly the locks you needand retries of get-all-locks are cheap

-^

Pure restart policy - abort when there’s aconflict and restart when the conflict disappears^ –

If aborts are cheap and there’s low contention forother resources, then this policy produces higherthroughput before thrashing than a blocking policy

But response time is greater than a blocking policy

Reducing Lock Contention (cont’d)

-^

Reduce number of conflicts^ –

Use finer grained locks, e.g., by partitioning tablesvertically^ Part#

Price OnHand PartName CatalogPage

Part#

Price OnHand

Part#

PartName CatalogPage

  • Use record-level locking (i.e., select a database

system that supports it)

Mathematical Model of Locking

-^

N transactions each own K/2 locks on average^ –

KN/2 in total

-^

Each lock request has probability KN/2D ofconflicting with an existing lock.

-^

Each transaction requests K locks, so its probabilityof experiencing a conflict is K

2 N/2D.

-^

Probability of a deadlock is proportional to K

4 N/D

2

Prob(deadlock) / Prop(conflict) = K

2 /D

if K=10 and D = 10

6 , then K

2 /D =.

•^

K locks per transaction

-^

D lockable data items

•^

N transactions

-^

T time between lock requests

Docsity.com