30.06.2013 Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

Performance Tuning with SQL Server Dynamic Management Views

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

117<br />

Chapter 4: Transactions<br />

unique transaction_id in our result sets. All statements executed <strong>with</strong>in an explicit<br />

transaction will be reported <strong>with</strong> a single transaction_id.<br />

<strong>SQL</strong> <strong>Server</strong> will attempt to ensure that each unit of work, be it a single-statement implicit<br />

transaction, or any number of individual <strong>SQL</strong> statements <strong>with</strong>in an explicit transaction,<br />

conforms to the ACID test characteristics.<br />

What we hope to demonstrate in this chapter is how to observe these units of work via<br />

the DMOs. Since the lifespan of these transactions is measured in milliseconds, when<br />

everything is going right the focus will be on those transactions that are having difficulty<br />

completing in a timely fashion, whether due to contention for resources, poor tuning, or<br />

other issues.<br />

Investigating Locking and Blocking<br />

Locking is an integral aspect of any RDBMS. Locks control how transactions are allowed<br />

to interact, impact, and impede one another when running simultaneously against<br />

common objects. Unless you restrict data access to one user at a time, clearly not a<br />

viable option, locks are necessary to the smooth functioning of any RDBMS.<br />

Locks are to be neither feared nor shunned but they can, nevertheless, cause problems<br />

for the reckless or unwary. When using <strong>SQL</strong> <strong>Server</strong>'s default isolation level, READ<br />

COMMITTED, shared read locks are acquired during data reads. These locks prevent<br />

another transaction from modifying that data while the query is in progress, but do not<br />

block other readers. Furthermore, "dirty reads" are forbidden, so <strong>SQL</strong> <strong>Server</strong> acquires<br />

exclusive locks during updates, to prevent a transaction from reading data that has been<br />

modified by another transaction, but not committed. Of course, this means that if one<br />

transaction (A) encounters data that is being modified by another transaction (B), then<br />

transaction A is blocked; it needs access to a resource that is locked by B and cannot<br />

proceed until B either commits or rolls back.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!