Download PDF
Download page Thread Contention.
Thread Contention
Works with:
Thread contention arises when two or more threads attempt to access the same resource at the same time. This page describes how AppDynamics helps you diagnose and resolve thread contention issues.
Performance Issues Resulting from Thread Contention
Multithreaded programming techniques are common in applications that require asynchronous processing. Although each thread has its own call stack in such applications, threads may need to access shared resources, such as a lock, cache, or counter. See Enabling Thread Correlation.
While synchronization techniques can help to prevent interference between threads in such scenarios, they may nevertheless compete for access to shared resources. This can result in application performance degradation or even data integrity issues.
AppDynamics can help you identify and resolve problems relating to thread contention in business transactions and service endpoints. See Trace Multithreaded Transactions for Java.
Thread Contention Detection
AppDynamics detects thread contention based on the thread state of the instrumented application.
It identifies these block or waiting states in the JVM:
- Acquiring a lock (
MONITOR_WAIT
) - Waiting for a condition (
CONDOR_WAIT
) - Sleeping (
OBJECT_WAIT
) - A blocking I/O operation
The OBJECT_WAIT
state is triggered when the application makes one of the following calls:
Thread.sleep
Object.wait
Thread.join
LockSupport.parkNano
sLockSupport.parkUntil
LockSupport.park
The Controller alerts you to possible thread contention problems in the Potential Issues pane of the Business Transaction Flow Map. From there, you can use the browser to access additional information about blocked and waiting threads in business transactions or service endpoints, and determine the cause of the performance problem.
The following sections explain how you use the browser to surface contention information for business transaction and service endpoints.
Thread Contention in Transaction Snapshots
To view information about thread contention:
- In the transaction snapshot navigation page, look for items labeled as Thread Contention issues in the Potential Issues pane. The time column indicates blocked or wait time:
- To display more information about the blocked method, click the thread contention item and select Drill Down into Call Graph:
The call graph shows the following information relevant to thread contention:- In the Call Graph header, Wait Time and Block Time indicate aggregate measures for the thread in one segment of the business transaction.
- In the Call Graph header, Node specifies the name of the node hosting the contending threads,
PojoNode
in the example above. - The Time column indicates the total self time for the method.
- The Percent% column shows the amount of time spent in the method as a percentage of overall time for the thread.
The Thread State Column indicates the degree of thread contention issues for the method. Gray means no problems; yellow to red shading signals the severity of contention problems.
(When you hover over the bar, a breakdown of the elements that make up the thread state is shown: This includes Block time and Wait time by default. To include Cpu Time in the Thread State detail, Dev mode must be enabled.)
- Right-click on any method with a thread state that indicates block or wait times and select View Details. The Thread Contention details pane appears:
The Thread Contention details pane displays the name of the blocked method in the top left corner and adds the following information in the Thread Contention table:
Element Meaning Blocking Thread The thread holding a lock on the blocking object. Blocking Object The object that the blocked thread is waiting to access. Block Time The amount of time waiting to access the object. Line Number The line number in the blocked method where the blocking object is being accessed.
With respect to the example above,run
is attempting to access a locked object at line 114.The order in which blocking threads are shown in the table is not significant; it does not imply a call order or time sequence.
In development mode, AppDynamics reports explicit locks such as java.util.concurrent.locks.ReentrantLock
as Wait Time instead of Block Time in the Thread Details Call Graph view. Take this into consideration when monitoring business transactions and analyzing performance related to lock contentions.
Thread Contention in Service Endpoints
You can view thread contention information for service endpoint methods in AppDynamics. Call graphs identify service endpoint methods with this icon: .
Select More > Service Endpoints from the menu bar to view thread contention information by service endpoint.
Export Contention Information
When you export the Call Graph for a Business Transaction, AppDynamics includes Transaction Contention information.
- The Summary pane includes Block Time data: the block time specified is the sum of all block times for the blocked methods shown in the CallGraph pane.
- The Call Graph pane lists block time by method: