Lock, Block, and Two Smoking CPUs

Slides:



Advertisements
Similar presentations
CM20145 Concurrency Control
Advertisements

1 Chapter 10 Protecting Data Integrity in a Multiuser Environment.
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Accessing data Transactions. Agenda Questions from last class? Transactions concurrency Locking rollback.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Module 20 Troubleshooting Common SQL Server 2008 R2 Administrative Issues.
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
More on transactions…. Dealing with concurrency (OR: how to handle the pressure!) Locking Timestamp ordering Multiversion protocols Optimistic protocols.
ACS-4902 R. McFadyen 1 Database Concurrency Control Deadlock Deadlock occurs when each transaction in a set is waiting for another transaction in the set.
CS533 - Concepts of Operating Systems 1 CS533 Concepts of Operating Systems Class 8 Synchronization on Multiprocessors.
9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Transactions and Locks Lesson 22. Skills Matrix Transaction A transaction is a series of steps that perform a logical unit of work. Transactions must.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
Profiles, Password Policies, Privileges, and Roles
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
Chapter 11 Concurrency Control. Lock-Based Protocols  A lock is a mechanism to control concurrent access to a data item  Data items can be locked in.
Concurrency Control Concurrency Control By Dr.S.Sridhar, Ph.D.(JNUD), RACI(Paris, NICE), RMR(USA), RZFM(Germany) DIRECTOR ARUNAI ENGINEERING COLLEGE TIRUVANNAMALAI.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
8 Copyright © 2005, Oracle. All rights reserved. Managing Data.
Transactions and Locks A Quick Reference and Summary BIT 275.
Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
CIS-NG CASREP Information System Next Generation Shawn Baugh Amy Ramirez Amy Lee Alex Sanin Sam Avanessians.
SQL Advanced Monitoring Using DMV, Extended Events and Service Broker Javier Villegas – DBA | MCP | MCTS.
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
COMP 430 Intro. to Database Systems Transactions, concurrency, & ACID.
CSC314 Day 16 Transaction processing Concurrency Control 1.
Session Name Pelin ATICI SQL Premier Field Engineer.
SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15.
Use Cases for In-Memory OLTP Warner Chaves SQL MCM / MVP SQLTurbo.com Pythian.com.
Curacao SQL Saturday June 11, 2016
Building a Performance Monitoring System using XEvents and DMVs
SQL – Transactions in SQLite
Renaming Databases I was thinking of using a few other titles, “There and Lock again, A DBA’s holiday”
Let Me Finish... Isolating Write Operations
Building a Performance Monitoring System using XEvents and DMVs
Concurrency Control.
Isolation Levels Understanding Transaction Temper Tantrums
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
Performance Monitoring Using Extended Events, DMVs & Query Store
Building a Performance Monitoring System using XEvents and DMVs
Simple Partitioning Building a simple partitioning solution with SQL Server Stephen Fulcher.
SQL 2014 In-Memory OLTP What, Why, and How
Batches, Transactions, & Errors
March 9th – Transactions
Transactions, Locking and Query Optimisation
Transactions.
TEMPDB – INTERNALS AND USAGE
Chapter 15 : Concurrency Control
Let Me Finish... Isolating Write Operations
Batches, Transactions, & Errors
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Let Me Finish... Isolating Write Operations
Transactions and Concurrency
Sioux Falls, SD | Hosted by (605) SQL
A Beginners Guide to Transactions
Building a Performance Monitoring System using XEvents and DMVs
Jean Joseph DBA\DEVELOPER
CONCURRENCY Concurrency is the tendency for different tasks to happen at the same time in a system ( mostly interacting with each other ) .   Parallel.
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Using wait stats to determine why my server is slow
Inside the Database Engine
Inside the Database Engine
Inside the Database Engine
Presentation transcript:

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”

Daniel R. Maenle Junior Database Administrator at ScriptPro Twitter: @DantheSQLMan Email: danmaenle@gmail.com Pharmacy for 8+ years OptumRX and ScriptPro Pharmacy IT 6+ years Junior DBA 2 years in January 2 | Introduction

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

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

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

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

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

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

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

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

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

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

DEMOS

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?

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?

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

Questions? Microsoft Connect: http://bit.ly/2dpGFri Glenn Berry wait stats – http://bit.ly/2cN60te Remus Rusanu - http://bit.ly/2cSbmTp Paul Randal - http://bit.ly/2cuph2L MSSQL Server 2014 Unleashed - http://bit.ly/2cDwo6z Tech NET - http://bit.ly/2dk6FnF Email: danmaenle@gmail.com Twitter: @DantheSQLMan Microsoft Connect: http://bit.ly/2dpGFri 17 | Q/A