Everyone test’s their web sites before going live (right??), even if it just means that you click on the site after pushing it to production, but how do you simulate the large user count your production environment may see? Apache’s Jakarta Project has a product called JMeter that fits this bill nicely, though getting it working can be intimidating. This post will walk you through setting up a basic web site test and where to configure the important bits with the latest JMeter release.
First, of course, you need to go download the latest JMeter binary release:
On OS X you will need the binary file that ends in .tgz, on Windows grab the binary that ends in .zip. You will also need a JRE setup on your system (to test if you do, drop to a command / terminal prompt, and enter ‘java -version’. If you get ‘bad command or file name’, go hit Sun’s site and download the appropriate JVM / JRE)
Unzip the file to any folder on your system, then navigate into the ‘/bin’ folder, and on OS X you will see a ‘jmeter’ terminal-like icon, and windows has a jmeter.bat file. Fire those up, and after thinking for a bit you should see a window like the following:
First, lets add an HTTP test. Right click on ‘Test Plan’, and add a ‘Thread Group’. This thread group defines how many threads (each thread represents a simultaneous user), and how many times you want your tests to be run. Setup your thread group something like this:
Next, right click on your new thread group, and choose ‘ HTTP Request HTTPClient’. This will add a simulated client request to our test plan. You can have many different client requests setup at once, and your threads will happily click through them as if they are users browsing your site. Then setup the HTTP Request HTTPClient options as illustrated below:
I will add 1 more sampler here, simulating a user searching for ‘Alagad’ on google. Add a request parameter by clicking the add under ‘Send parameters with the request’, enter the name ‘q’, and the value ‘alagad’. The path here will be ‘/search’, and the server name or IP will still be http://www.google.com
Now we are almost done, but how do we view the results of our test? If we started this running, it would happily send requests to google (please don’t overdo, I don’t want to tick them off with jmeter tests). Right click on your ‘Testing Google’ thread group, choose add, choose listener, and finally choose ‘Aggregate Report’. There are many different listeners here, but this one will give you a simple summary of the number of request made, how many if any had errors, and some average times for responses. Now go to the ‘Run’ main menu, and choose ‘Start’ at the top. If you have your ‘Aggregate Report’ node selected while it starts running, you will see that it gets populated with data right away. Play around with some of the other listeners, you can write results data to files, you can inspect the response on every single request (or only error requests, I recommend doing only errors), and you can even see general graphed metrics.
For fun, try testing your site without trusted cache, then with trusted cache. As you increase the thread count of your jmeter test, trusted cache makes a larger and larger difference. Happy testing!