Help Docs

Loop detection support in Java

Site24x7's APM Insight Java agent facilitates loop detection. This feature helps you identify loops in application code that may contain duplicate database queries or consume excessive time, ensuring a more efficient execution of code blocks.

Understanding loops and the need for monitoring

Loops are an essential component of programming that enable developers to execute a set of instructions repeatedly until a specific condition is met. This functionality is vital for performing repetitive tasks, processing data collections, and implementing various algorithms.

However, despite their usefulness, loops can also introduce performance issues if not implemented properly. When loops are executed excessively or contain inefficient logic, they can consume significant processing time and resources, leading to poor user experiences. Poorly written loops can cause application slowdowns, increased load times, and in some cases, even crashes.

To ensure optimal performance, it is crucial for developers to monitor continuously and identify inefficient loops within their code. By proactively detecting these code blocks, developers can optimize them and adopt better practices as their applications scale and evolve.

How loop detection in APM Insight Java agent helps

The loop detection feature in the APM Insight Java agent captures loops within your application's code and identifies duplicate calls. This capability is particularly valuable for uncovering inefficiencies that may not be evident in synchronous or asynchronous code. By detecting and addressing these hidden performance bottlenecks, developers can enhance application performance and provide a smoother user experience.

Note

By default, the loop detection feature is disabled, but you can enable it.

Where to view this in the UI

  1. Log in to your Site24x7 web client.
  2. Go to APM > your Java application.
  3. Click the Traces tab, then select the required trace.
  4. Select the Trace Details tab.
  5. Look for spans labeled Loop Detected.

The highlighted portion of spans depicts the agent's detection of a nested loop implementation in which the outer loop (at CatalogBean.viewProduct) runs twice, and the inner loop (at Product.sleepTime) runs twice, resulting in four iterations in total.

How to enable/disable loop detection

  1. Navigate to APM > APM Insight > your Java application.
  2. Click the hamburger icon (Hamburger icon) near the Application/Instance drop-down menu and select Edit.
  3. In the Edit Agent Configuration Profile screen, you can enable or disable Loop Detection.

How are loops captured?

Note

Not all loops are captured. 

Loop detection is specifically designed for methods within user packages. A loop is captured if it meets one of the following thresholds:

  • Contains at least one external call inside the loop.
  • The total duration of the loop exceeds 10ms.

Metrics captured

When a loop is detected, the following metrics are captured and displayed in the Trace Details tab:

Metrics Description
Duration Total time taken for the loop execution
Origin of the loop Name of the class and method enclosing the loop
Iteration count The number of iterations the loop goes through
Consolidated view of duplicate calls External calls that occur across iterations at the same place within a loop are merged and shown as a single span

Was this document helpful?

Would you like to help us improve our documents? Tell us what you think we could do better.


We're sorry to hear that you're not satisfied with the document. We'd love to learn what we could do to improve the experience.


Thanks for taking the time to share your feedback. We'll use your feedback to improve our online help resources.

Shortlink has been copied!