Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lock, Block, and Two Smoking CPUs

Similar presentations


Presentation on theme: "Lock, Block, and Two Smoking CPUs"— Presentation transcript:

1 Lock, Block, and Two Smoking CPUs
Implementing Application Locking with sp_getapplock I was thinking of using a few other titles, “There and Lock again, A DBA’s holiday”

2 Daniel R. Maenle Junior Database Administrator at ScriptPro
Pharmacy for 8+ years OptumRX and ScriptPro Pharmacy IT 6+ years Junior DBA 2 years in January 2 | Introduction

3 Agenda Intro to our workflow (Quick Overview) Table Locking
Why application locks are needed? Table Locking Switching to sp_getapplock Using sp_getapplock Demos What’s next? Q/A 3 | Agenda

4 Pharmacy Workflow Involved: Script Drug Insurance POS
Jenny brings in prescription RX#

5 Our Original Method ScriptPro functionality
Using an “Application_lock” table Handled table name, row_id and other lock information (application, timestamp) Insert when using / Delete when done. Queries written to poll this table Debugging from this table 5 | Table Locking

6 Benefits of Using Table Locking
Central point of locking Easy to view locks Simplified debugging What is locked? SELECT * FROM Application_lock Transaction logging 6 | Table Locking

7 Downsides of Table Locking
Single table contention Insert/Update/Delete schema locks Waiting on other queries before next insert/delete Isn’t really a lock! Concurrency Non-requester can delete the lock! What happened to what I was working on? 7 | Table Locking

8 The Project “Make our locking mechanism better”
What caused this request? Blocking Duration to insert and delete was long Wait stats were showing bad indicators of table/schema contention (LCK_M_IX) 8 | Switching to sp_getapplock

9 The Project (2) “Make our locking mechanism better” (2) Sp_getapplock
Keep current functionality No single point of contention Don’t break anything! Sp_getapplock Very promising! 9 | Switching to sp_getapplock

10 What is sp_getapplock? Built into SQL Server
No single point of contention Not a table! Held in memory Session/Transaction MSSQLSERVER likes this 10 | Using sp_getapplock

11 More on sp_getapplock Why do we need locking? No timestamp or duration
Concurrency Immediate resolution Timeout available No timestamp or duration Requires application development to use ACID test needs locking Shared, Update, IntentShared, IntentExclusive, or Exclusive. Value Result 0The lock was successfully granted synchronously. 1The lock was granted successfully after waiting for other incompatible locks to be released. -1The lock request timed out. -2The lock request was canceled. -3The lock request was chosen as a deadlock victim. -999Indicates a parameter validation or other call error. 11 | Using sp_getapplock

12 Demo of Performance Old Application_lock New style sp_getapplock
Stats/duration What locks are being used? New style sp_getapplock Some oddities discovered 12 | Demo’s

13 DEMOS

14 What’s Next? To maintain a VIEW instead of a table
Old procedures Query performance Lost timestamp Old habits/Troubleshooting Session mode was default Transaction mode difficulties 14 | What’s next?

15 Future Additions Switching to transactional locking
Better management Using tempdb for less TLOG as well Code changes to use APPLOCK_MODE DELETE VIEW Continued performance tweaks 15 | What’s next?

16 Summary Application locking can be tricky
No one best way Pro/Con Table Sp_getapplock has its uses LOCKING Able to be integrated into current code Without much pain Albatross to carry 16 | Summary

17 Questions? Microsoft Connect: http://bit.ly/2dpGFri
Glenn Berry wait stats – Remus Rusanu - Paul Randal - MSSQL Server 2014 Unleashed - Tech NET - Microsoft Connect: 17 | Q/A


Download ppt "Lock, Block, and Two Smoking CPUs"

Similar presentations


Ads by Google