Jmeter Calculate Value Response Thread Group - jmeter

how to jmeter calculate response data value
example
Number of thread = 3
Ramp Up = 1
Loop Count = 1
Thread 1 value extract = 3
Thread 2 value extract = 7
Thread 3 value extract = 10
how to get total = 3+7+10 = 20

Add JSR223 PostProcessor after the extractor and put the following code where
props.put('value_' + ctx.getThreadNum(), vars.get('extracted_value'))
Then somewhere in tearDown Thread Group you can use the following expression to get the sum of all values of properties which start with value_
props.entrySet().findAll {prop -> prop.getKey().startsWith('value_')}.collect {prop -> prop.getValue() as int}.sum()
More information about what do these props, ctx and vars mean: Top 8 JMeter Java Classes You Should Be Using with Groovy

Related

Error with twinx: 'PlotAccessor' object has no attribute 'twinx'

I'm using a for loop with a list of variables to create multiple plots against one variable each plot has an item in the list iterated in the for loop against the variable "PUMP FAILURE (1 or 0)"
ATTEMPT
ListOfVariables = ['Volumetric Flow Meter 1', 'Volumetric Flow Meter 2', 'Pump Speed (RPM)', 'Pump Torque', 'Ambient Temperature', 'Horse Power', 'Pump Efficiency']
for item in ListOfVariables:
first_axis = dataframe_raw[item].plot
second_axis = first_axis.twinx()
second_axis.plot(dataframe_raw['PUMP FAILURE (1or 0)'], color='teal')
plt.title(item)
plt.show()
ERROR
3 for item in ListOfVariables:
4 first_axis = dataframe_raw[item].plot
----> 5 second_axis = first_axis.twinx()
6 second_axis.plot(dataframe_raw['PUMP FAILURE (1or 0)'], color='teal')
7 plt.title(item)
AttributeError: 'PlotAccessor' object has no attribute 'twinx'

Can I use variables across all the threads in the thread groups in jmeter?

I'm trying to create a test plan for rate-limiting behavior.
I set a rule that blocks after X requests per minute, and I want to check that I get response code 200 until I reached the X requests, and from then, to get 429. I created a counter that shared between all the threads, but it seems to be a mess because it's not a thread-safe.
This is my beanshell "once only controller":
String props_pre_fix = ${section_id} + "-" + ${START.HMS};
props.remove("props_pre_fix" + ${section_id}, props_pre_fix);
props.put("props_pre_fix" + ${section_id}, props_pre_fix);
props.put(props_pre_fix + "_last_response_code", "200");
props.put(props_pre_fix + "_my_counter", "0");
and this is the beanshell assertion:
String props_pre_fix = props.get("props_pre_fix" + ${section_id});
//log.info("props_pre_fix " + props_pre_fix);
//extract my counter from props
int my_counter = Integer.parseInt(props.get(props_pre_fix + "_my_counter"));
//extract last response code
String last_response_code = props.get(props_pre_fix + "_last_response_code");
log.info("last_response_code " + last_response_code);
//if last seconds is greater than current seconds it means we are in a new minute - set counter to zero
if(last_response_code.equals("429") && ResponseCode.equals("200")){
log.info("we moved to a new minute - my_counter should be zero");
my_counter = 0;
}
//increase counter
my_counter++;
log.info("set counter with value: " + my_counter);
//save counter
props.put(props_pre_fix + "_my_counter", my_counter + "");
log.info("counter has set with value: " + my_counter);
if (ResponseCode.equals("200")) {
props.put(props_pre_fix + "_last_response_code", "200");
if(my_counter <= ${current_limit}){
Failure = false;
}
else {
Failure = true;
FailureMessage = "leakage of " + (my_counter - ${current_limit}) + " requests";
}
}
else if (ResponseCode.equals("429")) {
props.put(props_pre_fix + "_last_response_code", "429");
if(my_counter > ${current_limit}){
Failure = false;
}
}
I'm using props to share the counter, but I obviously feel that this is not the right way to do it.
Can you suggest me how to do that?
I don't think that it is possible to automatically test this requirement using JMeter Assertions because you don't have access to the current throughput so I would rather recommend considering cross-checking Response Codes per Second and Transactions per Second charts (can be installed using JMeter Plugins Manager)
All the 200 and 429 responses can be marked as successful using Response Assertion configured like:
If for some reason you still want to do this programmatically you might want to take a look at Summariser class source which is used for displaying current throughput in the STDOUT.
Also be informed that starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting.

How to loop CSV file values using Ultimate Thread Group?

I have this links.csv file:
METHOD,HOST,PATH,HITS
GET,google.com,/,7
GET,facebook.com,/,3
I want to create a JMeter test plan using Ultimate Thread Group (UTG) that randomize the hits based on the last column in the CSV above (HITS).
When viewing the results tree, I want to see something like this:
1. google.com
2. google.com
3. facebook.com
4. google.com
5. google.com
6. google.com
7. google.com
8. google.com
9. facebook.com
10. facebook.com
Ideally, I want to set the UTG to use the following settings:
Start Threads Count = sum of all hits in the CSV file (e.g. 7 + 3)
Initial Delay = 0
Startup Time = 60
Hold Load For = 30
Shutdown Time = 0
How to achieve this? I appreciate code samples and screenshots since I'm still new to JMeter.
I can only think of generating a new CSV file out of your original one in order to:
Get the "sum" of "HITS"
Generate a line containing method, host and path per "hit"
In order to achieve this:
Add setUp Thread Group to your Test Plan
Add JSR223 Sampler to the Thread Group
Put the following code into "Script" area:
def entries = new File('/path/to/original.csv').readLines().drop(1)
def sum = 0
def newCSV = new File('/path/to/generated.csv')
newCSV << 'METHOD,HOST,PATH' << System.getProperty('line.separator')
entries.each { entry ->
def values = entry.split(',')
def hits = values[3] as int
sum += hits
1.upto(hits, {
newCSV << values[0] << ',' << values[1] << ',' << values[2] << System.getProperty('line.separator')
})
}
props.put('threads', sum as String)
Use __P() function like ${__P(threads,)} in the Ultimate Thread Group
Use the new "generated" CSV file in the CSV Data Set Config in the Ultimate Thread Group

SAS parallel processing: Start k parallel jobs subsequently until N jobs are done

There might be a simple solution, but currently I cannot get my head around it. Maybe someone could help me out.
So I have the following problem:
I have in total N SAS jobs that I want to finish. As my resources on my machine are too limited to start all N jobs simultaneously, I only want to start say k = 5 at the same time. Every time one job finishes, I want to start the next one. The order in which the jobs are completed is not important.
Currently, I let all k=5 jobs finish before I start the next 5.
So here is the pseudo code, for what I am currently doing:
/*The following macro starts k threads*/
%macro parallel_processing(k);
options fullstimer autosignon=yes sascmd="sas -nonews -threads";
%global thread jj idlist;
/*These are the N ID numbers for the jobs*/
%let idlist = 1 2 3 4 5 ... N;
%let jj = 0;
%do %until(&jj.=N);
%do thread = 1 %to &k.;
%let jj = %eval(&thread.+&jj.);
%syslput thread = &thread;
%syslput jj = &jj.;
%syslput idlist = &idlist.;
rsubmit process=task&thread. wait=no sysrputsync=yes;
%let id =%scan(%trim(&idlist.),&jj.);
/*Do the job*/
%job(id);
endrsubmit;
%end;
/* HERE IS MY PROBLEM:
I want to wait for each job separately, and start a new one
with an increased id. So that constantly k threads are busy.
*/
/* Wait for all threads to finish */
waitfor _all_ %do thread = 1 %to &k.;
task&thread
%end;
/* GET RESULTS FROM THREADS */
%do thread = 1 %to (&k.);
rget task&thread;
%end;
/* SIGNOFF THREADS*/
%do thread = 1 %to (&k.);
signoff task&thread;
%end;
%end;
%mend parallel_processing;
%parallel_processing(k);
Maybe somebody has a nice idea, I would be grateful! Thank you in advance.
Use waitfor _any_ ... instead of waitfor _all_ ...:
Start the first 5 tasks, keeping a note of which 5 tasks are active.
Wait for any one of them to finish and remove it from the list of active tasks.
Start the next task from the queue and add it to the list of active tasks.
Repeat steps 2 and 3 until there are no tasks left in the queue.
You can use any method you like to keep track of which 5 tasks are currently active.

ruby multiple loop sets but with limited rows per set

Alrightie, so I'm building an CSV file this time with ruby. The outer loop will run up to length of num_of_loops, but it runs for an entire set rather than up to the specified row. I want to change the first column of a CSV file to a new name for each row.
If I do this:
class_days = %w[Wednesday Thursday Friday]
num_of_loops = (num_of_loops / class_days.size).ceil
num_of_loops.times {
["Wednesday","Thursday","Friday"].each do |x|
data[0] = x
data[4] = classname()
# Write all to file
#
csv << data
end
}
Then the loop will run only 3 times for a 5 row request.
I'd like it to run the full 5 rows such that instead of stopping at Wed/Thurs/Fri it goes to Wed/Thurs/Fri/Wed/Thurs instead.
class_days = %w[Wednesday Thursday Friday]
num_of_loops.times do |i|
data[0] = class_days[i % class_days.size]
data[4] = classname
csv << data
end
The interesting part is here:
class_days[i % class_days.size]
We need an index into class_days that is between 0 and class_days.size - 1. We can get that with the % (modulo) operator. That operator yields the remainder after dividing i by class_days.size. This table shows how it works:
i i % 3
0 0
1 1
2 2
3 0
4 1
5 2
...
The other key part is that the times method yields indices starting with 0.

Resources