Stress Testing your website with Apache jMeter

On June 23, 2010, in Testing, by Anuj Gakhar

I recently got a chance to work with jMeter to stress test one of the Projects I was working on. jMeter is an open source software like all other Apache Projects. It is written in 100% pure Java and works as a desktop application. The installation is pretty easy and straightforward as well. Download the package and unzip it and that’s it. To run the application on Windows, double click the “bin/jmeter.bat” file and to run it on MacOS, double click the “ApacheJmeter.jar” file.

In this post, I will mainly describe the processes I followed to setup a Test Plan in jMeter. I think the learning curve with this application is very minimal, as once you understand what the basic terminology is, that’s pretty much it. At the top of the hierarchy is something called a ‘Test Plan’. This is what you add all your sub-actions to. Here is how the initial screen looks like once you have opened it up.

As you can see, there is already an empty Test Plan existing. You can now add elements to this Test Plan. jMeter allows for many different types of requests to be made including but not limited to HTTP Requests, FTP Requests, WebService Requests, SOAP Requests and many others. In this post, I am only going to concentrate on HTTP Testing. Although, once you get an idea, it should be pretty straightforward to do the others as well in a similar way.

So, we start by adding a ‘Thread Group’ to our Test Plan. A Thread Group is something where you configure how many users you want to mimick. In other words, if I was to open xyz.com as a user in my browser, this Thread Group will do the same thing, the only difference is, you can tell it how many users you want to mimick and within what time span should those users hit the target URL. In the example below, I have got 5 users to hit the target within a timespan of 5 seconds.

You will see, I have called my Thread Group ‘WebTest’ in this example. To add a Thread Group, you simply right click on the Test Plan and add. Like this :-

Once you added your Thread Group in, you can add your HTTP Request Defaults config element to it. This Config element does not make any requests to the target. It is simply a config element where you can define what the starting URL, Protocol, Port number, timeout etc to use. To add a HTTP Request Defaults, you simply do this :-

And once you have it added to your Thread Group, you can configure it like below :-

As you can see, for this example, I have told jMeter to use digg.com as the default URL for all HTTP Requests. I have left everything else blank, but if you wanted, you can configure Port, Protocol,timeout and any starting path here. e.g./start-from-here etc. There is also an option to send any URL parameters along (key-value pairs).

Now, the next thing I did was I added a Loop Controller to my Thread Group. A Loop Controller simply runs all its child elements one by one in order – and runs them the number of times you tell it to. There is also something called a Random Controller which does pretty much the same thing but does not do them in the specified order. Here is how you add the Loop Controller :-

Now that you have the Loop Controller in, you can add as many Http Requests to the it. These are the requests that jMeter will execute as per the settings of the Loop Controller and the Thread Group. I have added 3 Http Requests in my Loop Controller, one for the HomePage, one for the Technology landing page and one for the Entertainment Landing page. But really, you can add as many as you want here. I would assume in a real scenario test, you will have a few more. Here is how my Technology Http Request looks like. Notice, how I have defined “/technology” in the Path. I have not given it the full URL because the initial starting URL (digg.com) comes from HTTP Request Defaults. This is where the Default settings come in handy.

ve

Now, that you have all your Http Requests in the Loop, we simply need a way of looking at the test results. And for that, we need to add some ‘Listeners’ to our Thread group. There are quite a few Listeners in there and they all capture exactly the same data, the only difference is how they treat the data. Each Listener has its own purpose and analyses the data differently. I have added 4 Listeners to my Test Plan above. ‘View Results in Table’, ‘View Results Tree’, ‘Summary Report’ and ‘Graph Results’. The process of adding these to your Test Plan is the same. Right Click on the Thread Group and add Listeners.

That’s it. The Test Plan is ready. We can now run the Test Plan and if everything has been setup properly, we should see the data coming in the Listeners. To run your test, click on the Run Menu and then Start. There are keyboard shortcuts for each of these menu items as well. Once I run the Test, I can see the data in my Listeners as follow :-

If you want, you can add more Listeners as well. You can also save the results to a file and save for future reference. The results are pretty clear to understand as you can see what works and what fails under what kind of stress. Normally, I would test a website for 10 users within a span of 20 seconds and if I dont get any errors, I would call the test a success. But these numbers can vary for different requirements and different server infrastructures.

This was a very simple Test Plan which involved nothing but 3 HTTP Requests mimicked as 5 users in 5 seconds. But you must have seen, that there is so much more you can do with it. You can test your FTP server settings with an FTP Request. You can test your Web Services with a Web Service Request. And so on….

It took me not more than half an hour to install and get used to and have my first Test Plan ready. And then another hour or 2 to get accustomed to jMeter terminologies and functionalities. I am liking it very much, indeed.

Tagged with:  

99 Responses to Stress Testing your website with Apache jMeter

  1. Abbies says:

    Hello Anuj, this tool looks promising for my load testing project but I wasn’t able to download the JMeter, can you help or provide steps on how to download Jmeter, thanks!!

  2. Larry C. LYons says:

    Hey Anuj,

    Good article. I’ve been using jMeter for a while for load and stress testing. One thing I’ve never really liked about jMeter is setting up each page request individually.

    There’s a nice app out called Badboy (http://www.badboy.com.au/) Its an automation tool for testing and development work. Badboy integrates with JMeter by by letting you save your badboy scripts in the JMeter file format so that you can open them and run them in JMeter. This support means that you can use Badboy to record your scripts to do functional testing, and then save the same script as a xml file to do performance testing using JMeter.

    regards,
    larry

    • Anuj Gakhar says:

      Larry, haven’t used Badboy before. Using the same script for functional testing and loading the same script with jMeter sounds pretty cool. I will give it a try. Thanks for the tip.

    • Sanjay M says:

      Anuj, thanks for your article, it gave a really nice overview about the key concepts. Though it didn’t work straightaway for my web app hosted on localhost, I could generate the JMeter script after installing BadBoy as suggested by Larry, saved me a lot of time. Thanks a Larry!

  3. Abbies says:

    Hello Anuj, Thanks to you for the link you shared I was able to download & run load test successfully on my website. However I am not sure how to use Jmeter to login to my application with a username & password, I tried passing username & password as parameters but how will I ask Jmeter to actually click on the “Login” button for me, can you please help, thanks!!

    ~Abbies

  4. Anuj Gakhar says:

    Hi Abbies, I would use the Once Only Controller and then add a HTTP request to that controller with the username and password parameters to the action page of your login form.
    Read about it here. http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Once_Only_Controller

  5. Jeffrey Lee says:

    In my website, there is a javascript that open a text file to read and display the content on the page when it loads. With more visitors to the website, the file is open and read more, and it should load the server more. If my test plan only have a HTTP request, is the file open and read by the javascript simulated? If not, how should I test it.

  6. Thanks for the tips and explanation but i am not much in jmeter user but still thanks for the link it was very helpful too.

  7. Chakravarthy says:

    Hi Anuj,

    Is path mandatory for HTTP Request

    THanks
    Chakravarthy

  8. Anuj Gakhar says:

    Hi Chakravarthy,

    You can have the defaults in HTTP Request Defaults and that way you dont need to have the server in your path but apart from that, you are going to need the Path.

  9. Chakravarthy says:

    Hi Anuj Thanks for the reply

    I am unable to record using proxy, When I am giving the local host in the proxy for recording then I am not able to connect to the internet and I am not able to record any thing.

    I have gone through the below link and followed the same steps but still I am not able to proceed

    http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf

    Can you please let me know how to access external sites from office network and record the same.

    I created on sample HTML page and tried to record on that page with proxy settings, Still I am unable to record.

    Can you please also let me know whether JMeter supports ADF Technology(Application Development Framework Technology)

    Thanks
    Kalyan

  10. Anuj Gakhar says:

    Hi Chakravarthy,

    I have not tried it with the Proxy so not sure how to resolve this. But the same settings as your browser should work, conceptually. I am also not sure whether jMeter supports ADF or not, I will try and find out an answer for you.

  11. Amit says:

    Hi Anuj,
    I am trying to test youtube movie using http request and i get answer (green light) after the first response.
    Do you know a way to get (green light) only after the full movie is downloaded
    Regards,
    Amit

  12. Anuj Gakhar says:

    Amit, you should be able to use the Content-length header in order to check for the downloaded video size. I haven’t done this kind of thing before but that would be my first attempt.

  13. venkat says:

    Hi Anuj,
    I am new to Jmeter.. i done web site test but how can i know Request & respnse time for each HTTP request..Could you help me?

  14. sameer says:

    how to do endurance testing with Jmeter ?

    any suggestion will b highly appriciated.

  15. vinay says:

    can we do functional testing and stress testing both at same time using jmeter.if yes how can we do that.
    please tell me

  16. pavan says:

    Hi Anuj i need to create automation framework in JMeter.Is it possible create frame work in JMeter.

  17. Kishore says:

    Hi Anuj. I have created a FTP test using Jmeter but I need to know how can i transfer more than one file from my local location to the FTP server location. All the files are text files.

  18. Siddartha says:

    Hi Anuj, do u know how to perform REST protocol test using Jmeter? If S pls let me know.And also some information regarding the where abouts of .jar file of REST protocol that can be integrated with Jmeter to run?

  19. Sanuji says:

    Hi,
    I am using Jmeter for the last three days…Its been found that when we are using heavy loads like 30000 users and 60sec ramp up time(ie i want to test a url that is hosted so that stress may be 30000/minute) given,it will be busy and show ‘loading’ symbol.
    Any suggestion about it.Because i want to test 60000/60sec without any problems

    Thank you,
    By,
    Sanuji

  20. Rekka says:

    Hi Anju

    Have proble in running the Jmeter.bat file both in cmd mode as well if dobule click the file . It gives me error msg ” Unable to access the jar file ApacheJMeter.jar ” error level = 1. I understand that i need to to run the jar file before executing the jmeter.bat file . But i do not see ApacheJMeter.jar file in any directory. Please advice .

    Thanks
    Rekka

  21. vijay says:

    Hi,
    Does Jmeter supports use of combined protocols of ADF and Flex?
    Regards,
    Vijay

  22. nila says:

    nice to learn very flexible to the user

  23. Raj says:

    I installed Jmeter recently to perform a load test on my application.
    Here, I need to find out the load time between one page to another page.
    So I captured all the transaction based on your above scenarios.
    But when run the test, I didn’t see any activity in the database.
    Am I doing something wrong?

    When I used the loadrunner, I can see all the transactions in the database while running the test through controller.

  24. deepmala says:

    Got this error while teting my web portal(http://localhost:8080/maa/admin):Need help?How do I configure for my aaplication?

  25. SQA says:

    My system: win7 and 32 bit

    i have download jemter from http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi

    then i unzip that put that in C:\ drive

    and move to bin and double click on jmeter.bat

    then i got the following error :
    ===========================
    unable to access jarfile apachejmeter.jar

    error level 1

    Press any key to continue
    ==============================
    then when i press any key it just shut down

    what is solve for this problem ? my email: niloy.cit1@gmail.com

    thank you

  26. Vardges says:

    Hi SQA. I saw your question just a minute ago, may be is too late now untill you have post your question, but i want to answer anyway 🙂
    Make sure that you have installed jdk properly, and check that you include it in your system variable path

  27. surender.M says:

    Hi anuj,

    Sub: Running the scripts in batch..

    We planned to use the Jmeter as a performance test tool in our project.

    we have recorded all the test scenarios and we are able to generate the load from different machines, But we would like to know is there any procedure that can combine all these scrips, where we can run them as a batch.

    If so kindly give me the sufficient guide lines to do so.

    Thanks in advance.

    Surender.M

  28. Mahesh says:

    Hello,

    I have recorded a script and now when i add some listeners to the test plan and run the script again then i get some results in listeners but how can i analyse the result and interpret as pass/fail.
    How to actually read the graph and all results of listeners in JMeter.

    Thanks in advance,
    Mahesh C.

  29. Era Gupta says:

    Hi Anuj,

    I just started working on Jmeter and wanted to know how to save a file coming from a response as an attachment. Please help me.

    Thanks in Advance.

  30. This makes so much sense. I will be back here often

  31. Jitendra says:

    i have one project in hand for performance testing if any freelancer/parttime/contract based resource can be contacted at 9908507962.it is very uregent as project already in ahand or reach me jkpatny@yahoo.com

  32. Jitendra says:

    i have one project in hand for performance testing using JMeter if any freelancer/parttime/contract based resource can be contacted at 9908507962.or reach me jkpatny@yahoo.com , it is very urgent as project already in ahand

  33. Daniela says:

    BlazeMeter- the load testing cloud for performance and fully JMeter compatible offers a lot of information about JMeter and how to handle these issues. Also- you can trial the system-10 free tests with one medium server, headless configuration and one JMeter console.

    Top 3 JMeter issues.
    1-The console freezes?
    2 The console freezes and doesn’t collect engine data using distributed architecture
    3-Engine running out of memory?

    To solve them, read the tutorial- http://tinyurl.com/ccu4bx3

    Hope it helps.

  34. Pasha says:

    Hi,

    we are planning to use Jmeter. However we are not able to download the pacakge.

    Please do the needful.

    Thanks,
    Pasha

  35. Swapnil says:

    Hello Anuj Sir,
    I am new to jmeter and i have already downloaded lot of stuff to get familiar with jmeter. But I not able to record a test using jmeter through http proxy server.it shows a big list of errors.I have configurd browser also. I am using IE8. The errors are as follows. Please Help.

    java.net.SocketException: Permission denied: connect at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.(Unknown Source) at java.net.Socket.(Unknown Source) at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80) at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122) at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.sample(HTTPHC3Impl.java:249) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:62) at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1018) at org.apache.jmeter.protocol.http.proxy.Proxy.run(Proxy.java:236)

  36. sathya says:

    I have tried load testing using jmeter.but the details are not hitting the database. how i do.please help me

  37. Proxy Sites says:

    Pretty component of content. I simply stumbled upon your weblog and in accession capital to assert that I acquire in fact loved account your blog posts. Anyway I will be subscribing for your feeds or even I achievement you get entry to constantly quickly.

  38. […] JMeter 這個名字叫JMeter的軟件,在SOF上,很多人推薦。 Apache官方出品,但程式使用上是極度困難,需要花時間學習。 網上教學是幾多的 – http://www.google.com/search?q=jmeter教學 我順著以下幾個教學相互補短,亦可以執行到Test。 Apache jmeter 2.3教學 JMeter 使用入門 — HTTP Request Stress Testing your website with Apache jMeter […]

  39. Chitra says:

    Hi Anuj,

    I have a question. I have a site built using Oracle ADF Portal application. I need to do performance testing on it using JMeter. Now in the site when I login (lets call this page A.jspx) with a username and password, it takes me to a page called B.jspx. But when I try to simulate the same in JMeter giving the username and pwd in an HTTP request sampler (named as Login), it logs in but when it gets to B.jspx it bounces back to A.jspx. It doesn’t stick on in the B.jspx page. I see this when I go to “View Results Tree” – there will be B with a green tick mark and inside it will be http://app.ac.za:9091/portal/faces/B.jspx and after that http://app.ac.za:9091/portal/faces/A.jspx. The second link shouldn’t be shown. Please help!

  40. Dora says:

    GJ ! Thanks.

  41. Ramanan says:

    Hi,
    i have a simple question as i m new in using Jmeter, how to make my script run for 1 hr in jmeter
    as i feel ramp up field is to rampup the user with a specific time ie say i give 5 sec,it will take 5 secs to make all users active
    but my question is i want the script to run for 60 mins and see what is the hit count and response time for it
    also let me wat r the elements i need to add
    i do thread pool-5users ,5secs,5loops
    sampler http request but u mentioned http request default not sure wat is difference
    listener-View Results Tree,Aggregate Report f-or 90percentile,View Results in Table
    Please suggest me with ur thoughts? and correct me if im wrong in using right elements or not

  42. Ramanan says:

    Also tell me how to record using badboy ie step by step simple procedure,i tried and im not sure whether im doin correctly
    let me know if any1 can explain the steps to record and save as to import the script and execute in Jmeter
    Your swift response will be highly appreciated
    Thanks

  43. Kannan says:

    Could anyone explain how to do correlation using JMeter regular expression.

  44. Prad says:

    Hi,

    I am trying to launch Jmeter on Opensuse 12.1

    when I click on the bin/jmeter file nothing happens and it opens in a text editor rather than launching the application.

    Can someone help me out?

  45. parmeshwar says:

    hi anuj,
    how i test my php website using jmeter.
    what is the procedure for testing.

  46. parmeshwar says:

    hi anuj,
    how i test my php website usinhg jmeter.

  47. Kushal says:

    Hi Anuj,

    It was really nice article and thanks for posting this. I want to perform Mobile website Performance testing using JMeter. Please tell me the procedure for this or there is any way to change the useragent in the tool.

    Regards
    Kushal

  48. Avneesh says:

    Hi Anuj,

    For a application after perform Run through Start(Ctrl+R) I am able to see the summary report, Aggregate Graph, View Result Tree, Graph Resuls etc, make save the displayed test plan. As I am trying to open the same result after perform the save Test Plan no data is displayed in above mention section.

    Will you please help me on it

    Avneesh

  49. site says:

    It appears to me that this website doesnt load in a Motorola Droid. Are other people having the exact same issue? I like this site and dont want to have to miss it when Im away from my computer.

  50. Harsh says:

    Hi,

    is it possible to Stress / Load test a web site on an iPad device or through iOS simulator using Jmeter ?
    Pls let me know if any other tool through which i can test a web page on iPad or through iOS simulator.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 450 other subscribers

© 2011 Anuj Gakhar
%d bloggers like this: