What is Tsung and what is load testing?
One of the tools we use on the ISD team is Tsung. We use it to load test our web based applications in our staging environment. In this article we’re going to go through all the steps necessary to setup and run a simple as possible load test. Later we’ll look at how to configure Tsung and your environment for more complex scenarios.
Load testing is the process of examining a system (such as an application or a device) under higher than normal load in order to see how it performs under those conditions. It is a very important part of testing any application where load amounts are variable and unpredictable. Load testing is a huge topic by itself but in brief here a few things that load testing can do for you:
- Benchmark the performance of the application under load so that it can be compared to previous or future releases.
- Identify trouble spots in the application that break only when under high load.
- Help managers more accurately anticipate and plan for resources such as hardware, employees, bandwidth etc.
- Test whether the application is going to perform within its specifications under projected usage.
Tsung is a distributed, multi protocol load testing framework that can be used to stress web and database servers. Tsung has many things in common with other load testing suites but what distinguishes it from the others is its ability to produce very high load with limited resources. Tsung is written in Erlang, (a language built for high concurrency and fault tolerance) but uses simple XML files for its configuration of load testing scenarios.
Let’s Try it Out
The best way to get familiar with Tsung is just to try it out. It doesn’t take long at all to get a working Tsung load test up and running.
My examples were all run on Kubuntu 10.10 so you may have to adapt tweak these steps a little for other distributions.
The first thing you’ll need to do is install erlang-nox on all of the servers that will be tested or used as clients.
$sudo apt-get install erlang-nox
You should now be able to run
from your terminal and be in an Erlang shell. Type ‘Control-C’ and then ‘a’ to get out of the Erlang shell.
Next you’ll need need to install Tsung on your client machine. Tsung has not yet been packaged for Ubuntu but a Debian package is available.
$sudo dpkg -i tsung_1.3.3-1_all.deb
The following are needed for generating reports from the collected data:
$sudo apt-get install gnuplot perl libtemplate-perl python-matplotlib
You should now be able to run
You should then see ‘Tsung version 1.3.3′ displayed.
In order for Tsung to communicate with the other servers in the cluster and obtain statistics from them, password-less ssh must be enabled between the client machine(s) and the server machine(s).
$ssh-copy-id -i ~/.ssh/id_rsa.pub username@host
If for the purposes of experimenting you’re just running both client and server on one machine the above is not necessary.
You will recall that Tsung uses XML files for its configuration. Here is an example of pretty much the smallest Tsung configuration file:
<!DOCTYPE tsung SYSTEM “/usr/share/tsung/tsung-1.0.dtd”>
<!– Minimal tsung configuration file –>
<server host=”localhost” port=”8000″ type=”tcp”/>
<arrivalphase phase=”1″ duration=”1″ unit=”minute”>
<users interarrival=”1″ unit=”second”/>
<session name=”foo” probability=”100″ type=”ts_http”>
<http url=’/’ version=’1.1′ method=’GET’/>
Save the above file and give it a name, for example minimal.XML.
Basically before it can run Tsung has to know 4 things: the IP address of the machine on which the client is running, the IP address of the machine on which the server is running, how many users to create, and what each user is to do. In the above example both the client and the server are running on localhost, a new user will created each second for one minute, and each user will run one get request of the home page of the tested site.
Before we can run our simple load test we’ll need to run our server. I am running a Django application that’s listening on port 8000 so you’ll need to change your server line to match your environment. Once your server is running you’re ready to start.
$sudo tsung -r erl -f minimal.xml start
Note: Normally you do not need to run Tsung via sudo, but the very first time that it is run it needs to create files that require root access.
If Tsung ran without any problems you should have seen displayed the path to the directory where the log files for this load test can be found. CD to that directory and generate your report like this:
You can now view your report from a browser:
$firefox report.html &
Congratulations! You’ve just setup and run your first Tsung load test. Next time we’ll look at more complex scenarios and delve deeper into Tsung’s capabilities.