2012-10-30

Stress Testing in JMeter

In this following article we are going to see how to perform stress testing on a sample website(www.kaz.com.bd).
Before going inside of it, we should have basic idea on what is stress testing ? Stress testing is a form of testing that is used to determine the stability of a given system or entity[wiki]. Stress testing determines the data handle capability of a site
Before starting, we should know the basic working process with JMeter. If we go through the article step by step, it would be very easy for us to understand the basic work process of JMeter.
Step 1. : Start JMeter by clicking “jmeter.bat” from “apache-jmeter-2.8\bin” and you will see this
image
Step 2 : From here, you will see Test Plan. Our full test procedure will be under Test plan(as sub section).
JMeter allows for many different types of requests like as HTTP Requests, FTP Requests, WebService Requests, SOAP Requests and many others. In here we will see an example of HTTP Testing. When we have the basic idea we will try others in a same fashion.
Step 3 : Adding Thread Group :
A Thread Group will define is the number of users you want to use for stress testing. Or we can say, if you open www.kaz.com.bd as one user in pc browser, this Thread Group will do the same , the only difference is, you can define how many users you want to hit the target URL within a time span .
Now, right click on test plan and keep mouse on Threads(Users) and we will get Thread group, setUp thread group, tearDown thread group.
image
Select Thread Group and you will see the UI
image
Provide name as “KazTest”, comments as “Demo Stress Testing”. Please look at the options carefully, I have used 50 threads(means 50 users) in Ramp-up period 5 seconds(after each 5 second , 50 user will hit the URL). I use Loop Count as forever, meaning, I want to continue the test all times. If you provide any value in the in the Loop Count text box, this test will be continued up to that time.(i.e. 5 times). I will use Loop Count as 5. If you select the scheduler then the 4 text box will come to take the inputs. though I have selected to show, but I will not use that. So, my settings screenshot will be
image
Now, save the thread group in the PC to a suitable location.
Step 4 : HTTP Request Defaults : What is HTTP Request Defaults ? This is nothing but a configuration set of default http request settings which will be perform under our thread group.
For this,  Add HTTP Request Defaults (under Config Element)to our KazTest.
image
After adding, provide this URL(www.kaz.com.bd) as Server Name or IP(out test site) . 
We have left other options blank, but when we need we can configure Port, Protocol, Content encoding, Implementations image , Timeout etc.There is also options to send any URL parameters with request(key-value pairs).
Step 5: Loop Controller : We will add a Loop Controller under Logic Controller. What is a Loop Controller? A Loop Controller simply runs all its child elements one by one in order up to the number that we configure. There is also Random Controller which does pretty much the same thing but does not do them in the specified order.
image
image Now that We have the Loop Controller in.
Step 6: Http Requests : We will add Http Requests for each of my page inside of that loop controller. This is because, the loop controller will hit the pages of my site.(In here, JMeter will execute as per the settings of the Loop Controller and the Thread Group) .In our URL(www.kaz.com.bd), we have 4 pages, Home, Talents, Culture, Contact. Lets add a Http Requests for Home page.
image
Right click on Loop controller->Add->Sampler->HTTP Request. When we add one , we will get similar page as “HTTP Request Defaults” with some extra Http request option. We will name every request as out page, select Redirect Automatically instead of follow redirects and put comments(optional). We will use Get method. Please look at the path section where you see that we have inserted only sub URL part of the full path this is because the base URL will be taken from initial setting at HTTP Request Defaults.
 image
So my Http Request pages are Home,
image
Talents,
image
Culture,
image
and Contact.
image
So, Up to this we have completed the stress test arrangements using Http Request. Now, we need way of looking at the test results.
Viewing results :
For viewing data , we need to add some ‘Listeners’ to our Thread group. There are a few Listeners JMeter and all of them capture exactly the same data. The only difference is how they work with the data. Each Listener has its own purpose and analyses the data differently. To add a ‘Listeners’ right click on thread name(KazTest) –> Listener –> ‘Summary Report’. This will add ‘Summary Report” listener in the thread group. Like the same we will add total 4 Listeners to KazTest [‘View Results in Table’, ‘View Results Tree’, ‘Summary Report’ and ‘Graph Results’]. The process of adding these to our Test Plan are the same. We can add more listeners based on our needs. To read more about listeners see this.
image
Now, We are ready for testing. To run your test, click on the Run Menu and then Start. Once we run the Test, we can see the data in the Listeners [I am providing some sample screenshots]
image
image
image
image
image

Some Extra Listeners …
image
image
image
So, that’s it. It is a very simple example using 4 requests. I have added only few listeners, you can add according to your need. We will learn details on those customization later on. I wrote this from the inspiration of this site.
Thanks…:)

10 comments:

  1. Hi, Shantonu,

    It's great to read your blog. It's simple and easy to follow. Thanks!
    One minor comment though: for the Home page, putting '/index.html' in the Path for the HTTP Request, gives 404 response when I run it. But if I keep it blank, it works just fine.

    Keep up the great work!
    Thanks again!

    --Ishti

    ReplyDelete
    Replies
    1. I need to see the request that you are sending. send me JMX, i can show you why is the errors.

      Delete
  2. Replies
    1. Thanks... . there are some issues
      1. Try http 4.0 (or 3.2) for http requests and default.
      2. Try not to keep request inside a loop unless you spatially need

      from my blog, it was their old site.. this time hit only kaz.com.bd

      the response you are getting is warning messages( http sampler is not getting the expected messages.). Because they restructured their site, you can get the response from kaz.com.bd not /index.html
      your messages : http://screencast.com/t/U2WDeAdshf
      passed : http://screencast.com/t/LyN4E7ZHGhq

      Delete
  3. Your blog is missing many pictures. Please fix

    ReplyDelete
    Replies
    1. Thanks for feedback , but I don't see any one missing? Please check again.
      BTW.. KAZ software changed the site, so those images may not sync with actual site.

      Delete
  4. Hi Shantonu,

    I want to learn Remote Testing using Jmeter. Can I have the article for this?

    ReplyDelete
    Replies
    1. https://shantonusarker.blogspot.com/2013/01/how-to-distribute-test-in-jmeter.html

      Delete
  5. Hi Shantonu, Have u tried load testing a chat application using jmeter?

    ReplyDelete