JMeter: How to assign weights/frequencies/smapleRates to ThreadGroups/"TestSets" dynamically from CSV file - jmeter

I would like to create a JMeter test setup with important sampling and test variation parameters entirely controlled by csv-Files (i.e. not modifying the JMX-File). It should be run with maven.
Ideas is as follows:
sources.csv contains
sampleRate;file
40;samplesForController1.csv
30;samplesForController2.csv
5;samplesForController3.csv
...
SampleRate should determine, how often a certain number of tests (defined by parameters in the respective file) should be executed (relative to others).
How could this be achieved? Im asking for the first step here (make sure the files/testSamples are sampled/executed given the indicated sampleRate) as I think I can solve the second part (dealing with parameters in samplesForController1.csv etc.) by myself.
P.S.
I'm struggling with the options presented here: In Jmeter, I have to divide number of thread into the multiple http requests in different percentage but have to keep sequence remain same since
afaics, thread groups cannot be created on-the-fly/dynamically/progammatically
apparently, Throughput Controller needs to know its child element(s probablities) upfront (i.e. not created dynamically), otherweise, sampling is very odd (I could not get it working maintaining the desired sampleRate)
I did not try to integrate jmeter-plugins in the maven build thus far as my impression is, the available plugins/controllers also needs to know their child element upfront

It is possible to create thread groups programmatically, check out:
Five Ways To Launch a JMeter Test without Using the JMeter GUI
jmeter-from-code example project
jmeter-java-dsl project
You can use Switch Controller and use a function like __groovy() to generate the child element index, example implementation can be found in Running JMeter Samplers with Defined Percentage Probability article
It's not a problem to use JMeter Plugins with Maven, see Adding jar's to the /lib/ext directory documentation section for example setup

Related

JMeter Thread Groups - Is it possible to make the same instance of one behave as a time based or an iteration based element dynamically at runtime?

I am creating a JMeter Test Harness that will be run from Jenkins using "Build with Parameters' to set runtime parameters that are passed into JMeter as Properties using -J attributes.
End users will be given the choice of running tests either based on the number of iterations or a period of time.
I can easily interrogate a passed in property value to determine if an 'iteration' or 'time' based test type and in order to try this I have added variables (which may or may not be have values depending) for ALL of the Thread Group 'Thread Properties' fields as can be seen below. Each variable will have a value of either 0 or 1+ depending upon the Jenkins parameters passed in at runtime.
enter image description here
As I do not want to create 2 Thread Groups (one for iteration based, and the other time based) then use logic controllers or similar to control what way to test, is there a dynamic way to switch the Thread Group 'Thread Properties" behaviour at run time using the singular Thread Group?
enter image description here
Any help in making 1 thing do 2 things in my little world of JMeter will be greatly appreciate!!
Not really, with "vanilla" JMeter you can:
Set number of iterations to -1 for "duration" based test
Set duration to a very long value (a couple of years) for the "iteration" based test
Other options are in:
JMeter .jmx scripts are basically XML files and XML is a subset of text so you can use a text editor like sed to substitute values directly in the .jmx file
Taurus automation framework has a nice feature of modifying an existing JMeter test before launching, it allows overriding absolutely any property of absolutely any element.

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example

What is purpose to use setup threadgroup and teardown threagroup in Jmeter? Please explain same with example.
I know why we use thread groups and also aware of fact that setup is for pre activities like creating user and monitoring purpose but not sure with an incident where can i use it. same with tear down.
It sounds like you have pretty much figured it out already, but let me give you a few examples of when I've used it.
setup:
Get a large data set from a database into a jmeter variable for use during the test.
Get and log the version number from the system under test:s version number.
Run a javascript to set jmeter properties based on more simple input parameters/properties. Lets say you want to configure the selection of target host a simple true/false value, but in your test you need to expand it to different strings, and you dont want to have logic spread out all over your test plan.
teardown:
Never used it, but I guess it is mainly useful for cleaning up your system (e.g. deleting users that were created during the test)
correct me as i'm probably wrong, but a setUp thread cannot be used to store variables for use on the test threads (that i can see). any variables that i use in the setUp are never available. however, i found that if i use a beanshell and convert the variable in the setUp thread to a property like this
${__setProperty(userToken, ${userToken})};
then on each test thread i either use the property directly like:
${__property(userToken)}
or at the top of my thread i convert the property back into a variable like:
vars.put("userToken","${__property(userToken)}")
however, this seems a bit long winded and it would be great if there was a way to set up variables in the setUP to be used on every thread.
A special type of ThreadGroup that can be utilized to perform Pre-Test/ Post-Test Actions.The behavior of these threads is exactly like a normal Thread Group element.
The difference is that these type of threads execute before/after the test has finished executing its regular Thread Groups.enter image description here

JMeter: What is a good test structure for load testing REST APIs?

I am load testing (baseline, capacity, longevity) a bunch of APIs (eg. user service, player service, etc) using JMeter. Each of these services have several endpoints (eg. create, update, delete, etc). I am trying to figure out a good way to organize my test plans in JMeter so that I can load test all of these services.
1) Is it a good idea to create a separate JMeter Test Plan (jmx) for each of the APIs rather than creating one JMeter test plan and adding thread groups like "Thread Group for User Service", "Thread Group for Player Service", etc? I was thinking about adding one test plan per API, and then adding several Thread Groups for different types of load testing (baseline, capacity, longevity, etc).
2) When JMeter calculates the Sample Time (Response Time), does it also include the time taken by the BeanShell Processors?
3) Is it a good idea to put a Listener inside of each Simple Controller? I am using JMeter Plugins for reporting. I wanted to view the reports for each endpoint.
Answers to any or all of the questions would be much appreciated :)
I am using a structure like below for creating a test plan in JMeter.
1) I like a test plan to look like a test suite. JMeter has several ways of separating components and test requirements, so it can be hard to set a rule. One test plan is likely to be more efficient than several, and can be configured to satisfy most requirements. I find there can be alot of repetition between plans, which often means maintaining the same code in different places. Better to use modules and includes on the same plan to reduce code duplication, but includes are equivalent and can be used with test fragments to reduce duplication.
Threadgroups are best used as user groups, but can be used to separate tests any way you please. Consider the scaling you need for different pages/sites. ie User/Administrator tests can be done in different Thread Groups, so you can simulate say 50 users and 2 admins testing concurrently. Or you may distinguish front-end/back-end or even pages/sites.
2) It does not include beanshell pre- and post-processing times. (But if you use a beanshell sampler, it depends on the code)
3) listeners are expensive, so fewer is better. To separate the results, you can give each sampler a different title, and the listeners/graphs can then group these as required. You can include timestamps or indexes as part of your sampler title using variables, properties and ${__javaScript}, etc. This will cause more or less grouping depending on the implementation you choose.

Running A Large List of Files Once and Only Once in JMeter (Possibly in a Particular Order)

I'm trying to run around 15000 soap requests through JMeter. I have 15000 individual soap files in a folder.
I know that the WebService(SOAP) Request component has the option to point to a folder.
But, the problem is that the files in the folder will get picked up and run randomly and a file can get run multiple times.
This is not ideal because each request has a unique correlation id and if a file get's run twice, the second run will fail due to a duplicated correlation id.
Is there anyway, I could tell jmeter to run the files only once?
Also, as certain soap requests are dependent upon other request having already run, the ability to run these in a specified order would be desirable. Is this possible?
These seem like common problems that should have already been solved. But, I can't find much on google.
Do you guys have any ideas?
I would use the JSR223 Sampler to run a script (e.g. Groovy) to iterate through the files in the directory and store the text of each file in a String.
See, for example, this other answer about using a Groovy script to iterate a list of values.
You could put the data into a csv file and read it in using a CSV Data Set Config. If you need unique values over multiple threads then you have to create multiple files, one per thread.
You could also put the data in a database and use a JDBC Config/Sampler to access it, making sure to either a: delete the data after it is read, or b: mark it as 'read' using a flag. Both methods would prevent the same record being read twice by different threads.
If you need to run requests in order you should structure the test plan as such, requests will be made sequentially, top to bottom.

Call function in user parameter definition

I'm running a set of thread groups (consecutively) and I need to reset a number of parameters at the start of each thread group so that they have a unique value.
Presently I'm referencing a User Paramaters node using a test fragment, and setting the value to value-${__time()}. Unfortunately, this results in the value being used verbatim (without resolving the time).
Is there a better way to achieve per-thread group variables that include function calls?
Works fine for me (Jmeter 2.5.1), as per below example.
Sample params set to ${__time(HMS,)} and value-${__time()} successfully resolved, generated and updated (once per iteration) for each thread (in this case:3 Thread Groups, 5 threads # 3 loops).
Can you please answer why are you using User Parameters via Test Fragment (as per your post)?
...And several articles, just fyi:
Parametrization in JMeter with user parameter
JMeter Variables vs. Properties. vs. Parameters
UPDATED:
Please find below results for example with both User Params and test logic put into Test Fragment and called from Module Controllers.
Works the same way as in sample above: successfully resolved, preserved between samplers in separate loop and updated (once per iteration) between loops for each thread (well, I 've commented in screen the rest of thread groups to get output for the first only; works fine with all TGs enabled too).
I think you could also try to put User Params config from Test Fragment to each thread group and leave in Test Fragment only test logic - if the above schema will still not work for you:
It's not very nice but both the Module Controller and Include Controller are still quite "buggy" and sometimes unpredictable.
You could also try to debug problem controllers in your scenario: select controller > click Help in jmeter's main menu > click Enable Debug > look into jmeter.log for details after execution.
You could also look onto custom Parameterized Controller - maybe it will work better.

Resources