Replicate browser and user behavior with JMeter - jmeter

I am new on JMeter and would like to get insight on how to replicate browser and user behavior in JMeter.
What is the best practice when using JMeter to test web application (mainly for httpd, php, angular etc)
i.e from some reading documentation I should use timer to delay each sampler for more realistic use case
after reading JMeter documentation, I still have some confusion about:
HTTP Request configuration:
- should we use Java instead of HTTPClient4?
- should we enable embedded resources from HTML files?
Cookie Manager:
- should we keep or clear cookies on each iteration
Cache Manager:
- should we clear cache on each iteration or keep it?
- should we use cache-control header?
- what is the best value for max number elements in cache?
Where i should put cache manager, cookies manager?
Under test plan or under thread group if i have more than 1 thread group?
How to configure keepalive in JMeter sampler or header manager?
My use cases is to replicate 10 concurrent unique user accessing a web application

HTTP Request configuration:
should we use Java instead of HTTPClient4? - The recommended implementation is HTTPClient4, this way you will be able to use DNS Cache Manager, HTTP Authorization Manager with Kerberos, etc.
should we enable embedded resources from HTML files? - Of course, but make sure to exclude "external" ones which are not related to your application, i.e. fonts or scripts which reside in other domain. See Web Testing with JMeter: How To Properly Handle Embedded Resources in HTML Responses for more information.
Cookie Manager:
should we keep or clear cookies on each iteration Depending on your scenario, for example if it starts from login and ends with logout - it makes sense to clear the cookies to represent "clean" session
Cache Manager:
should we clear cache on each iteration or keep it? Depending on your scenario, like Cookie Manager
should we use cache-control header? Depending on how caching is implemented in your application under test
what is the best value for max number elements in cache? It needs to be sufficient to keep all cacheable content in your application. You can clear i.e. Chrome browser cache, execute your test scenario manually, open chrome://net-internals/#httpCache URL and see how many Entries do you have. Amend this setting to be equal or a little bit more
Where i should put cache manager, cookies manager?
Under test plan or under thread group if i have more than 1 thread group? These "managers" obey JMeter Scoping Rules, if you put them under Test Plan -
they will be applied to all Thread Groups, if you put them under Thread Groups - they will be applied to current Thread Group only
How to configure keepalive in JMeter sampler or header manager? - If you tick Use KeepAlive under HTTP Request sampler - it will AUTOMATICALLY add Connection: keep-alive header. If you untick it - JMeter will send Connection: close header. Don't use HTTP Header Manager for amending Connection header value

Related

JMeter - Load Test a user scenario

I am load testing a scenario in JMeter. I'm trying to achieve a certain amount of r/s and then sustain that for x amount of time. However, with the testing tool, it looks like falling short of r/s for each endpoint. Do I just need more virtual users from the system? or is an additional fix needed for the test plan below?
HTTP Header Manager
User Defined Variables
DNS Cache Manager
HTTP Authorization Manager
HTTP Cache Manager
Thread Group
HTTP Cookie Manager
CSV Data Set Config # 1
HTTP Request #1
HTTP Header Manager
HTTP Request #2
HTTP Header Manager
JSON Extractor
HTTP Request #3
HTTP Header Manager
CSV Data Set Config # 2
HTTP Request #4
JSR2223 PreProcessor
HTTP Header Manager
The CSV Data Set Config # 1 is CSV of username and passwords that are passed to HTTP Requests #1 and #2. The JSON Extractor extracts values from HTTP Request #2 to the HTTP Header Manager of HTTP Request #3.
I can think of 2 situations:
JMeter isn't capable of sending requests fast enough. If this is the case:
Make sure to follow JMeter Best Practices
Try increasing the number of threads/ virtual users
If you cannot conduct the required load from a single load generator - consider switching to Distributed Testing
Your application under test isn't capable of responding fast enough. The reasons could be:
Your application lacks resources (CPU, RAM, Network, Disk, Swap, etc.). Consider monitoring its baseline health metrics using i.e. JMeter PerfMon Plugin
Your application middleware configuration isn't suitable for high loads. Inspect configuration of load balancer, application server, database, whatever to see if they're set up good enough for the anticipated load. Check out Web Performance Optimization tips to get initial idea. Normally the vendors of application servers, databases, etc. provide scaling instructions.
Your application code is not efficient enough, i.e. uses bad algorithms. You can use profiling tools to check what are the slowest and/or frequently called functions, largest objects, etc.

How to simulate the browser load in JMeter?

We need to test our web application with 100+ users with JMeter tool.
Should we use JMeter webdriver plugin to launch the real browsers or can we use the blazemeter plugin to generate the script and run in JMeter? Will the script created with blazemeter simulate the real browser load?
Theoretically you can use real browsers, but be aware that browsers are very resource intensive so my expectation is that you will need at least one CPU core and at 1 GB of RAM per browser instance in order to have enough resources.
This means you will have to go for distributed testing and on average you will have one slave per 5 browsers. If this is something you can afford - go for it. If don't - be aware that you can configure JMeter to behave like a real browser, to wit:
Tell JMeter to Retrieve All Embedded Resources from HTML Files and Use concurrent pool of 6 threads. This can be done using HTTP Request Defaults, the settings live under "Advanced" tab
Add HTTP Cache Manager to simulate browser cache
Add HTTP Cookie Manager to mimic browser cookies
Add HTTP Header Manager to send browser-like headers (i.e. User-Agent, Accept-Encoding, etc.)
If your application uses AJAX requests - put the relevant HTTP Request samplers under the Parallel Controller

How to execute JMeter recorded script in parallel

How can I execute those JMeter recorded script in parallel as we do while creating HTTP SAMPLER (Embedded HTTP Resource) ?
While recording I also checked Retrieve All Embedded Resource with pool of 6. Because of this I getting incorrect response time(Varies from browser timing of page).
Is there any way that we could execute our recorded HTTP Samplers in parallel?
As of JMeter version 3.2 it is not possible to kick off extra threads to run a specific sampler(s) group in parallel, each thread (virtual user) executes samplers upside down.
So you should be very careful with what you are recording. For example, you must not be recording any embedded resources calls, there is `URLs Patterns to Exclude" input on the "Requests Filtering" tab of the HTTP(S) Test Script Recorder where you can define which resources need to be excluded from the recording.
Remember that well-behaved JMeter test should be producing response time similar to real browser, but you need to configure JMeter to mimic real browser, to wit:
Add HTTP Header Manager to represent browser headers
Add HTTP Cookie Manager to represent browser cookies and deal with cookie-based authentication
Add HTTP Cache Manager to act like browser's memory and disk caches
See How to make JMeter behave more like a real browser guide for more information on JMeter fine tuning.

jmeter active threads and csv - is this setup correct

I am using jMeter to load test logging in and logging out of my application. I have a CSV with 500 uname and pwords, and I have also set the active threads to 500.
Is this the correct way to stimulate a load of 500 users?
From technical perspective - yes, JMeter will pick up credentials from CSV and send them along with the request.
However if you think about what happens in reality logging in and immediately logging out doesn't seem a realistic use case for me. The whole idea of load testing a web application is simulating real users as close as possible, it includes:
Application usage scenario(s): how many users will be accessing your application at the same time and what users will be doing what things? For example given Stack OverFlow the vast majority of users are searching for answers by given criteria, some users are typing questions, some of them providing answers, and some of them are commenting. These all are different behavioral patterns which need to be accurately simulated by your load test
Each user should have a "user session" which identifies him so application would distinguish different users so make sure you have HTTP Cookie Manager in your Test Plan
Real users use real browsers which are downloading images, CSS and JavaScript files using parallel thread pool (around 5 concurrent threads) to speed up page loading process. In order to mimic this behavior you need to configure HTTP Request samplers to download embedded resources and do it in parallel. You can apply this configuration to all the HTTP Request samplers via HTTP Request Defaults.
Don't forget to add HTTP Cache Manager to mimic browser cache as real browsers normally cache embedded resources to disk and don't re-request them on subsequent calls.
So I would recommend reviewing your test scenario and/or load pattern and get familiarized with How to make JMeter behave more like a real browser article

Does a Jmeter thread really approximate a user?

I am trying to setup a JMeter load test, using the Recording Controller.
This results in duplication of all the calls the web browser would make - including css files, js files and images.
Given that a web browser would get these concurrently (performing approximately 10 web requests concurrently). The jmeter documentation tends to equate 1 user to 1 thread - but this does not line up with the way in which modern web browsers work.
Do I need to use 10 threads for each user when setting up my load test?
Strictly Speaking, JMeter can't simulate a browser. JMeter has its own limitations, like not parsing .js files (as per 3.0 version), sending ajax requests from events etc.
But, for your question, there is support in JMeter.
So, you can specify the concurrent pool size as per your requirements, say concurrent pool size value set to 10, which would solve your issue.
Today browser normally sends requests concurrently and each browser has its own max value for maximum connections that can be made concurrently.
Refer following links:
Max parallel http connections in a browser?
and How to solve Chrome's 6 connection limit when using xhr polling.
When you use "Retrieve Embedded Resources" and set Concurrent Pool Size, you ONLY need to add parent sampler, which triggers resource requests like .css, .js files by Jmeter itself. (Eg: add only stackoverflow.com and it will load all the resources like .css, .js automatically). During recording , all these requests are seperately recorded, so you need to remove all of them or create a new plan/thread group containing only parent sampler.
Note: As I mentioned, requests triggered from .js, .csv won't be sent as Jmeter won't parse them like Browser. You need to add ONLY these requests as samplers explicitly. Add View Results Tree and compare the requests triggered by Jmeter and Browser (F12 -> Network tab) to know which request are missing by Jmeter.
First of all, don't record requests to embedded resources. If you click Add Suggested Excludes button the HTTP(S) Test Script Recorder will automatically populate a regular expression to filter images, scripts and styles.
Second. To simulate browser behaviour: 1 main request to the page and several parallel requests to retrieve content you can use "Advanced" tab of the HTTP Request Sampler (or even better HTTP Request Defaults). You can also limit embedded resources to your application under test domain there
Real browsers download images, styles and scripts. However well-behaved browsers do it only once, on subsequent requests these entities are being returned from cache. So make sure you add HTTP Cache Manager to your Test Plan to represent browser cache so you could avoid overwhelming your server with extra requests which don't happen in the reality.
See How To Make JMeter Behave More Like A Real Browser for more detailed explanation and instructions on using aforementioned Test Elements

Resources