Skip to content

Optimize parent controller path retrieval in JMeterThread#6721

Open
rajat315315 wants to merge 1 commit into
apache:masterfrom
rajat315315:optimize-parent-traversal
Open

Optimize parent controller path retrieval in JMeterThread#6721
rajat315315 wants to merge 1 commit into
apache:masterfrom
rajat315315:optimize-parent-traversal

Conversation

@rajat315315

Copy link
Copy Markdown

Fixes: #6720

Description

This PR introduces a thread-local parent controller path cache (parentControllersCache) inside JMeterThread.

Specifically, the changes are:

  1. Added a HashMap mapping Sampler to List<Controller> in JMeterThread.
  2. Created a lightweight nested class CachedPathToRootTraverser extending FindTestElementsUpToRootTraverser to bypass tree walks on cache hits.
  3. Updated triggerLoopLogicalActionOnParentControllers to lookup resolved paths in the cache and save the path on a cache miss.

Motivation and Context

When a sampler execution fails with the onErrorStartNextLoop option enabled, or when loop logical actions (such as Break/Continue) are triggered, JMeter traverses the entire test tree using DFS (testTree.traverse()) from the sampler to the root to resolve parent controllers.

For large test plans with deep nesting, this full tree walk is redundant since the test tree's hierarchy is static during thread execution. Under error-heavy loads, these continuous traversals degrade performance and spike CPU usage. Caching the path to the root per-sampler inside each thread avoids this overhead entirely.

How Has This Been Tested?

  1. Performance Microbenchmark:
    Created a microbenchmark simulating a deeply nested test plan structure (10 nested levels of loop controllers) over 100,000 iterations:
    • Without cache (full tree walk): 292.57 ms
    • With cache (lazy map lookup): 30.68 ms
    • Performance Speedup: ~9.53x (over 950% performance improvement).
  2. Compilation:
    Compiled core module Java classes using ./gradlew :src:core:compileJava.
  3. Unit Tests:
    Executed the core test suite using ./gradlew :src:core:test (379 tests completed, 0 failed, 1 skipped).

Screenshots (if appropriate):

N/A (performance optimization)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parent Controller Path Caching Optimization

1 participant