Bug 65552

Summary: Groovy classes not unloading
Product: JMeter Reporter: btmuscat <btmuscat>
Component: MainAssignee: JMeter issues mailing list <issues>
Status: NEEDINFO ---    
Severity: normal    
Priority: P2    
Version: 5.4.1   
Target Milestone: JMETER_5.4   
Hardware: PC   
OS: All   
Attachments: Code used

Description btmuscat 2021-09-05 13:21:54 UTC
I am running Jmeter tests using JMeter 5.4.1 and Groovy and openjdk version "16".

During these test l see the heap memory progressively increases up to the point to provoke an Out of Memory exception metaspace and a heap dump.

From Jconsole I can see that Loaded Classes continuously increase, up to the point of 100K+ classes loaded.

I've run JMeter using -verbose:classes, and there are thousand of lines regarding loading "Script" classes like:

[Loaded Script1 from file: /groovy/script]
[Loaded Script2 from file: /groovy/script]
[Loaded Script3 from file: /groovy/script]
[Loaded Script2409 from file: /groovy/script]

All my JSR223 elements have check to cache complied scripts.

Can you recommend a solution ?
Comment 1 Felix Schumacher 2021-09-05 14:23:43 UTC
Can you provide a minimal test plan, that we can use to reproduce this?

(My guess is, that you are using ${...} inside the scripts and have caching of JSR223 scripts enabled (default))
Comment 2 btmuscat 2021-09-05 14:49:24 UTC
Created attachment 38019 [details]
Code used
Comment 3 btmuscat 2021-09-05 14:51:01 UTC
Yes to both of these "${...} inside the scripts and have caching of JSR223 scripts enabled (default))"

I am new to this level of jmeter and need to sort this out or look for a new job.
Comment 4 btmuscat 2021-09-05 15:06:37 UTC
Sorry there are two JSR223 sampler in the script attached that dont have the caching option flagged. Even when l flag them l get this problem. l am currently working on the script to make it work with them all flagged.
Comment 5 Felix Schumacher 2021-09-05 15:50:22 UTC
As stated on http://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler do not use ${...} together with JSR223 scripts (and especially not together with caching).

The ${...} will be replaced by JMeter on each call of the sampler and will produce a "new" script, that has to be compiled (and then will be cached).

Instead of "abc = ${someVar}" use "abc = vars.get("someVar")". That is Groovy code and not JMeter templating stuff.

Same thing about ${function(...)}. Do not use it in JSR223 scripts.

You can
 a) ask questions about usage of JMeter on the users mailing list (which would have been probably the right place for this question)
 b) replace the ${..} calls with native Groovy code
 c) use the parameters line to let JMeter ${...} fill in outside of the JSR223 script.