JustNatural
JustNatural

Reputation: 448

Get the initial expected test duration or end time of a Concurrency Thread Group at the beginning of the script

In Jmeter, I am using Concurrency Thread Group with ${__tstFeedback(ThroughputShapingTimer,1,10,10)} in combination with the Throughput Shaping Timer to dynamically change the target throughput throughout the test duration.

I want to have a JSR223 test element (Assertion or PostProcessor, does it matter?) in which to write custom logic to not log some specific error but only if it occurs near the end of the test script and I don't want to hardcode the time value.

For example if I get a java.net.SocketException in the last 2 minutes of the scheduled run time, I want to not log it, but I do want to log it in the rest of the time. For this, I suppose that I need some way to grab the date when the test is supposed to end since the beginning of the test, evaluate it and subtract 2 minutes from it and then compare the current time with that time and then if the current time is higher, then start doing some logic to exclude the result from the logging.

Update: In the "Normal" or "Default" Thread Group I noticed that I can do this to get the initial duration:

String groupDuration = ctx.getThreadGroup().getDuration();
log.info(groupDuration)

But for the Concurrency Thread Group it does not work the same.

I would appreciate any information to help me achieve this goal.

Upvotes: 0

Views: 546

Answers (3)

Janesh Kodikara
Janesh Kodikara

Reputation: 1821

If your Concurrency Thread Group is configured with a Throughput Shaping Timer and Schedule Feedback Function the scheduled test duration is available through a property exposed by the Throughput Shaping Timer.

props.get('elementName_totalDuration')

The element will export the following propertyy that you can access through __P function or using in JSR223 Test Elements props.get("property name")

elementName_totalDuration - Total duration as sum of the "Duration,sec" column

elementName will be the name of your Throughput Shaping Timer

NOTE You should set Hold Target Rate Time to a value equal or greater than the total Duration specified in the Throughput Shaping Timer schedule. Hence set this value to a very high value to avoid test completing before scheduled duration in Throughput Shaping Timer. e.g Set Target Hold rate t0 1440 minutes.

Using concurrency Thread Group with Throughput Shaping Timer and the Feedback Function

When this thread group is used with Throughput Shaping Timer, you may replace Target Concurrency value with a call to the tstFeedback function to dynamically maintain thread count required to achieve target RPS. When using this approach, leave Concurrency Thread Group Ramp Up Time and Ramp-Up Steps Count fields blank, but be sure to set Hold Target Rate Time to a value equal or greater than the total Duration specified in the Throughput Shaping Timer schedule.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168092

For dynamic thread groups and derivatives you can use the following function:

ctx.getThreadGroup().getHold()

If you need to determine whether it is in minutes or seconds you can use

ctx.getThreadGroup().getUnitStr()

Example:

enter image description here

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

Upvotes: 1

Ori Marko
Ori Marko

Reputation: 58772

You can filter results after test with Filter Results Tool

If you want to remove the ramp-up phase, you could use offset filters

Using --end-offset 120 parameter (seconds)

Upvotes: 0

Related Questions