Tsung (formerly known as idx-Tsunami) is a powerful, open-source, multi-protocol distributed load testing tool. Written in Erlang, it’s licensed under the GPL and excels at simulating a high number of concurrent users to stress-test servers. Tsung supports a wide range of protocols, including HTTP, WebDAV, LDAP, MySQL, PostgreSQL, SOAP, and XMPP. Its distributed architecture allows you to simulate hundreds of thousands of users from a single system or scale out across a cluster of machines.
Installation on CentOS
This guide walks you through installing and configuring Tsung on a CentOS system.
-
Install Erlang: Tsung is written in Erlang, so you’ll need to install it first. Use the following command:
[ahmed@server ~]$ yum install erlang -
Download Tsung: Download the Tsung source code. You can find the latest version on the official Tsung website or a mirror. This example uses version 1.5.1.
[ahmed@server ~]$ wget http://tsung.erlang-projects.org/distrib/tsung-1.5.1.tar.gz # Replace with the actual download link -
Extract Tsung: Extract the downloaded archive to the
/optdirectory.[ahmed@server ~]$ tar -xvzf tsung-1.5.1.tar.gz -C /opt -
Configure Tsung: Navigate to the extracted directory and run the configuration script.
[ahmed@server ~]$ cd /opt/tsung-1.5.1 [ahmed@server ~]$ ./configureNote: You may need to install additional dependencies if the configure script reports missing libraries. Use
yumto install these dependencies. -
Compile Tsung: Compile the Tsung source code.
[ahmed@server ~]$ make -
Install Tsung: Install the compiled binaries to your system.
[ahmed@server ~]$ make install
Verifying the Installation
After installation, verify that Tsung is correctly installed and accessible in your system’s PATH.
[ahmed@server ~]$ tsung -v
Tsung version 1.5.1
[ahmed@server ~]$ tsung
Usage: tsung <options> start|stop|debug|status
Options:
-f <file> set configuration file (default is ~/.tsung/tsung.xml)
(use - for standard input)
-l <logdir> set log directory where YYYYMMDD-HHMM dirs are created
(default is ~/.tsung/log/)
-i <id> set controller id (default is empty)
-r <command> set remote connector (default is ssh)
-s enable erlang smp on client nodes
-p <max> set maximum erlang processes per vm (default is 250000)
-m <file> write monitoring output on this file (default is tsung.log)
(use - for standard output)
-F use long names (FQDN) for erlang nodes
-w warmup delay (default is 1 sec)
-v print version information and exit
-6 use IPv6 for Tsung internal communications
-x <tags> list of requests tag to be excluded from the run (separated by comma)
-h display this help and exit
This output confirms that Tsung is installed and provides a list of available command-line options.
Creating a Basic Tsung Configuration File
Tsung uses an XML configuration file to define the load test. Here’s a basic example (load.xml). You’ll need to adjust the host attributes in the <clients> and <servers> sections to match your environment.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd" []>
<tsung loglevel="warning">
<clients>
<client host="load_test_machine" cpu="2" maxusers="30000000"/>
</clients>
<servers>
<server host="web_server_to_test" port="80" type="tcp"/>
</servers>
<load>
<arrivalphase phase="1" duration="1" unit="minute">
<users arrivalrate="5" unit="second"/>
</arrivalphase>
</load>
<sessions>
<session name="es_load" weight="1" type="ts_http">
<request>
<http url="/postdata/Information"
method="POST"
contents_from_file="test.json" />
</request>
</session>
</sessions>
</tsung>
Explanation:
-
<clients>: Defines the machines that will generate the load. Replaceload_test_machinewith the hostname or IP address of the machine running Tsung.cpuspecifies number of cores to use.maxusersspecifies the maximum number of virtual users to simulate on that client. -
<servers>: Defines the server(s) being tested. Replaceweb_server_to_testwith the hostname or IP address of your web server.portspecifies the port the server is listening on (usually 80 for HTTP or 443 for HTTPS). -
<load>: Defines the load generation pattern. Thearrivalphaseelement defines a period of time (duration) and the rate at which users (virtual clients) will start their sessions. In this example, 5 users will start per second for 1 minute. -
<sessions>: Defines the sequence of requests a virtual user will perform. Thesessionelement defines a named session. Theweightattribute determines the probability of this session being executed. Thetypeattribute specifies the protocol (in this case, HTTP).<request>specifies single request to be sent.<http>element defines the HTTP request.urlattribute specifies the URL to request.methodattribute specifies the HTTP method (e.g., GET, POST).contents_from_fileattribute tells tsung to load the body of the request from specified file.
Creating the Request Body (test.json)
If your test case requires sending data in the request body (e.g., a POST request with JSON data), create a file (e.g., test.json) containing the data. In this example, the load.xml refers to test.json which contains the following:
{
"name":"ahmed",
"age":30
}
Running the Load Test
Once you have configured the load.xml file, you can start the load test using the following command:
tsung -f load.xml start
This command tells Tsung to use load.xml as the configuration file and start the load test.
Monitoring the Results
Tsung generates detailed logs and statistics in the ~/.tsung/log directory. A new directory is created for each test run, named according to the date and time of the test. Within this directory, you’ll find:
tsung.log: A log file containing information about the Tsung process itself.report.html: A graphical report that summarizes the test results. Open this file in a web browser to view charts and statistics on response times, error rates, and more.erlang.log: Erlang specific logstsung.xml: Copy of the tsung configuration used for the test.
The report.html is the most useful for quickly understanding the performance of your server.
Stopping the Load Test
Tsung will automatically stop when it reaches the end of the defined load phases in your configuration file. You can also manually stop the test using the following command:
tsung stop
Additional Resources
For more in-depth information and advanced configuration options, refer to the official Tsung documentation: