I am using JMeter for tasting a site. I am creating a GET request to an URL which returns a html document. From that document I am extracting a value using XPath Extractor which is the key of next request URL I am going to make.
The problem is, for single user its working fine, but for multiple users sometimes it fails to extract because of getting partial(not full) html as response.
How can I make the extractor to delay a bit before starting to extract the key or Is there any other way to get the entire html document before starting extraction?
Can anyone help me with this?
Well, partial response indicates a problem and setting a delay is not what you should be looking for as XPath Extractor is a Post Processor hence response data will remain the same no matter for now long you will be sleeping before XPath Extractor fires.
Few things to consider:
All post processors and assertions have their cost and XPath Extractor is the most "expensive" one as it builds DOM in memory. In case of large responses and severe loads it's behavior may be flaky. Try switching to Regular Expression Extractor or CSS/JQuery Extractor
Make sure that JMeter has enough memory allocated. For Windows look for set HEAP=-Xms512m -Xmx512m line in jmeter.bat file and increase max heap value (Xmx) to be approx 75% of available RAM.
If you're running tests using JMeter GUI - consider switching to command-line, Ant, Maven or whatever mode. See 5 Ways To Launch a JMeter Test without Using the JMeter GUI for options available
Make sure that you're following recommendations from JMeter Performance and Tuning Tips post.
Hope this helps.
Use "Constant timer"
right click on your HTTP request --> Timer --> Constant Timer
hope this will help.
Related
what is the recommended approach for developing a script in Jmeter from below options if I need to extract single/multiple values from response and Mark sampler as fail if it has error
Option 1. Use Jmeter built-in postprocessor for each of the variable needed or grab all variable in one go using regular expression extractor or Json path extractor etc and use assertion to check for the success or failure
Option 2: Use JSR223postprocessor and use groovy to parse response and grab required variable/variables and write code to check the success or failure instead of using built-in assertion
It is not possible to provide a valid answer without knowing the full details of your requirements, however here are several factors which can help you to take the right decision:
Readability/maintainability of your script. Sometimes it's better to sacrifice minimal performance improvement in order to make your script better understandable by others. So it depends whether your colleagues better understand 2 lines of Groovy code or 20 Regular Expression Extractors or vice versa
Performance. Each PostProcessor has its cost and depending on the number/nature of PostProcessors this or that option may act faster and/or consume less resources. The only way of checking this is measuring the throughput of both solutions using fake data provided by e.g. Dummy Sampler and the solution which has more throughput or consumes less CPU/RAM (whatever is the most important to you) will be the right choice
With regards to Assertions, as per 9 Easy Solutions for a JMeter Load Test “Out of Memory” Failure article:
Every test element added to the test plan will be processed - and this takes CPU time and memory. This also applies to all your Assertions, and is especially true for Compare Assertions - which consumes a lot of resources and memory. Only use the assertions you need and, even then, just use the amount that are absolutely required.
I have a jmeter script where I need to open a page multiple times. Hence, I kept this action under loop controller. What I observed is the response time of loading page is decreasing for every iteration. This could be due to caching. Can anyone help me on how to clear cache for this sampler after every iteration (I am referring to loop controller iteration here not thread group one).
Your requirement doesn't really make a lot of sense as well-behaved JMeter test should represent a real user using a real browser and real browsers caching strategy assumes minimizing the amount of downloaded assets by obeying Cache-Control headers
If you're aware of this good practice and still want to discard the cache for each iteration:
Add JSR223 PreProcessor as a child of the HTTP Request sampler which cache you want to clear
Put the following code into "Script" area:
sampler.getCacheManager().clear()
You can use HTTP Cache Manager in JMeter and check this checkbox to Clear cache each iteration?. You can follow the page to learn more about this. This applies to all the requests in the current thread. I know this is not what you are looking for but JMeter has only this option as UI setting.
Another way can be to use Beanshell PreProcessor to intercept the request and clear the cache on the run.
import org.apache.jmeter.protocol.http.control.CacheManager;
CacheManager clearCache = ctx.getCurrentSampler().getProperty("HTTPSampler.cache_manager").getObjectValue();
clearCache.clear();
I want to do a performance test of a website so i am creating a script that mimics user behaviour. I am using blazemeter to record those scripts and upload it in jmeter. I have two questions:
1) Do the results of a record and play script vary when run on another machine or a different time ?
2) I am getting a 400 bad request error in one of the steps of the recorded script.
What should i do ?
Is there any other way to test the web pages other than record and play ?
The chance of getting a good load test from recording is minimal as modern web applications widely use dynamic HTTP Cookies HTTP Request Parameters for different reasons (security, tracking client state, etc)
So after recording your test scenario "skeleton" most likely you will need to perform so called correlation - the process of
detecting dynamic parameters
extracting them using JMeter Post Processors and storing into JMeter Variables
and reusing the variables where required
Detecting parameters is quite simple: just record your test 2 times and compare request defaults: if you see differences - you will need to perform the correlation.
Extracting dynamic parameters is a bigger story, choosing the right extractor depends on response type, for example:
for HTML response types use CSS/JQuery Extractor
for XML/XHTML and in some cases HTML use XPath Extractor
for JSON - JSON Extractor
for anything else - Regular Expression Extractor which works with any text (including all above response types)
Also be aware that there is a solution allowing to perform JMeter correlation in an automated manner so you won't to detect and handle the dynamic parameter manually, check out How to Cut Your JMeter Scripting Time by 80% article for more details.
test plan screenshot:
For example instead of using 2000 as a threshold for each sample when do the assertion, I want to assert based on the medium response time. How can I do that?
You seem to be using the easiest solution already. Implementing assertion on average response time is possible, but a little bit tricky as you will need to use a JSR223 Assertion which will:
Store response time for each request into a JMeter Variable
On each request completion calculate arithmetic mean of all existing JMeter Variables and compare the result to the expected value.
The easier way would be running your JMeter test via Taurus tool. Taurus can execute existing JMeter tests providing some extra reporting and other features, particularly for your use case Pass/Fail Criteria Subsystem seems to be the perfect match
I am very new to jmeter and have recently started working on it for API load test.
Could someone please explain me why do we need to put assertion in load test, that should have been checked as part of functional test.
Also if I add any assertion as part of my load test it will have an impact on result (avg time, deviation, median etc) which is not correct.
Your thought
The purpose of an assertion on a response would be to insure that you have actually reached the correct destination.
For example if under load you server sends back incomplete responses, or a valid page containing an error message you would never know it without an assertion.
There is always some overhead for processing the assertion, but unless it is performing an excessive number of tests it should be minimal. The assertion is performed on the load generator so if that component cannot handle the additional overhead then the assertions will not be your only concern.
You need to use assertions, but you need to use it carefully. Ensure you use them when required, try to extract as less data as possible.
Follow JMeter tuning tips:
Use Response Assertion or Size assertion, but avoid XML Assertion,
XML Schema Assertion and XPath Assertion
Use Regular Expression Extractor, but avoid XPath Extractor when possible