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.

Chapter 4: Transactions<br />

As noted, this is normal behavior but, in conditions of highly concurrent user access, the<br />

potential for blocking will increase. The situation will be exacerbated, for example, by<br />

transactions that are longer than they need to be or are poorly written, causing locks to<br />

be held for longer than necessary. As locking and blocking increase, so does the overhead<br />

on the RDBMS and the end result is a significant reduction in concurrency.<br />

READ UNCOMMITTED – Don't do it<br />

If you want concurrency at all costs, then READ UNCOMMITTED isolation level will shun locks as far as<br />

possible. This mode allows dirty reads, so use it at the expense of your data consistency and integrity.<br />

In READ COMMITTED mode, shared read locks are released as soon as a query completes,<br />

so data modification transactions can proceed at that point, even if the transaction to<br />

which the query belongs is still open. Therefore, non-repeatable reads are possible; if the<br />

same data is read twice in the same transaction, the answer may be different. If this is not<br />

acceptable, the isolation level can be made more restrictive. The REPEATABLE READ level<br />

will ensure that all the rows that were read cannot be modified or deleted until the<br />

transaction which reads them completes. However, even this level does not prevent new<br />

rows (called phantom rows) being inserted that satisfy the query criteria, meaning that<br />

reads are not, in the true sense, repeatable. To prevent this, you could switch to<br />

SERIALIZABLE, the most restrictive isolation level of all, which basically ensures<br />

that a transaction is completely isolated from the effects of any other transaction in<br />

the database.<br />

However, as the isolation level becomes more restrictive, so the use of locks becomes<br />

more prevalent and the likelihood of blocking, and even deadlocking, where transaction<br />

A is waiting for a resource that is held by B and vice versa, increases dramatically. Note<br />

also, that it is not only competing modifications that can cause a deadlock. It is just as<br />

possible for a modification to deadlock <strong>with</strong> a reporting query.<br />

118

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

Saved successfully!

Ooh no, something went wrong!