Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy.

Slides:



Advertisements
Similar presentations
Optimistic Methods for Concurrency Control By : H.T. Kung & John T. Robinson Presenters: Munawer Saeed.
Advertisements

SQL Server AlwaysOn: Active Secondaries Luis Vargas Program Manager Microsoft Corporation DBI312.
Transaction Processing. Objectives After completing this lesson, you should be able to do the following: –Define transactions effectively for an application.
Module 20 Troubleshooting Common SQL Server 2008 R2 Administrative Issues.
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
9 Copyright © 2009, Oracle. All rights reserved. Managing Data Concurrency.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Allowing Multi-user Access Grant – GRANT ON TO – |WITH GRANT OPTION / WITH ADMIN OPTION| – can be PUBLIC or a role – can be all Revoke – REVOKE ON FROM.
BIS Database Systems School of Management, Business Information Systems, Assumption University A.Thanop Somprasong Chapter # 10 Transaction Management.
1099 Why Use InterBase? Bill Todd The Database Group, Inc.
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
Concurrency and Transaction Processing. Concurrency models 1. Pessimistic –avoids conflicts by acquiring locks on data that is being read, so no other.
Unit 9 Transaction Processing. Key Concepts Distributed databases and DDBMS Distributed database advantages. Distributed database disadvantages Using.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
Transactions and Locks A Quick Reference and Summary BIT 275.
Random Logic l Forum.NET l Transaction Isolation Levels Forum.NET Meeting ● Nov
SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant 26 th.
Module 6: Data Protection. Overview What does Data Protection include? Protecting data from unauthorized users and authorized users who are trying to.
Roy Ernest Database Administrator Pinnacle Sports Worldwide
Connect with life Vinod Kumar Technology Evangelist - Microsoft
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
10 Managing Rollback Segments Objectives Planning the number and size of rollback segments Creating rollback segments using appropriate storage.
Module 11: Managing Transactions and Locks
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Deadlocks 3.0. Final Edition. Everything that developer needs to know Denis Reznik Microsoft SQL Server MVP Director of R&D at Intapp Kyiv.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
Read Dirty to Me: SQL Server Isolation Levels Wendy Pastrick Arrow IT Consulting.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Session Name Pelin ATICI SQL Premier Field Engineer.
SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15.
Database Transactions  Transaction Management and Concurrency Control.
Memory-Optimized Tables Querying at the speed of light.
DBMS & TPS Barbara Russell MBA 624.
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Database Transactions
Transaction Management and Concurrency Control
Let Me Finish... Isolating Write Operations
LAB: Web-scale Data Management on a Cloud
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Tech Ed North America /23/2018 1:32 AM Required Slide
Isolation Levels Understanding Transaction Temper Tantrums
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
Working with Very Large Tables Like a Pro in SQL Server 2014
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Optimistic Concurrency Internals
Everything you ever wanted to ask but were too shy
Transactions, Locking and Query Optimisation
When I Use NOLOCK AND OTHER HINTS
Understanding Transaction Isolation Levels
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
When I Use NOLOCK AND OTHER HINTS
Locks, Blocks, Deadlocks
Transactions and Concurrency
Deadlocks Everything you ever wanted to ask but were too shy
Sioux Falls, SD | Hosted by (605) SQL
A Masters view on Locking and blocking
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
A Masters view on Locking and blocking
Presentation transcript:

Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy

About me Working with SQL Server from v6.5 SQL Server Trainer and Consultant with over 60 projects in Bulgaria, Finland, Germany, UK, Sweden… 5 years Senior Consultant in Microsoft, member of Microsoft Worldwide Technical Leadership Team BG SQL UG Founder and Leader Now teaching and presenting SQL Server, running SQL Master Academy Training Program - and SQL Server consulting company -

What’s the problem –The blocking drama and how to isolate it –The main reason, the common occurrence How we are used to resolve the problems while working with pessimistic concurrency levels –Some working and not so well working solutions Optimistic Concurrency –how it works, when it could be a solution and in what cases it could generate problems –Side effects and thinks to consider Approaching the blocking today

Locking and blocking are often confused! Locking The action of taking and potentially holding locks Used to implement concurrency control between transactions Blocking is a result of long time locking! One process needs to wait for another process to release locked resources In a multiuser environment, there is always blocking! Only a problem if it lasts too long The drama of blocking

Blocking and how to get info about it DEMO

Writers block readers and vise versa Resource blocking - performance Lock escalation Lock duration Default pessimistic isolation level – holding eXclusive lock too early Increasing isolation level to RR because the need of consistent reading Serializable specific cases – no index or using EF Schema blocking Writers block writers (concurrent writing – OLTP) The common reasons of blocking

Controlling lock escalation with ALTER TABLE –ALTER TABLE Person.Address SET (LOCK_ESCALATION = {AUTO | TABLE | DISABLE) –Trace flag 1211 – disables lock escalation on server level –Trace flag 1224 – disables lock escalation on server level until 40% of the memory used is consumed Controlling Lock duration with SET LOCK TIMEOUT n(sec) –Error 1222!!! Reading dirty data with hints – NO_LOCK, READPAST –Data consistency!! How we are used to deal with blocking in pessimistic concurrency None of them is a good solutions!

How we are used to deal with blocking in pessimistic concurrency Consider solutions design changes –Partitioning –Workload separation using 2012 AG or other technologies like replication –In Memory OLTP tables in SQL Server 2014 OK, but it takes additional resources!

Based on Row versioning –When updating a row, the previous version is stored in the version store –The new row contains a pointer to the old row in the version store Adds 14bytes to every row Needs Version Store i.e. TempDB space Readers do not block writers and writers do not block readers. BUT writers can and will block writers, this can cause conflicts. Optimistic Concurrency V1 V2 Transaction 1 Transaction 2 Select

Implementation – RCSI and SI RCSI –Statement-Level versioning, i.e. any query sees the last version of data as of the beginning of the statement –Requires ALTER ATABASE SET READ_COMMITTED_SNAPSHOT ON V1 V2 Transaction 1 Transaction 2 Select in RCSI Select Select in SI Snapshot Isolation Level –Session Level versioning, i.e. the most recent committed version of the rows as of the beginning of the transaction –Requires ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON and SET TRANSACTION ISOLATION LEVEL SNAPSHOT –If used then better together with RCSI! Else, you have drawbacks of versioning only! –Conflicts occur!! –Some DDL statements are not allowed within SI transactions (no metadata versioning exists)

DEMO Optimistic Concurrency

The Version Store –SQL Server starts generating versions in tempdb as soon as a database is enabled for one of the snapshot-based isolation levels –Maintains link lists of rows, the end of the list is the oldest version of that particular row Managing Version Store –SQL Server maintains a clean-up thread –If file cannot grow, a snapshot query fails (tempdb growth errors) –Monitoring counters Free Space in tempdb Version Store Size Version Generation Rate and Version Cleanup Rate Longest Transaction Running Time Snapshot Transactions Managing Version store [size of common version store] = 2 * [version store data generated per minute] * [longest running time (minutes) of the transaction]

RCSI –Consumes less tempdb space than SI –Works with distributed transactions; SI does not –Does not produce update conflicts –Does not require any change in your applications. Any of your applications written using the default Read Committed isolation level automatically uses RCSI after making the change at the database level (you should always test first, check the complex Begin..commits) Consider using SI when –The probability is low that any of your transactions have to be rolled back because of an update conflict. –You have reports that need to be generated based on long-running, multistatement queries that must have point-in-time consistency Choosing a Concurrency Model

SELECT operations do not acquire shared locks, so readers and writers do not block each other. All SELECT operations retrieve a consistent snapshot of the data. The total number of locks needed is greatly reduced compared to pessimistic concurrency, so less system overhead is used. SQL Server needs to perform fewer lock escalations. Deadlocks are less likely to occur Benefits of Optimistic Concurrency

SELECT performance can be affected negatively when long-version chains must be scanned. The older the snapshot, the more time it takes to access the required row in an SI transaction. Row versioning requires additional resources in tempdb. The space in tempdb must be carefully managed Row versioning information increases the size of every affected row by 14 bytes. UPDATE performance might be slower due to the work involved in maintaining the row versions Applications must be programmed to deal with any update conflicts that occur in SI Costs of Optimistic Concurrency 15

Writers block writers cases in high intensive OLTP workloads Resource blockings (you need to perform resource optimizations first) Lock escalation (especially X locks) Schema blocking In-Memory OLTP Memory-optimized Tables is a special case! What optimistic concurrency doesn’t resolve

Thank you! naumova/9/965/206