How to save start time of all the individual samples in my jmeter test and use that in JSR223 Listener - performance

Im using influxfb to save the result of my jmeter test.
bellow is the part of code in JSR223 Listener where im in need of your help.
result = new StringBuilder();
result.append("Thro_5,")
.append("label=")
.append(escapeValue(sampleResult.getSampleLabel()))
result.append("count=")
count=sampleResult.getSampleCount();
result.append(count)
result.append(",duration=")
dur1=sampleResult.getStartTime();
result.append(sampleResult.getEndTime()-sampleResult.getStartTime())
*****here code to write data to influxdb*****
I'm trying this code in which i want to know the total duration sample has taken till now to calculate throughput.
a=sampleResult.getEndTime()-sampleResult.getStartTime()
.append(",throughput_=")
.append(totalSamplecount/(a/1000))
Last line in the above code , i.e sampleResult.getStartTime() ,it should be the starting time of a sample in the first loop.
If i have 3 samples in my test ,having loop count 3 ,i want to save the starting time of each sample in the first iteration and use that value in the calculation of throughput of each samples.
Then while i'm in 3rd loop i want to know the total duration it has taken so far from the first iteration.And totalsamplecount/duration
As far as i know sampleResult holds the result of current sample.
I'm stuck in 2 points:
in saving the start time of each samples and use it later for each iteration to calculate the duration.
In saving the total count of individual samples executed till now.

Related

Rps is very low compare to given number of users

I am new in load testing , For understanding the statistics generated by locust , I give very low load to an API, See my below snapshot, there is only 1 user run against given API and it finish its process within milliseconds but my RPS is showing 0 . I am expecting RPS value as 1 because the request able to finish within one second.
Test Result
See my code below and please note that I am not giving any wait_time in my code and it is a very simple code which I wrote.
Main code
config file

Forcing thread to take a particular value from CSV and does not change till the test is completed

I have CSV file which contains Mobile Number, for e.g. number.csv
1276543281
1276543282
1276543283
1276543284
1276543285
Configured CSV Data Set Config with following options
Recycle on EOF? : True
Stop Thread on EOF? : False
Sharing Mode: All Threads
Thread Group settings are given below:
Number of Threads: 5
Ramp-up: 1
Loop Count: 10
Now, when I execute it, threads take any number from CSV and on next iterations based on the thread completion takes the value from CSV.
I want to force Thread1 to take 1st row, Thread2 to take 2nd row and so on... till the loop count is reached or the duration is reached.
You won't be able to achieve the described behaviour using CSV Data Set Config, with the above configuration each thread will pick up the next value on each iteration.
There is no guarantee that 1st thread will pick 1st line and 2nd thread 2nd line.
If you want to "stick" each thread to the respective line from CSV you should use __groovy() function instead like:
${__groovy(new File('/path/to/your/number.csv').readLines().get(ctx.getThreadNum()),)}
where ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information.
you can achieve this solution by two ways
You can achieve by keeping the CSV dataset config only once in the controller
You can achieve by using Baolu CSV Data Set Config, in your scenario, set block size for each threads as 1
In these two scenarios, the value picked in first iteration those same values would be picking in next iterations.

Jmeter - executed a script with and without timer. but the result doesnt seem to work well

i executed a script for login in Jmeter.
User 1, rampup time 1, loop 5, cache and cookie manager added. Clear cache of each iteration checked.
without timer below are the time taken for a user in next iteration
after adding constant timerof 3000ms below are the values obtained.
can someone please explain the results after adding constant timer of 3000ms?
according to me the result should be approx. 2+30sec =around 32 sec foreach iteration.
JMeter doesn't include Pre-Processors, Post-Processors and Timers duration into Sample Result by default
If you want to include these 3 extra seconds added by the Timer put your Sampler under the Transaction Controller and tick both Generate parent sample and Include duration of timer and pre-post processors in generated sample boxes:

Can you track how long controller was running? jmeter

I'm doing some testing with while controller.
In my test it checks every 3 seconds for a correct response text and if condition is not met, it repeats.
I would like to track how long that while controller was running, repeating itself until the condition was correct.
Is there any way to do that?
You do it via JMeter Functions, to wit:
__time() - to get the current timestamp before entering the While Controller
__longSum() - to calculate the delta between 2 timestamps
Something like:
Before the While Controller starts put the following expression somewhere in your script:
${__time(,before)}
It will store the current timestamp into ${before} JMeter Variable
After the While Controller ends put the following expression somewhere in your script:
${__longSum(${__time(,)},-${before},)}
It will get the new current timestamp and calculate the delta by substracting ${before} variable value from it
Demo:
See How to Use JMeter Functions posts series for more information on using JMeter Functions.
you can use Counter and Bean Shell Post Processor.
Keep Counter Config Element inside the While Controller. The value of Count will be incremented in each iteration.
So, in if condition, you can add BeanShell Post Processor to the sampler inside If controller, and calculate the total time taked using the following formula:
count value * 3 = total seconds waited to reach If Condition.
Following is the placement of elements in the TestPlan:
While Controller
...Counter
...If Controller
......HTTP Sampler
.........Bean Shell Post Processor
Image reference:
Counter Configuration screenshot:
Bean Shell Post Processor code:
int count = Integer.parseInt(vars.get("count"));
int totalTime = count*3;
log.info("total time waited : " + totalTime);
vars.put("totalTime", totalTime);
Screenshot:
Note: the value is saved in totalTime variable, so you can refer the value in subsequent requests using ${totalTime}

To manullay calculate the total duration of jmeter testplan from the Logfile

I want to manually calculate the Duration of jmeter testplan from the csv Logfile.I was following the calculation of last timestamp-first timestamp and it looks correct if am running for 1 thread group.For more than 1 threadgroup the samplers will be repeating and I think it should not be the right way to calculate the duration.I tried using transaction controller thinking that the corresponding timestamp will give me the duration of all contained samples but got confused when I saw multiple transaction controller entry in the Log file for more than one threadgroup. I am newcomer in the performance testing and in the jmeter.Any help will be appreciated.
JMeter provides variable which holds test start timestamp, it is ${TESTSTART.MS}
You could use tearDown Thread Group which is designed to run post-test actions. Under tearDown Thread Group you can use Beanshell Sampler to print test duration to jmeter.log file as follows:
long start = Long.parseLong(vars.get("TESTSTART.MS"));
long end = System.currentTimeMillis();
log.info("Test duration: " + (end - start) / 1000 + " seconds");
By the end of the test you should see something like:
2015/06/17 22:20:15 INFO - jmeter.util.BeanShellTestElement: Test duration: 300 seconds
See How to use BeanShell: JMeter's favorite built-in component guide for more Beanshell scripting tips and tricks.
If you have only result file, another option is open .jtl results file with Excel or Google Sheets or equivalent, sort timestamp column (usually the first one), subtract first cell/first row value from the first sell/last row value - this way you'll get test duration in milliseconds.

Resources