Jmeter postprocessor best practices - jmeter

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.

Related

Jmeter - Dummy Sampler vs Flow Action

I have read the user guide, here or on Blazemeter blogs regarding usage of flow action to implement dynamic pacing in Jmeter script with help of a JSR223 timer. I wanted to check if I can use JMX dummy sampler to implement the same JSR223 timer?
Does it really impact performance if using Dummy Sampler vs Flow Action in performance test scripts as both are samplers only. Please advise and any support link would be appreciated.
Impact performance of what?
"Pacing" is yet another approach to control the number of hits per second by slowing down the requests for whatever reason (not to overwhelm the application, send desired number of requests per second, etc.)
Any implementation of "pacing" is "killer" of the performance because it adds a pause between iterations instead of starting new iteration immediately so your question doesn't make a lot of sense. If you want to use the most resource efficient solution - you need to either share your implementation details for these 3 approaches or better measure it yourself using a profiler tool
If you're looking for a easier/better way of sending requests at constant rate instead of implementing the "pacing" I would rather recommend considering using of the following test elements:
Constant Throughput Timer
Precise Throughput Timer
Throughput Shaping Timer

In Jmeter how to make the jmeter fail a test based on the medium response time?

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

Jmeter: Using Assertions on jmeter scripts being used in Blazemeter will it cause slowness/increase in response time?

I need clarification that if I use Assertion in our scripts will it make any slowness?
I was using 10 to 15 assertion on my scripts and the type used are Response and Duration assertion, will there is any impact that could cause slowness/increase in response time and other metrics?
Please help me on this by getting the answers from expertise, as the mail address support team.
According to what BlazeMeter say about assertions they only consume CPU and Memory
All assertions come with a cost, in terms of CPU or memory consumption. However, some assertions carry a greater cost than others. According to the JMeter Performance and Tuning Tips guide, the Response Assertion and the Duration Assertion are typically lower-impact choices, whereas Compare Assertion and other XML-based ones like XPath Assertion consume more CPU and memory.
The assertions are done at the machine which is running the tests not on the server where the application is running so there is no need to worry about slower response times from the server. The only thing that assertions are going to bother are your processor and the RAM eventually.
I see that you already got the answer for your question. Just wanted to share additional info that It is not just only for assertion.
The issue will even happen based on the type of response data extractors you have in your test plan. Check this link for a simple comparison and to get an idea.
Each and every element in the test plan affects the execution. You need to be very careful what you are adding in the test plan.
For the above question I got reply from the Blazemter team and here is the Message;
"Some assertions are consuming a lot of system resources and using a lot of assertions can cause slowness and out of memory errors.
The duration assertion is not very resource consuming, however the Response assertion can consume a lot of memory as it has to fetch the whole page full of data.
I highly recommend reading this short blog post(https://www.blazemeter.com/blog/why-you-must-use-jmeter-assertions-your-load-tests-0) about how to use assertion in JMeter and also which assertions you should avoid."

Delay In JMeter

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.

Assertion in jmeter and its impact on result

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

Resources