Using JMeter and Firefox to load test

I spent some time recently building an application using AJAX technology – which simply means a collection of client side JavaScript and XML that asynchronously retrieves data from the server in the background only when needed so as to minimize the impact on the user experience. Once the basic application was up and running, I wanted to run some performance test and thanks to the abundant availability of cloud based compute resources, it was easy to quickly and inexpensively put together a performance testing environment. The trouble is that it isn’t so easy to automate a load test on a dynamic AJAX based application, especially if there are no static DOM identifiers to include in the scripts. So, I came up with a quick hack to push AJAX actions through Firefox’s proxy configuration to record a JMeter script.

Here are some simple steps for recording an AJAX session using Apache’s JMeter.

1. Create a new JMeter Test Plan

2. Add a HTTP Request Defaults config element
# This can be used to specify defaults for you entire test suite
+ Specify your Server Name or IP address and any required port #

3. Add a HTTP Cookie Manager config element
# This can be used to control and manage the cookie policy across the test

4. Add a Thread Group
# No need for multi-threaded recording, so:
+ Specify 1 thread, 1 sec ramp up time and loop count of 1

5. Add a Once Only Controller
# My application has a user login that also generates a session, cookie
# If your application does not, you can skip this step and the next

6. Add a HTTP Request Sampler to the Once Only Controller
# Here you specify the protocol method (put/get), path to the request and any parameters

7. Add a Recording Controller to the Thread Group

8. Test Plan > Add > Listener > Aggregate Report

9. Under Workbench, Add > Non-Test Element > HTTP Proxy Server
+ Port 9090
+ Target Controller: Thread Group > Recording Controller
+ Patterns to include: Click Add then enter “.*”

10. Under HTTP Proxy Server, Add > Timer > Gaussian Random Timer
+ Set Constant Delay Offset (in milliseconds): ${T}

Now, lets set up Firefox to proxy actions. Bring up the Firefox browser and under Tools/options/advanced tab/network tab/settings button/”Manual proxy configuration”
+ Set 127.0.0.1 port 9090
+ Enable the “Use this proxy for all protocols” check box

And when ready to start recording the browser action just bring up the HTPP Proxy Server within JMeter and click Start. Everything that is done within Firefox will be recorded in JMeter’s recording controller. When done, just click the Stop button on the HTTP Proxy Server within JMeter.

That’s it, the JMeter script that was created above now has all the AJAX data recorded and it ready to replay. JMeter has built in capacity to run the script and generate a load. I recorded a few different JMeter scripts and using a couple of cloud instance and the JMeter command line interface, I simulated the AJAX action of many thousand of clients with offset timing.

Reblog this post [with Zemanta]

About chipcorrera

Chip Correra http://about.me/ChipCorrera View all posts by chipcorrera

10 responses to “Using JMeter and Firefox to load test

  • hari

    it is not working with ajax requests could you please check it once regarding the response codes ru getting correct response codes are not.

  • chipcorrera

    I am not exactly sure what you mean by not working – nothing shows, wrong codes, etc…?One potential problem is that AJAX response codes are UTF-16 and JMeter uses a java html page to display results which may not be capable of handling UTF-16. You could try saving results to a file and see if you get better results.

  • Don Rivard

    Nice job! I was honestly looking for this. I am using Xceptance but same theory.Hows it going. Hope all is well.

  • huh

    Not a hack. You used JMeter’s proxy to record your browser requests. Almost every browser can do this.

    That’s what the JMeter recorder is for.

  • Miguel Perez

    JMeter is already an amazing tool. But your article has made the software even better. I’ll be using your tip many times this year. Thanks.

  • Chuck

    Chip – it’s over a year since you posted that I came across this article, yet it is still relevant. It helped me ramp up my proof-of-concept JMeter testing. Thank you.

  • Miguel

    What If the browser answers with just JavaScript code?
    And this code is what bults up the entire page… i.e. you send a post to the server… and it answers 200 OK with javascript code as answer… we miss all the gets… that come along….

  • glinius

    Although JMeter is capable of recording AJAX calls it won’t replay them properly. AJAX calls are executed in parallel, each call by separate thread, and JMeter doesn’t provide any relevant sampler implementing this behavior and allowing to override parent thread group limitations. However it’s possible with some scripting. See How to Load Test AJAX/XHR Enabled Sites With JMeter for example samplers details

  • Anonymous

    Chipcorrea, too easy to be true, I guess Jmeter recorded the request and you replaed and all was green but that doesnt mean the server app was hit, unless your app updates something in a DB and you see the changes there, also in a server log then you could say it really work.

Leave a comment

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