I need to sign my request xml and add a token to it before hitting the application. For that I am using a JSR223 preprocessor which gets the data from current sampler, makes the necessary changes and puts the data back to sampler. This approach works fine with a single thread group. When multiple thread groups are used data between the samplers(in different thread groups) gets interchanged and it results in incorrect requests for the thread group. Below is the code in my preprocessor:
import jmeter_plugin.*;
String body = sampler.getXmlData();
log.info(body);
Utils utils=new Utils();
String request=utils.getResponse( body,"url/to/fetch/token");
log.info(request);
sampler.setXmlData(request);
Tried by having a single preprocessors for the entire test plan and also separate pre processors for each thread group. Both approaches did not work.
Your approach should work fine no matter how many Thread Groups do you have. Pre-Processors are executed before each sampler in its scope and should modify only the current sampler.
Quick checklist:
Make sure you're using Groovy as JSR223 PreProcessor language
Make sure you have Cache compiled script if available box ticked
Remove these log.info lines as they create unnecessary Disk IO overhead
Make sure your Utils class don't use methods which are not Thread Safe
Looking into sampler.getXmlData() it appears you're using JMeter 3.1 or below as SOAP/XML-RPC Request has been removed in JMeter 3.2 and users are encouraged to use HTTP Request sampler instead.
If your "sign" algorithms is not very exotic if might be easier to use WS Security for SOAP JMeter Plugin which can be installed using JMeter Plugins Manager
Related
I have just started using Jmeter WebDriver Sampler for automating performance of an application. I'm curious to know that can i call one webdriver sampler from another sampler?.Is it possible in Jmeter. Because I need to login and logout in every sampler.
Theoretically it is possible via JMeter API and JSR223 bridge however it will be too complicated and in general you ain't gonna need it.
There are 2 main points which you might not know:
JMeter executes Samplers upside down so if you have the following structure:
Login Sampler
Logout Sampler
Jmeter first will execute Login than Logout. Browser instance will be shared across the samplers
There is a mechanism in JMeter which helps avoiding code duplication so if you have Logout sampler(s) somewhere in your test plan and would like to re-use it in several places instead of copying and pasting it each time you can call it using Module Controller
Was wondering if anybody has tried to use jmeter to test gRPC application.
I was hoping that
I could write a gRPC client class with a non-blocking/asynchronous stub that makes non-blocking calls to the server,
Create a Jar of the above client
Import the Jar to JMeter
Use the Java method in Jmeter BeanShell sampler
before investing time in trying the above I wanted to see if any body has tried something similar and
if above workaround work?
will each thread create a separate TCP connection?
We have tried the load test with python client and locust.io but python gRPC is not gevent compatible and even with async call e.g. stub.GetFeature.future, we are hitting a limit on the request per second per process (async call doesn't seem to be async, GIL bottleneck, once TCP stream)
if above workaround work?
Your solution will work. But if you need it long term, I would recommend, rather than having client class and using BeanShell sampler, implementing custom Java Sampler. It's very practical, since work-wise it will be similar/same as implementing custom client + BeanShell sampler script, but Java sampler is typically more efficient than BeanShell sampler, and maintainability of such solution will be better (you won't have 2 co-dependent components to maintain).
A more fancy option is to create your own JMeter Plug-in (the link I provide here is old, and not very accurate, but it's a good starting point). This is quite an investment, but might be worth it eventually if you find that a simpler solution generally works, but has some major limitations, or you need higher level of configurability and control.
will each thread create a separate TCP connection?
Each thread runs independently, but whether each thread will have its own connection will depend on how you implemented them. In straight forward implementation (where sampler creates and destroys connection), each thread will have a separate TCP connection. But JMeter has properties shared among threads, which, among the rest, can contain objects. So you could share a connection between threads that way. Or you can implement configuration element, which could hold a connection pool, shared by all threads.
Please see grpc-client java project (maven) that creates a gRPC client with JMeter samplers to enable stress testing with JMeter
Build the project with maven and copy the generated jar to JMeter lib/ext folder (e.g. /usr/local/apache-jmeter-3.1/lib/ext/) so that the samplers are in the class path
After that when you launch JMeter, you should be able to see the classes in the "java request" samplers.
By default JMeter sends all the requests sequentially. Is there any
methodology to send the requests concurrently at the same time for a single user i.e.
something similar to web_concurrent_start () and web_concurrent_end ()
functionality in Load Runner. Any thoughts / ideas in this regard?
JMeter's equivalent of the web_concurrent_start () would be Synchronizing Timer, however depending on what you're trying to achieve you may need to use a different approach.
For simulating browser's behaviour with regards to images, scripts and styles it would be using "Retrieve All Embedded Resources" and "Parallel downloads" in the HTTP Request sampler "Advanced" tab
For simulating AJAX requests you may need to do some scripting using JSR223 Test Elements and classes from i.e. java.util.concurrent namespace as JMeter Thread Groups are not designed to kick off more threads than defined.
It sounds like you need a custom sampler to fire asynchronous requests. I added some info here regarding one I am using:
Performance Testing of AJAX calls via JMeter
If your requirement is simulating browser behaviour of sending requests concurrently to load images, .css and .js files, You should have a look at the following answer:
Does a Jmeter thread really approximate a user?
You can send multiple requests in parallel by only specifying the parent URL (let's say stackoverflow.com) and enable the checkbox "Retrieve All Embedded Resources" to send requests in parallel and define concurrent pool size to specify the number of parallel requests to be sent (usually 6).
Note: JMeter parses the HTML response and triggers the requests for the resources specified in HTML response. In JMeter 3.0, it can parses .css files also, but can't parse .js files (a limitation). so, you have to take care of those requests manually (by adding HTTP samplers for those requests)
The mobile app that I am testing with Jmeter makes 4 asynchronous API calls when logging in. Is there any way to simulate this with JMeter ?
Currently I can only get JMeter to make the calls synchronously, so when wrapping them all in the same transaction controller, the response time is the total of the 4 calls (instead of the highest one)
Many thanks
Currently JMeter doesn't offer a relevant test element, the easiest way of implementing your scenario is using JSR223 Sampler to perform nested asynchronous calls, something like:
See How to Load Test AJAX/XHR Enabled Sites With JMeter guide for more detailed explanation, code snippets,etc.
You can also consider developing a custom sampler with similar functionality and make it a part of your JMeter as a plugin or even share it with the community.
Take a look at Parallel Controller in JMeter.
All elements inside the Parallel Controller will be executed parallel to each other. This way, you will have one main flow and other flows with asynchronous requests, which will be executed in a parallel way.
https://www.blazemeter.com/blog/how-to-load-test-async-requests-with-jmeter
I am new to Jmeter and trying to understand what all can be achieved using Jmeter. I want to perform endurance or soak testing of a application using Jmeter, i.e. I want to run a particular script for a particluar number of users for a period of 3 hours.
What all options are available to me and what is the best availablelistener to monitor the result?
Please help. Kindly add if I am missing anything that I should know before starting with soak testing?
For setting up the numbers of users and runtime of the test you use a Thread Group. Setting the runtime is done by checking the Scheduler check-box and specifying Duration.
Of the original listeners in JMeter I have found myself most oftenly just using the plain Summary Report. But JMeter Plugins gives additional listeners which may be better, it depends on what you want to measure. The JMeter Plugins also gives additional thread groups, where you can specify e.g. an increasing load over time.
Use a Thread Group to set up your number of users and the duration of your test (using the scheduler of the Thread Group).
Then add all the samplers and logic controllers you need to perform your testing.
Next, add a Summary Report listener to get an overview of your results (min/max/average and such), and add a View Result Tree listener to get an overview of EACH step your testplan is taking. This Tree listener is great to actually see what jmeter is doing, and to debug your tesplan.
BTW: if you add a HTTP Request Defaults object, you can set your URL and options in there, and don't need to add it to each and every sampler again. Especially works like a charm if you start using regexp extractors and such.