You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I need a JSR223 groovy script to be able to dynamically create samples. This script receives kafka records which have headers including processing times. I'd like to be able to create samples using these timestamp info.
In my script, I create sampleresults :
def sr = new org.apache.jmeter.samplers.SampleResult(t_in, t_out - t_in)
But there's no way I know to add this sampleresult to JMeter results (.jtl, listeners...).
How could I do that ?
Thanks a lot !
First point might be annoying, but it is critical? Report could ignore those sample, could not it?
For the second point. Do you think those listeners should be enhanced to support subsamples?
Another way of implementing creation of samples would be by setting an array like object in the sampler and using a while/loop controller afterwards to iterate over the values of the array, using those values to fill in samplers.
First point is quite critical because I won't be able to postprocess the jtl file (blazemeter)
About the alternate way, do you suggest I use a loop controler then alter each sample created with the values I want ? I'm not sure I can alter the sample start time for instance.
Ok it seems to work, but I had to put the loop in a teardown threadgroup.
I'm using SampleResult.setStartTime() and SampleResult.setEndTime().
However, it rises an exception on every loop :
2022-11-17 12:02:39,362 ERROR o.a.j.s.SampleResult: sampleEnd called twice java.lang.Throwable: Invalid call sequence at org.apache.jmeter.samplers.SampleResult.sampleEnd(SampleResult.java:1147) ~[ApacheJMeter_core.jar:5.5] at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:82) ~[ApacheJMeter_java.jar:5.5] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:651) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:570) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:?] at java.lang.Thread.run(Thread.java:750) ~[?:1.8.0_345]
Any idea on how I could fix that ?
Yes, the exception comes from JSR223Sampler calling SampleResult#sampleEnd() without checking, if the sampler has set a timestamp (not equal to 0) first. Should probably fixed.
I'm using a dedicated JSR223 sampler into a loop controller, to create the samples I need. The values (start time, end time) are pushed by the main sampler to a java.util.concurrent.ConcurrentLinkedQueue and used by this sampler. All other samplers are setIgnore(). The main sampler is multithreaded, so it is important to use data structures supporting concurrent access.
It looks like that :
@frgirard thank you so much for your quick response. if its not too much to ask could you please provide a example JMX script with above script so i can better understand how main JSR223 is working with this logic together to produce dynamic labels ?
Activity
FSchumacher commentedon Nov 16, 2022
Have you thought about adding those samples as sub results into your given SampleResult?
https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html#addSubResult(org.apache.jmeter.samplers.SampleResult)
frgirard commentedon Nov 16, 2022
Yes I did, but there are 3 issues with this method :
FSchumacher commentedon Nov 16, 2022
First point might be annoying, but it is critical? Report could ignore those sample, could not it?
For the second point. Do you think those listeners should be enhanced to support subsamples?
Another way of implementing creation of samples would be by setting an array like object in the sampler and using a while/loop controller afterwards to iterate over the values of the array, using those values to fill in samplers.
frgirard commentedon Nov 16, 2022
First point is quite critical because I won't be able to postprocess the jtl file (blazemeter)
About the alternate way, do you suggest I use a loop controler then alter each sample created with the values I want ? I'm not sure I can alter the sample start time for instance.
FSchumacher commentedon Nov 16, 2022
In Groovy space, you can do quite a lot. I would try it out. But it should be possible to use SampleResult#setStartTime(long) on the current sample.
frgirard commentedon Nov 17, 2022
Ok it seems to work, but I had to put the loop in a teardown threadgroup.
I'm using SampleResult.setStartTime() and SampleResult.setEndTime().
However, it rises an exception on every loop :
2022-11-17 12:02:39,362 ERROR o.a.j.s.SampleResult: sampleEnd called twice java.lang.Throwable: Invalid call sequence at org.apache.jmeter.samplers.SampleResult.sampleEnd(SampleResult.java:1147) ~[ApacheJMeter_core.jar:5.5] at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:82) ~[ApacheJMeter_java.jar:5.5] at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:651) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:570) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:?] at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:?] at java.lang.Thread.run(Thread.java:750) ~[?:1.8.0_345]Any idea on how I could fix that ?
FSchumacher commentedon Nov 18, 2022
Yes, the exception comes from JSR223Sampler calling SampleResult#sampleEnd() without checking, if the sampler has set a timestamp (not equal to
0) first. Should probably fixed.Allow SampleResult#setEndTime be set in JSR223Sampler
frgirard commentedon Nov 30, 2022
Thanks a lot for your help, @FSchumacher !
Allow SampleResult#setEndTime be set in JSR223Sampler
PavanMudigondaTR commentedon Apr 24, 2024
@frgirard Could you please provide a sample on how you were able to do this "How to dynamically create samples
"?
I opened a new issue but no one responsed #6273
frgirard commentedon Apr 25, 2024
I'm using a dedicated JSR223 sampler into a loop controller, to create the samples I need. The values (start time, end time) are pushed by the main sampler to a java.util.concurrent.ConcurrentLinkedQueue and used by this sampler. All other samplers are setIgnore(). The main sampler is multithreaded, so it is important to use data structures supporting concurrent access.
It looks like that :
PavanMudigondaTR commentedon Apr 25, 2024
@frgirard thank you so much for your quick response. if its not too much to ask could you please provide a example JMX script with above script so i can better understand how main JSR223 is working with this logic together to produce dynamic labels ?
PavanMudigondaTR commentedon May 20, 2024
@frgirard just wanted to check again if you could help me with above request ! I have a bit of hard time doing this ! any guidance is appreciated.