SlideShare une entreprise Scribd logo
1  sur  22
Locking and Blocking with SQL Server Choosing a concurrency Model – Optimistic or Pessimistic Vinod Kumar M Technology Evangelist - Microsoft www.ExtremeExperts.com http://blogs.sqlxml.org/vinodkumar
Why Study Concurrency? Contention Degrades Performance Most Tuning Tools Don’t Consider Concurrency Issues You Can Write Better Applications
Concurrency Models Pessimistic Concurrency Preventative approach Limited concurrent access Uses locking to avoid conflicts Optimistic Concurrency Allows full concurrent access Row versioning allows access to consistent data Conflict detection avoids inconsistent updates
Transactions in SQL Server  Transaction Basics Preventable Phenomena
Transaction Basics Allow Correctness of Operations To Be Verified Exhibit Four Properties (ACID): Atomicity Consistency Isolation Durability
PreventablePhenomena Lost Updates Dirty Reads Non-Repeatable Reads Phantoms
Read X (10) Compute X=X+15 (25) Write X Compute X=X+10 (20) Read X (10) Write X Classic unsynchronized update T1 X=20 X=25 X=10 X=25 Time T2 Lost Update
Read X (10) Compute X=X+15 (25) Rollback Use value ofX that was nevercommitted to DB Read X (25) Write X T2 sees effects of T1 that were never committed T1 X=10 X=25 X=10 Time T2 Dirty Read
Read X (10) Compute X=X+15 (25) Commit Read X (10) Read X (25) Non-Repeatable Read Transaction sees only committed data but data changes when referenced multiple times T1 Write X X=10 X=25 Time T2
Jones,6 Insert The “Phantom” Problem Transaction’s input set defined  by a predicate Transaction should not see additions/deletions from input set Must prevent other transactions from inserting even if we don’t see the effects! T1 Jones,6 Smith,4 Smith,4 Time Brewer,7 Brewer,7 Select count (*) where rank > 3 (2) Select count (*) where rank > 3 (3) T2
IsolationLevels True Isolation Is Expensive  Trade off between correctness and concurrency ANSI SQL Defines Four Isolation Levels based on which phenomena are allowed No specification as to how to achieve isolation SQL Server 2000 implements all ANSI isolation levels using Pessimistic Concurrency Model SQL Server 2005 provides Optimistic Concurrency Alternatives Optimistic implementation of read committed New Snapshot Isolation
SQL2008IsolationLevels ,[object Object],Phenomena Allowed
Locking Decision Current Activity Isolationlevel Scan type(Range, Table, Probe) Locking strategy(Table, Page, Row) # of rows in scan # of rows/page Operation type (scan, update) Lock hints sp_IndexOption Settings
Pessimistic Concurrency Control Aspects of Locking Blocking Controlling Locking
Aspects of Locking Type of Lock Duration of Lock Granularity of Lock
Blocking Occurs when one process requests a lock on the same resource held by another process in an incompatible mode Blocking and Isolation Summary for Pessimistic Concurrency Writers block writers in all levels Writers block readers in Read Committed and higher Readers block writers in Repeatable Read and higher
Deadlock What is Deadlock? Handling Deadlock
Process 1 X Resource A Resource B X Process 2 WhatisDeadlock? Two Processes Mutually Blocking Each Other
Blocked Process Threshold Generates an event when a task(s) blocked for greater than ‘threshold’ ‘Threshold’ is a configurable option There is a background thread (Lock Monitor) that periodically checks tasks that are blocked. You can use event to identify tasks
Demo: Blocked Process Threshold
Summary Concurrency Models Transactions in SQL Server  Isolation Levels Pessimistic Concurrency Control Optimistic Concurrency Control
Additional Resources Inside SQL Server 2005:        The Storage Engine (Microsoft Press, available now) Blogs: http://blogs.msdn.com/sqlserverstorageengine http://blogs.msdn.com/sqltips http://blogs.msdn.com/sqlcat http://sqlblog.com/blogs/kalen_delaney Scripts available at  www.InsideSQLServer.com/conferences http://sqlblog.com/blogs/kalen_delaney

Contenu connexe

Tendances

Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyBoris Hristov
 
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgradeDevelopers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrademCloud
 
Intro to tsql unit 12
Intro to tsql   unit 12Intro to tsql   unit 12
Intro to tsql unit 12Syed Asrarali
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6Syed Asrarali
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSeerat Malik
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton patternbabak danyal
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern PresentationJAINIK PATEL
 

Tendances (10)

Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
 
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgradeDevelopers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
Developers’ mDay 2019. - Bogdan Kecman, Oracle – MySQL 8.0 – why upgrade
 
Intro to tsql unit 12
Intro to tsql   unit 12Intro to tsql   unit 12
Intro to tsql unit 12
 
Intro to tsql unit 6
Intro to tsql   unit 6Intro to tsql   unit 6
Intro to tsql unit 6
 
Singleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation PatternSingleton Design Pattern - Creation Pattern
Singleton Design Pattern - Creation Pattern
 
Flex
FlexFlex
Flex
 
Observer & singleton pattern
Observer  & singleton patternObserver  & singleton pattern
Observer & singleton pattern
 
The Singleton Pattern Presentation
The Singleton Pattern PresentationThe Singleton Pattern Presentation
The Singleton Pattern Presentation
 
Intro to tsql
Intro to tsqlIntro to tsql
Intro to tsql
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 

Similaire à Choosing A Concurrency Model, Optimistic Or Pessimistic

Choosing a concurrency model, optimistic or pessimistic
Choosing a concurrency model, optimistic or pessimisticChoosing a concurrency model, optimistic or pessimistic
Choosing a concurrency model, optimistic or pessimisticVinod Kumar
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Oliersqlserver.co.il
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
 
Locking and Race Conditions in Web Applications
Locking and Race Conditions in Web ApplicationsLocking and Race Conditions in Web Applications
Locking and Race Conditions in Web ApplicationsAndrew Kandels
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql ServerRishikesh Tiwari
 
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionSQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionMark Broadbent
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsBoris Hristov
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
 
Lecture-04-Principles of data management.pdf
Lecture-04-Principles of data management.pdfLecture-04-Principles of data management.pdf
Lecture-04-Principles of data management.pdfmanimozhi98
 
arch_mtg_sqlsig_hcotter_replication.ppt
arch_mtg_sqlsig_hcotter_replication.pptarch_mtg_sqlsig_hcotter_replication.ppt
arch_mtg_sqlsig_hcotter_replication.pptssuser418eef
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsVlad Mihalcea
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!Boris Hristov
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...MSDEVMTL
 
Scalable Service Architectures
Scalable Service ArchitecturesScalable Service Architectures
Scalable Service ArchitecturesZoltán Németh
 
20141021 AWS Cloud Taekwon - Startup Best Practices on AWS
20141021 AWS Cloud Taekwon - Startup Best Practices on AWS20141021 AWS Cloud Taekwon - Startup Best Practices on AWS
20141021 AWS Cloud Taekwon - Startup Best Practices on AWSAmazon Web Services Korea
 
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...Spark Summit
 
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang Phi
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang PhiIntroduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang Phi
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang PhiHo Chi Minh City Software Testing Club
 
Shopzilla On Concurrency
Shopzilla On ConcurrencyShopzilla On Concurrency
Shopzilla On ConcurrencyWill Gage
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developerswebhostingguy
 

Similaire à Choosing A Concurrency Model, Optimistic Or Pessimistic (20)

Choosing a concurrency model, optimistic or pessimistic
Choosing a concurrency model, optimistic or pessimisticChoosing a concurrency model, optimistic or pessimistic
Choosing a concurrency model, optimistic or pessimistic
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
 
Locking and Race Conditions in Web Applications
Locking and Race Conditions in Web ApplicationsLocking and Race Conditions in Web Applications
Locking and Race Conditions in Web Applications
 
High Availbilty In Sql Server
High Availbilty In Sql ServerHigh Availbilty In Sql Server
High Availbilty In Sql Server
 
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 EditionSQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
SQL Server AlwaysOn for Dummies SQLSaturday #202 Edition
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
 
Lecture-04-Principles of data management.pdf
Lecture-04-Principles of data management.pdfLecture-04-Principles of data management.pdf
Lecture-04-Principles of data management.pdf
 
arch_mtg_sqlsig_hcotter_replication.ppt
arch_mtg_sqlsig_hcotter_replication.pptarch_mtg_sqlsig_hcotter_replication.ppt
arch_mtg_sqlsig_hcotter_replication.ppt
 
Transactions and Concurrency Control Patterns
Transactions and Concurrency Control PatternsTransactions and Concurrency Control Patterns
Transactions and Concurrency Control Patterns
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
 
Scalable Service Architectures
Scalable Service ArchitecturesScalable Service Architectures
Scalable Service Architectures
 
20141021 AWS Cloud Taekwon - Startup Best Practices on AWS
20141021 AWS Cloud Taekwon - Startup Best Practices on AWS20141021 AWS Cloud Taekwon - Startup Best Practices on AWS
20141021 AWS Cloud Taekwon - Startup Best Practices on AWS
 
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...
Clipper: A Low-Latency Online Prediction Serving System: Spark Summit East ta...
 
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang Phi
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang PhiIntroduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang Phi
Introduction to Back End Automation Testing - Nguyen Vu Hoang, Hoang Phi
 
Shopzilla On Concurrency
Shopzilla On ConcurrencyShopzilla On Concurrency
Shopzilla On Concurrency
 
SQLCLR For DBAs and Developers
SQLCLR For DBAs and DevelopersSQLCLR For DBAs and Developers
SQLCLR For DBAs and Developers
 

Plus de Vinod Kumar

Backup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL ServerBackup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL ServerVinod Kumar
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query PerformanceSQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query PerformanceVinod Kumar
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverAdvanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverVinod Kumar
 
Sql Server Security
Sql Server SecuritySql Server Security
Sql Server SecurityVinod Kumar
 
Windows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastWindows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastVinod Kumar
 
Protecting Your Key Asset – Data Protection Best Practices V2.0 Final
Protecting Your Key Asset – Data Protection Best Practices V2.0   FinalProtecting Your Key Asset – Data Protection Best Practices V2.0   Final
Protecting Your Key Asset – Data Protection Best Practices V2.0 FinalVinod Kumar
 

Plus de Vinod Kumar (6)

Backup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL ServerBackup beyond just a strategy with SQL Server
Backup beyond just a strategy with SQL Server
 
SQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query PerformanceSQL Server Query Optimization, Execution and Debugging Query Performance
SQL Server Query Optimization, Execution and Debugging Query Performance
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverAdvanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql server
 
Sql Server Security
Sql Server SecuritySql Server Security
Sql Server Security
 
Windows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage WebcastWindows Mobile 5.0 Data Access And Storage Webcast
Windows Mobile 5.0 Data Access And Storage Webcast
 
Protecting Your Key Asset – Data Protection Best Practices V2.0 Final
Protecting Your Key Asset – Data Protection Best Practices V2.0   FinalProtecting Your Key Asset – Data Protection Best Practices V2.0   Final
Protecting Your Key Asset – Data Protection Best Practices V2.0 Final
 

Dernier

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterMateoGardella
 

Dernier (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 

Choosing A Concurrency Model, Optimistic Or Pessimistic

  • 1. Locking and Blocking with SQL Server Choosing a concurrency Model – Optimistic or Pessimistic Vinod Kumar M Technology Evangelist - Microsoft www.ExtremeExperts.com http://blogs.sqlxml.org/vinodkumar
  • 2. Why Study Concurrency? Contention Degrades Performance Most Tuning Tools Don’t Consider Concurrency Issues You Can Write Better Applications
  • 3. Concurrency Models Pessimistic Concurrency Preventative approach Limited concurrent access Uses locking to avoid conflicts Optimistic Concurrency Allows full concurrent access Row versioning allows access to consistent data Conflict detection avoids inconsistent updates
  • 4. Transactions in SQL Server Transaction Basics Preventable Phenomena
  • 5. Transaction Basics Allow Correctness of Operations To Be Verified Exhibit Four Properties (ACID): Atomicity Consistency Isolation Durability
  • 6. PreventablePhenomena Lost Updates Dirty Reads Non-Repeatable Reads Phantoms
  • 7. Read X (10) Compute X=X+15 (25) Write X Compute X=X+10 (20) Read X (10) Write X Classic unsynchronized update T1 X=20 X=25 X=10 X=25 Time T2 Lost Update
  • 8. Read X (10) Compute X=X+15 (25) Rollback Use value ofX that was nevercommitted to DB Read X (25) Write X T2 sees effects of T1 that were never committed T1 X=10 X=25 X=10 Time T2 Dirty Read
  • 9. Read X (10) Compute X=X+15 (25) Commit Read X (10) Read X (25) Non-Repeatable Read Transaction sees only committed data but data changes when referenced multiple times T1 Write X X=10 X=25 Time T2
  • 10. Jones,6 Insert The “Phantom” Problem Transaction’s input set defined by a predicate Transaction should not see additions/deletions from input set Must prevent other transactions from inserting even if we don’t see the effects! T1 Jones,6 Smith,4 Smith,4 Time Brewer,7 Brewer,7 Select count (*) where rank > 3 (2) Select count (*) where rank > 3 (3) T2
  • 11. IsolationLevels True Isolation Is Expensive Trade off between correctness and concurrency ANSI SQL Defines Four Isolation Levels based on which phenomena are allowed No specification as to how to achieve isolation SQL Server 2000 implements all ANSI isolation levels using Pessimistic Concurrency Model SQL Server 2005 provides Optimistic Concurrency Alternatives Optimistic implementation of read committed New Snapshot Isolation
  • 12.
  • 13. Locking Decision Current Activity Isolationlevel Scan type(Range, Table, Probe) Locking strategy(Table, Page, Row) # of rows in scan # of rows/page Operation type (scan, update) Lock hints sp_IndexOption Settings
  • 14. Pessimistic Concurrency Control Aspects of Locking Blocking Controlling Locking
  • 15. Aspects of Locking Type of Lock Duration of Lock Granularity of Lock
  • 16. Blocking Occurs when one process requests a lock on the same resource held by another process in an incompatible mode Blocking and Isolation Summary for Pessimistic Concurrency Writers block writers in all levels Writers block readers in Read Committed and higher Readers block writers in Repeatable Read and higher
  • 17. Deadlock What is Deadlock? Handling Deadlock
  • 18. Process 1 X Resource A Resource B X Process 2 WhatisDeadlock? Two Processes Mutually Blocking Each Other
  • 19. Blocked Process Threshold Generates an event when a task(s) blocked for greater than ‘threshold’ ‘Threshold’ is a configurable option There is a background thread (Lock Monitor) that periodically checks tasks that are blocked. You can use event to identify tasks
  • 21. Summary Concurrency Models Transactions in SQL Server Isolation Levels Pessimistic Concurrency Control Optimistic Concurrency Control
  • 22. Additional Resources Inside SQL Server 2005: The Storage Engine (Microsoft Press, available now) Blogs: http://blogs.msdn.com/sqlserverstorageengine http://blogs.msdn.com/sqltips http://blogs.msdn.com/sqlcat http://sqlblog.com/blogs/kalen_delaney Scripts available at www.InsideSQLServer.com/conferences http://sqlblog.com/blogs/kalen_delaney