SQL Server Blocking
By default, the monitoring of Process Blocking is disabled in Teratrax
Performance Monitor. You can
enable block capturing from the Defaults tab in Monitoring Agent for a
short period of time to detect blocking. Results of monitoring will be
available for you to analyze at any time. Teratrax does not recommend
permanent monitoring of SQL Server blocking because it increases the
frequency of database access performed by the Monitoring Agent.
You can view SQL Server blocking activity from the Process Blocking
node in Server Explorer. By default, the pane reports all SQL Server
blocks that took longer than 5 seconds. You can change the default from the Defaults tab in Monitoring Agent.
Block Details
The Process Blocking node displays a list of all SQL Server Blocking
events. For detailed information about an individual block, select the
block in the list to view its details in the lower part of the screen.
SQL Server Blocks
SQL Server blocking occurs when one connection (user process or application
process)
places a lock on a table (or a number of rows) and a second connection
attempts to read or modify the data under the lock. Depending on the
type of the lock, this can cause the second connection to wait until the
first connection releases its lock. A blocked connection waits
indefinitely for the blocking connection to release its lock.
The more blocking happens on the server the less concurrency the
system achieves. A certain amount of blocking is unavoidable but too
many blocks for longer periods of time can degrade the performance of
SQL Server.
SQL Server Deadlocks
The combination of two blocked connections where the first is
blocking the second and the second is blocking the first is called a
deadlock. Since deadlocks are not naturally resolved with time, SQL Server
automatically kills one of the connection (Deadlock victim) once it detects a deadlock.
This allows the
other connection to continue with its transaction.
Although deadlocks can be caused by two short blocks (Fraction of a
second), it is often the long blocks that increase the chances of a
deadlock to happen. Teratrax Performance Monitor does not detect
deadlocks but it provides you with enough information on long blocks
(Origin, SQL code, etc...) in order for you to fix them and consequently
decrease the possibilities of deadlocks.
Blocks Escalating to Deadlocks
The following diagram shows the sequence of events leading to a
deadlock. Consider two applications (A1, A2) accessing two different
table (T1, T2):

Event 1: A1 places a lock on T1 inside its transaction and
continues to execute other statements
Event 2: A2 places a lock on T2 inside its transaction and
continues to execute other statements
Event 3: A1 attempts to place a lock on T2 (Needs to access T2
before it can finish the transaction) but has to wait for A2 to release
its lock
At this point, a block is created since A2 is
blocking A1
Event 4: While A1 is waiting, A2 attempts to place a lock on
T1 (Needs to access T1 before it can finish its own transaction)
A deadlock is created since two connections
have blocked one another. SQL Server automatically resolves the deadlock by choosing one of
the connections as a deadlock victim and killing it.
|