Saturday, 12 November 2011

Tsung: Web Application Performance and Stress Testing


The purpose of Tsung is to simulate users in order to test the scalability and performance of IP based client/server applications. You can use it to do load and stress testing of your servers.You can test with Tsung HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP and XMPP/Jabber.


Installation
To install tsung you need Linux distributive, I am using debian.
  1. apt-get install erlang
  2. apt-get install gnuplot-nox libtemplate-perl libhtml-template-perl libhtml-template-expr-perl
  3. Download latest distributive  - http://tsung.erlang-projects.org/dist/tsung-1.4.1.tar.gz
  4. tar -zxvf tsung-1.4.1 .tar.gz
  5. cd tsung-1.4.1
  6. ./configure && make && make install
  7. also you should create .tsung folder in root and tsung.xml inside it (ypu can see tsung.xml examples in tsung folder)
Thats all after typing tsung command in console, you should see tsung help information.

Configuration tsung.xml
   1. Server configuration
<servers>
   <server host="example.com" port="80" type="tcp"></server>
</servers>

2.Client configuration
Very important to specify  maxusers
<clients>
     <client host="localhost" use_controller_vm="true" maxusers="7000"/>
</clients>

 3.Define the load that we want our server to be exposed to
Tsung simulates the user arrivals in the application. The example below describes 2 different phases.The first will last 5 minutes and every second will come 10 new users, at all 5 minute x 10 users = 3000 users. Next phase will last 10 minutes and every second will come 25 new users , 10 minutes x 25 users = 15 000 users.
<load>
<arrivalphase phase="1" duration="5" unit="minute">
<users arrivalrate="10" unit="second"/>
</arrivalphase>
<arrivalphase phase="2" duration="10" unit="minute">
<users arrivalrate="25" unit="second"/>
</arrivalphase>
</load>

4. Recording script
To test smth, you should provide sequence of actions, what tsung should to do. This configuration you should put in  tag <sessions> ..</sessions> tsung.xml.  I will test web-site and easiest way it's to use tsung proxy to record actions. To achieve that we must first tell our browser to pass through a proxy listening to port 8090 (Firefox preferences - Advanced - Network - Settings) and ip of the your server.

To start recording use tsung-recorder start
To stop recording use tsung-recorder stop

We will end up with an xml representing the newly recorded session located in ~/.tsung/tsung_recorderyyyymmdd-HH:MM.xml. Just copy-paste this session into the main tsung xml file:
<sessions>
<session name='login_settings' probability='25' type='ts_http'>
<request> <http ... /> </request>
<thinktime random="true" value="4"/>
<transaction name="Login">
<request> ... </request>
...
</transaction>
<request> ... </request>
...
</session>
<session name='login_add_people' probability='75' type='ts_http'>
...
</session>
...
</sessions>

Running
To run Tsung tsung start and to stop tsung stop. Tsung is logging data in the ~/.tsung/log/yyyymmdd-HH:MM folder. To view status tsung status. Wery important to set ulimit value greater than default, type in console ulimit -n 100000. One time i have situation when tsung process not terminated, but tsung stop command didn't worked, in this case you could use ps ax | grep tsung to see all processes and  kill -9 <process pid>

Generating HTML report
In order to use these info, we launch the tsung_stats.pl script which will produce a nice html report.
cd .tsung/log/yyyymmdd-HH:MM
and copy tsung_stats.pl file here or specify absolute path type perl tsung_stats.pl . This script will create in this folder reports.


Here is my example, of Simultaneous Users:

And more reports examples here

References:
The Tsung manual 
Tsung home page
This article in Russian
Tsung presentation in Russian

5 comments:

  1. The below line not work for me
    /configure && make && make install

    But this work for me
    ./configure && make && sudo make install


    Thanks ..Good Artical

    Email Id:shashi.gupta1988@gmail.com

    ReplyDelete
  2. Thanks for this straightforward and easy-to-follow post! It got me up and running on my first day using tsung :)

    ReplyDelete
  3. Hello. I am very new to load testing. I want to do Performance Analysis of a messaging server for an enterprise application which uses XMPP. I want to test the performance during login, chat sessions, presence service notifications, etc., when under load. Tsung seems to be an apt tool for my requirements.

    I am not able to completely analyse the results (both graphical and statistical) that I have obtained. I have referred the Tsung documentation and other websites. But I still have few queries. Could someone please help me with this??

    Here are log details from ‘connect.txt’. This load is generated for max 100 users with arrivalphase of 1min and interarrival of 0.5second.

    0 1.3 0.8100961538461539 0.3003341117366558 1.364990234375 0.566162109375 0 0
    10 2.3 1.0076851222826086 0.28226948557783504 1.384033203125 0.55517578125 0.8100961538461539 13
    20 1.5 0.9711100260416666 0.2764732010730768 1.384033203125 0.5380859375 0.9363335503472222 36
    30 2.2 1.1567937677556817 0.36105147083378225 1.93896484375 0.5380859375 0.9465619255514706 51
    40 1.4 0.9898332868303571 0.2942442039408825 1.93896484375 0.5380859375 1.0099194670376712 73
    50 1.3 1.0449969951923077 0.28618096652614605 1.93896484375 0.5380859375 1.0066872081537357 87
    60 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    70 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    80 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    90 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    100 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    110 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100
    111 0 0 0 1.93896484375 0.5380859375 1.01166748046875 100

    Main Statistics:

    Name: connect
    highest 10sec mean: 1.16msec
    lowest 10sec mean: 0.971msec
    Highest Rate: 2.3/sec
    Mean rate: 0.73/sec
    Mean: 1.01msec
    Count: 100

    Now consider the data line for 20seconds. As per ‘stats.conf’, ‘connect’ is of type ‘sample’ and the format is:
    name: connect;
    count (during the last10sec): 1.5;
    mean: 0.9711100260416666;
    stddev: 0.2764732010730768;
    max: 1.384033203125;
    min: 0.5380859375;
    globalmean: 0.9363335503472222;
    globalcount: 36;

    1) What is count exactly? I can tell that (using globalcount) from 0-10 sec 13 users were connected. From 10-20 sec 23 more users were connected. But what is count representing?
    2) mean is calculated every 10 sec. But what is globalmean? How is it calculated?
    3) max and min are representing maximum and minimum of what ?
    4) How is Mean Rate calculated in Main Statistics table?
    5) As per the log file, lowest 10sec mean must be 0.81. But why is it 0.97msec in Main Statistics table?

    Any pointers or directions will be really helpful!!!

    Thanks and Regards

    ReplyDelete