Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide

Similar presentations


Presentation on theme: "Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide"— Presentation transcript:

1 Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide SESSION CODE: DAT315 Strategies to Get Maximum Concurrency for Your Workload in Microsoft SQL Server Sunil Agarwal Senior Program Manager Microsoft Corporation © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 Goals Concurrency challenges with applications
Identifying and troubleshooting concurrency issues Strategies for creating applications for higher concurrency

3 Common Concurrency Issues with Applications
Wrong transaction isolation level Incorrect locking granularity Missing Indexes Accessing large dataset leading to lock escalation Long running transactions User interactions in active transaction Accessing objects in reverse order across transactions Application induced hotspots

4 Isolation Levels SQL-Standard specifies four isolation levels
SQL Server has implemented these all along using lock based implementation. Read Uncommitted Most concurrent, least restrictive, more anomalies are possible SQL Server: No share locks Read Committed Only reads committed data. Data can change over multiple reads SQL Server: Data access only after acquiring S-lock. Lock released when moved to next row/page Repeatable Read Read rows don’t change. Phantom rows can appear SQL Server: Data access only after acquiring S-lock. Lock released at the end of the transaction Serializable Least concurrent, most restrictive, always ‘correct’ Isolation-levels impact the concurrency SQL2005 introduced RCSI (Read Committed Snapshot) and SI (Snapshot Isolation) using non-blocking implementation.

5 Reader Writer Blocking
Data Page Tran2 (Select) Tran1 (Update) Row-1 Row-1 S-Lock Blocked X-Lock

6 Read Committed Snapshot Statement-Level ‘Snapshot Isolation’
New “flavor” of read committed Turn ON/OFF on a database Readers see committed values as of beginning of statement Writers do not block Readers Readers do not block Writers Writers do block writers Can greatly reduce locking / deadlocking without changing applications

7 Snapshot Isolation Transaction level ‘Snapshot Isolation’
SQL Server proprietary isolation level Turn ON/OFF on a database Available since SQL Server 2005 Readers see committed values as of beginning of the Transaction Writers do not block Readers Readers do not block Writers Writers do block writers Can greatly reduce locking / deadlocking but requires application change Set Transaction Isolation level Snapshot Scenario: Cross query data view consistency

8 Locking Granularity Small lock granules, such as rows:
Maximize concurrency Are expensive to maintain(require many lock manager calls). Approx 100 byte overhead Large granules, such as tables: Expensive in terms of concurrency Cheap to acquire (few lock manager calls) Multi-granular lock protocols allow us to have it both ways Decided at run-time using internal heuristic Can be over-ridden using sp_indexoption or locking hint Lock Escalation

9 Lock Modes Common locking modes Mode Description
S Share - used for reading X Exclusive - typically used for writing (insert, update, delete) U Update - used to evaluate prior to writing IS Intent Share - share locking at finer level IX Intent Exclusive - X locking at finer level BU Bulk Update. Used in Bulk Load SCH-S Schema Share SCH-M Schema modify lock

10 Locking Hints Locking hints are used to Lock duration
Change locking behavior at statement level Example: TABLOCK, UPDLOCK To change isolation level at statement level Examples: NOLOCK, READPAST, TABLOCK, READCOMMITTED, REPEATABLEREAD Lock duration Depends on isolation level it is acquired at.

11 Blocking Detection and Troubleshooting
Tech Ed North America 2010 8/23/2018 1:32 AM Blocking Detection and Troubleshooting Sunil Agarwal Senior Program Manager Microsoft DEMO © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

12 Lock Escalation Lock Escalation HOBT Page Row T1: IX T1: X T1: IX

13 Lock Escalation Converting finer-grain locks to coarse grain locks.
Row to Table Page to Table. No escalation from Row to Page Benefits Reduced locking overhead Reduces Memory requirement. Each lock structure is 100 bytes Impedes concurrency Triggered when Number of locks acquired on a rowset > Periodically after that It is not based on the locks in a transaction Memory pressure

14 Lock Escalation… Cont Controlling Lock Escalation
TF-1211 disables lock escalation for the instance. SQL Server can run out of lock memory TF 1224 disables 5000 limit but keeps lock escalation due to memory pressure. Using ALTER TABLE to disable/enable lock escalation (SQL2008) Allows lock escalation at partition level

15 Lock Escalation Detection and Troubleshooting
Tech Ed North America 2010 8/23/2018 1:32 AM Lock Escalation Detection and Troubleshooting Sunil Agarwal Senior Program Manager Microsoft DEMO © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

16 Silent Blocker: Page Latches
What is a Pagelatch? Schema and access patterns leading to latch contention Clustering index has a increasing primary key with high rate of inserts Relatively small tables with a lot of read/write/delete Indexes with low cardinality in the key with high rate of inserts Allocation Structures (e.g. SGAM) Observed with 16+ concurrent threads Page Header R1 Free Offset R2 R3

17 Silent Blocker: Page Latches
What can you do? Cluster on some other column Partition the table on some other attribute (computed column (hash)) Add another major key column Change the application

18 Page Latch Contention and Troubleshooting
Tech Ed North America 2010 8/23/2018 1:32 AM Page Latch Contention and Troubleshooting Sunil Agarwal Senior Program Manager Microsoft DEMO © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

19 Deadlock Example: User 1 holds X lock on page P1
User 1 requests to acquire SH lock on P2 It waits for User 2 User 2 requests to acquire SH lock on P1 It waits for User 1 Leads to an indefinite wait

20 Deadlock: Detection Background Thread (Lock Monitor)
Runs every 5 seconds (adjusted dynamically) When deadlock detected, a victim is chosen based on Transaction that has done minimum amount of work Deadlock priority. Victim transaction is rolled back and an error 1205 is generated. Deadlock Troubleshooting Use SQL profiler User TF-1204 (SQL2000) TF-1222 (SQL2005)

21 Deadlock Detection and Troubleshooting
Tech Ed North America 2010 8/23/2018 1:32 AM Deadlock Detection and Troubleshooting Sunil Agarwal Senior Program Manager Microsoft DEMO © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

22 Deadlock: Avoidance Access objects/rows in same order
Use lower isolation level Use read-committed-snapshot or snapshot isolation Use shorter duration transactions Watch out for lock escalation

23 Guidelines: Concurrent Application
Choose lowest isolation needed for consistency Use shorter transaction when possible Avoid using larger row sets Break the statement into smaller rowsets Minimize large scans Enable index usage when possible When possible, design to spread DML across multiple pages

24 Summary Balance consistency vs. concurrency
Factors that impact concurrency Troubleshooting Blocking Best practices for developing concurrent applications

25 Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Tech Ed North America 2010 8/23/2018 1:32 AM DAT Track Scratch 2 Win Find the DAT Track Surface Table in the Yellow Section of the TLC Try your luck to win a Zune HD Simply scratch the game pieces on the DAT Track Surface Table and Match 3 Zune HDs to win © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

26 Resources Learning Required Slide www.microsoft.com/teched
Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide Resources Learning Sessions On-Demand & Community Microsoft Certification & Training Resources Resources for IT Professionals Resources for Developers © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

27 Complete an evaluation on CommNet and enter to win!
Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide Complete an evaluation on CommNet and enter to win! © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

28 Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st
You can also register at the North America 2011 kiosk located at registration Join us in Atlanta next year

29 Tech Ed North America 2010 8/23/2018 1:32 AM
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

30 Required Slide Tech Ed North America 2010 8/23/2018 1:32 AM
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Tech Ed North America 2010 8/23/2018 1:32 AM Required Slide"

Similar presentations


Ads by Google