Running samplers in sequential Manner Jmeter - performance

I am creating a script on a simple web application which includes following:
1)Login
2)Some API call(which requires token from login response)
I successfully created the script and executed for one thread which worked fine. Now I am trying increase the load upto 100 threads wherein i got some errors on few API request which got executed before Login sampler(authorization error). Then I put if controller for all API calls(if login success then request API), in this case login will always run first before any API request($JMeterThread.last_sample_ok==true).
My manager has told me not to use if controllers in the script because it will consume some time to execute which in turn will affect the final response time.
What is the alternate method to achieve this in term of performance aspect.

Related

JMeter : How to run Multiple Samplers under a single Thread group for multiple concurrent users?

I am new to JMeter and trying to learn JMeter by doing performance testing for one of the application in my organization.
I am facing the blow issue with the concurrent execution of a single thread for multiple users.
Base URL: http://xyz.abc.com/app/
Complete URL : http://xyz.abc.com/app/{RandomSesionID}/Account/Login
I've create a Thread with HTTP Requests as show below.
Thread Group
Hit Base URL
It Loads Login URL
Post Credentials and Click Login
Navigate to Landing Page(baseURL/{RandomSessionID}/Main/Home)
Click Logout(It will navigate to BaseURL/{RandomSessionID}/Main/Home)
When I let the thread count to its default value 1, Everything is working fine. However , The moment I set it to more than 1 (with ramp up time to 10sec), below thing happening.
User 2--->
Hit Base URL
Get The Login URL
Post The Credential
It again goes back to Request 2 (Get The Login URL)
and all the steps of the user are getting redirected to the second request irrespective of what I am requesting.
I tried organizing everything into Simple Controllers to see if the sequence will remain for all users but no avail, I am still running into the same issue.
please help me to understand what is going wrong here and how I can resolve these errors to test the application with more concurrency.
EDIT 1
I did a further investigation on this issue from my end and here are the observations I had.
Case 1: When I create two separate JMeter instances and run the same test parallel with different users, The Thread completely successfully without any errors.
Case 2: Wile Running the Thread with 2 users as mentioned above, The second HTTP request for BaseURL:/Home/Main redirecting the request to /Account/Main instead of going to the next step as shown below.
Image 1 :All The HTTPRequests In Order
Image 2 : This Is the Navigation Request For User 1
Image 3 :User 2 Hitting /Home/Main and Getting Redirected To /Account/Login As Response
Image 4 : User 2 Hitting /Home/Main and Got /Home/Main response
Image 5: User 2 Hitting The /Home/Main and Getting Redirected in Response
As you can see in Image 1, Those are the series of requests which I am making through the thread group and these requests are the same for all the users in the thread.
In Image 2, You can see /Home/Main is a Single GET request with a valid /Home/Main response without any issues.
However, In the Subsequent Images 3-5, You could see that the GET /Home/Main-134 making sub-request and 134-0 and 134-1 with 134-0 to GET /Home/Main and 134-1 to GET /Account/Login.
My Observation: I doubt that JMeter is using a single tab/ instance of the browser and hitting those web requests in the same tab where the first request was initiated. Due to which for the second user, it is always redirecting to the Login Page even though the session ID is valid.
To Confirm whether what I observed is correct, I tried replicating the same scenario in the Chrome Browser as mentoined below.
1. Open Chrome broswer and Access the Base URL.
2. Login and Navigate to Home/Main
3. Now In the same Tab, Type BaseURL and It redirected me to the Login page.
4. Now Enter Credentials of User 2 and login and nvaigate to Home/Main.
5. Now I Try accessing the firt User URL by going back by 3-4 tabs.
However, This won't replicate the exact steps as we are using the browser normally whereas in the requests, we are directly hitting the urls with the GET/POST requests.
I am in a fix and unable to understand what I should do to get through this issue.I am not even sure whether it is the issue with the Application or issue with the Jmeter.
Are there any setting in JMeter which will make sure each Thread (user) of the Thread group gets the option to have a dedicated request instead of using the single instance of the browser internally ?
My expectation is that your It again going back to Request 2 statement is wrong.
Each JMeter thread (virtual user) executes Samplers upside down (or according to Logic Controllers)
So most probably your Get The Login URL is being executed by the second user and given the label of the request is the same you cannot distinguish which user is executing which sampler.
You can add i.e. __threadNum() function as the postfix for the request label like:
Hit Base URL user: ${__threadNum}
this way you will get the information regarding which virtual user is executing which request at each moment of time:
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept

E commerce load test with complete flow

I'm trying to do a load test of e commerce site with complete flow from product search, login to add to cart and submit. Product search and anonymous order is working fine but when I'm trying to run script for registered user it's not working. How can I fix this?Click here to download script
Your "download" link is broken or expired or whatever.
Most probably your request doesn't work for authorised users due to missing or improperly working correlation. Modern web applications cannot be just recorded and replayed as they widely use dynamic request parameters mostly for security reasons. So if this is the case your test needs to look as follows:
Open Login Page (usually GET request)
Extract dynamic parameters using one of matching JMeter Post-Processors and store them into JMeter Variables
Perform Login (usually POST Request) providing not only credentials, but also dynamic parameters values from the first request
Also make sure you add HTTP Cookie Manager to your Test Plan - it represents browser cookies and automatically deals with cookie-based authentication
You might want to try an alternative way of recording a JMeter test - using cloud-based proxy which is capable of exporting recorded tests in "SmartJMX" mode with automatic correlation of any dynamic parameters detected. Check out How to Cut Your JMeter Scripting Time by 80% article for more information.

Running Jmeter for Https app with single user for multiple times through Loop controller

Attached is the snapI am trying to run jmeter for single user with value of 10 in loop controller , I first login into the app and then subsequently uses the CSRF token accordingly for future request .The login is always successful and generates CSRF token, But when i try to use CSRF token for future request , I get unauthorized HTTP 401 reponse code , when running with value 10 in loop controller for single user , the same works when i try to run single user with value 1 in loop controller , Any idea how to fix this? (Note :- All this is present in same thread Group)
Well-behaved JMeter test should be able to loop single user without any problem, most likely you have a problem with your test design or mismatch with the application under test behaviour. General recommendation would look like:
First of all switch to iterations on Thread Group level, JMeter configuration elements don't respect iterations originated from elsewhere as "iterations"
Add Debug Sampler and View Results Tree listener to your Test Plan
Run your test with 1 user and 2 loops
Inspect request and response details, identify missing/extra/different parameters and fix them. See How to Debug your Apache JMeter Script for more details on JMeter test troubleshooting techniques.
Blind shot: your test includes login request and the virtual user is already logged in therefore it doesn't require login on 2nd loop. In this case you have 2 options:
Put the logic which needs to be executed only 1 time under Once Only Controller
If you use HTTP Cookie Manager be aware that Clear cookies each iteration works only on Thread Group-level iterations

Automated script logs out using JMeter

I am trying to automate testing of a web application.
I have recorded the test using JMeter proxy template (JMeter version is 3.2) and couple of times when I ran the test in the JMeter it ran properly but after sometime only some part runs properly.
Following are the steps I am doing:
Hitting the URL
Logging into the application
changing some feature in the application
and so on.
All the steps ran perfectly first few times but then after that only till login everything runs properly.
Just to be sure I tried passing the jsessionid from the first request to the next requests using the Regular "Expression Extractor". I can see in the View Results Tree that jsessionid is passed properly but next page after the step two still takes me into the login screen.
Any help will be very much appreciated.
I have attached screenshot for better understanding:
The response header of logged in page includes a sessionid which is used by another request while logging in.
All the sessionID are properly maintained still after logging in the next page takes me to the login page instead displaying what was done next in the recording.
When it comes to load testing of JSF-based web applications you need to take care at least of the following dynamic parameters:
JSESSIONID
javax.faces.Viewstate
JSESSIONID is a normal HTTP cookie so it is quite enough to add a HTTP Cookie Manager to deal with it
javax.faces.Viewstate is client state management mechanism which also acts as a security token to verify user's origin. So you will need to properly correlate it, i.e. extract from previous response using one of JMeter PostProcessors, store into a JMeter Variable and add as a parameter to the next request. Remember to do this for each and every request.
There might be more application specific dynamic parameters, the easiest way of detecting them is recording the same request (or scenario) 2 times, compare the recorded scripts, detect and work around the differences.

HTTP request not hitting controller

I currently have a problem where I send an asynchronous ajax request to a .NET controller in order to start a database search. This request makes it to the server which kicks off the search and immediately (less than a second) replies to the callback with a search ID, at which point I begin sending ajax requests every 10 seconds to check if the search has finished. This method works fine, and has been tested successfully with multiple users sending simultaneous requests.
If I send a second search request from the same user before the first search is finished, this call will not make it to the controller endpoint until after the first search has completed, which can take up to a minute. I can see the request leave chrome (or FF/IE) in the dev tools, and using Fiddler as a proxy I can see the request hit the machine that the application is running on, however it will not hit the breakpoint on the first line of the endpoint until after the first call returns.
At the point this call is blocking, there are typically up to 3 pending requests from the browser. Does IIS or the .NET architecture have some mechanism that is queuing my request? Or if not, what else would be between the request leaving the proxy and entering the controller? I'm at a bit of a loss for how to debug this.
I was able to find the issue. It turns out that despite my endpoint being defined asynchronously, ASP.NET controllers by default synchronize by session. So while my endpoints were able to be executed simultaneously across sessions, within the same session it would only allow one call at a time. I was able to fix the issue by setting the controller SessionState attribute to Read Only, allowing my calls to come through without blocking.
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]

Resources