Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/jmeter.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,9 @@ view.results.tree.renderers_order=.RenderAsText,.RenderAsRegexp,.RenderAsBoundar
# Used by JSR-223 elements
# Size of compiled scripts cache
#jsr223.compiled_scripts_cache_size=100
# Configurable options on the compiled scripts cache, overrides the jsr223.compiled_scripts_cache_size property
# See com.github.benmanes.caffeine.cache.Caffeine API for details
jsr223.compiled_scripts_cache_spec=maximumSize=100,recordStats

#---------------------------------------------------------------------------
# Classpath configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ public abstract class JSR223TestElement extends ScriptingTestElement
* Cache of compiled scripts
*/
private static final Cache<ScriptCacheKey, CompiledScript> COMPILED_SCRIPT_CACHE =
Caffeine
.newBuilder()
.maximumSize(JMeterUtils.getPropDefault("jsr223.compiled_scripts_cache_size", 100))
.build();
Caffeine.from(JMeterUtils.getPropDefault("jsr223.compiled_scripts_cache_spec","maximumSize=" +
JMeterUtils.getPropDefault("jsr223.compiled_scripts_cache_size", 100) + ",recordStats")).build();

/**
* Lambdas can't throw checked exceptions, so we wrap cache loading failure with a runtime one.
Expand Down Expand Up @@ -257,11 +255,11 @@ private static <T extends ScriptCacheKey> CompiledScript getCompiledScript(
} catch (ScriptCompilationInvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
cause.addSuppressed(new IllegalStateException("Unable to compile script " + newCacheKey));
cause.addSuppressed(new IllegalStateException("Unable to compile script: " + newCacheKey));
throw (IOException) cause;
}
if (cause instanceof ScriptException) {
cause.addSuppressed(new IllegalStateException("Unable to compile script " + newCacheKey));
cause.addSuppressed(new IllegalStateException("Unable to compile script: " + newCacheKey));
throw (ScriptException) cause;
}
throw e;
Expand All @@ -287,7 +285,7 @@ public boolean compile()
((Compilable) scriptEngine).compile(getScript());
return true;
} catch (ScriptException e) { // NOSONAR
logger.error("Error compiling script for test element {}, error:{}", getName(), e.getMessage());
logger.error("Error compiling script for test element named: '{}', error: {}", getName(), e.getMessage());
return false;
}
} else {
Expand All @@ -297,7 +295,7 @@ public boolean compile()
((Compilable) scriptEngine).compile(fileReader);
return true;
} catch (ScriptException e) { // NOSONAR
logger.error("Error compiling script for test element {}, error:{}", getName(), e.getMessage());
logger.error("Error compiling script for test element named: '{}', error: {}", getName(), e.getMessage());
return false;
}
}
Expand Down Expand Up @@ -357,6 +355,9 @@ public void testEnded() {
*/
@Override
public void testEnded(String host) {
if (COMPILED_SCRIPT_CACHE.estimatedSize() > 0) {
logger.info("Compiled cache size: {}, stats: {}", COMPILED_SCRIPT_CACHE.estimatedSize(), COMPILED_SCRIPT_CACHE.stats());
}
COMPILED_SCRIPT_CACHE.invalidateAll();
scriptMd5 = null;
}
Expand Down
2 changes: 1 addition & 1 deletion xdocs/usermanual/component_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ To benefit from this feature:
</li>
</ul>
Cache size is controlled by the following JMeter property (<code>jmeter.properties</code>):
<source>jsr223.compiled_scripts_cache_size=100</source>
<source>jsr223.compiled_scripts_cache_size=100</source> or via a more complex cache setup using the <source>jsr223.compiled_scripts_cache_spec</source>
<note>Unlike the <complink name="BeanShell Sampler" />, the interpreter is not saved between invocations.</note>
<note>
JSR223 Test Elements using Script file or Script text + checked <code>Cache compiled script if available</code> are now compiled if ScriptEngine supports this feature, this enables great performance enhancements.
Expand Down
4 changes: 4 additions & 0 deletions xdocs/usermanual/properties_reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1985,6 +1985,10 @@ JMETER-SERVER</source>
Used by JSR-223 elements.<br/>
Size of compiled scripts cache.<br/>
Defaults to: <code>100</code></property>
<property name="jsr223.compiled_scripts_cache_spec">
Used by JSR-223 elements.<br/>
Caffeine framework spec configuration in String format. Overrides <code>jsr223.compiled_scripts_cache_size</code><br/>
Defaults to: <code>maximumSize=<jsr223.compiled_scripts_cache_size>,recordStats</code></property>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you refer the documentation or copy the relevant bits here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@KingRabbid KingRabbid Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean it would be worth adding the links to JMeter documentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed new code, not sure it addresses your suggestion with regards to documentation, please let me know where to edit.

</properties>
</section>

Expand Down