Tsung HTTP Scripting Development

Source: Internet
Author: User
Tags app service

Tsung HTTP Scripting Development

Personal notes, for reference only

1. Tsung Introduction

Tsung is a distributed stress testing tool developed based on the Elang language, which supports multiple protocols for load testing of HTTP, WebDAV, SOAP, PostgreSQL, MySQL, LDAP, and JABBER/XMPP servers. The power of Tsung is that it can simulate the generation of a large number of users on a single machine. Compared to Apache Jmeter,tsung can easily simulate 40,000 requests/second, and there is no confusing GUI page, just need to configure in the XML file. If a single client cannot meet the stress test requirements, you can also use a multi-client cluster to load the server.

2. Installation

Deployment environment: Linux operating system

Before you install Tsung, you need to prepare some required modules, install Elang,tsung, and report generation modules.

Reference: http://www.cnblogs.com/tsbc/p/4272974.html

3. Tsung.xml

After the installation is complete, all the impersonated build users, the requested configuration is defined in the Tsung.xml file: Tsung load test the target server by performing Tsung.xml. All the contents of the script are encapsulated in the <Tsung></Tsung> tag pair:

<?xml version= "1.0"?>

<! DOCTYPE Tsung SYSTEM "/USR/SHARE/TSUNG/TSUNG-1.0.DTD" [] >

<tsung loglevel= "Info" >

...

</tsung>

1.1 Client&server

Scripting starts with defining the client and server. Client, which imposes load pressure on the server. For normal load testing, the client and server definitions are as follows:

<clients>

<client host= "localhost" use_controller_vm= "true"/>

</clients>

<servers>

<server host= "192.168.1.1" port= "+" type= "TCP" ></server>

</servers>

Throughout the load test process, the script uses a single client to test the unique server.

L USE_CONTROLLER_VM: The attribute is true meaning to use Erlang virtual machine as controller;

L Port: Indicates that the port of the app service is 80;

L TYPE:TCP indicates that the client and the server make TCP connection;

The Port,type item can be obtained from a communication message using Wireshark to obtain application services on the PC side.

To perform a heavy load test on a server, using only one client to significantly simulate a large number of requests to the server, you can use multiple virtual IPs to simulate more machines.

By default, the load is evenly distributed across all CPUs (by default a client has one CPU). The weight parameter is given a different set of capabilities for each client processing, assuming that only two client,weight values are

1, and 2, then the client with a weight of 1 will assume a 1/3 load, and the client with a weight value of 2 will assume a load of 2/3.

The default value of the Maxusers parameter is 800, and a single process of different operating systems establishes a limited number of socket links, typically no more than 1024. Therefore, if the number of users exceeds the limit, a new Erlang virtual machine needs to be opened to increase the number of users.

<clients>

<client host= "Loadnode2" weight= "1" maxusers= "40000" cpu= "1" >

<ip value= "192.168.122.3"/>

</client>

<client host= "Loadnode3" weight= "1" maxusers= "40000" cpu= "1" >

<ip value= "192.168.122.21"/>

</client>

<client host= "Loadnode4" weight= "1" maxusers= "40000" cpu= "1" >

<ip value= "192.168.122.11"/>

</client>

</clients>

<servers>

<server host= "10.9.195.1" port= "8080" type= "TCP" ></server>

</servers>

1.1 Defining load loads

The client imposes a load on the server by using multiple arrival phases Tags:

<load>

<arrivalphase phase= "1" duration= "unit=" Minute ">

<users interarrival= "2" unit= "second" ></users>

</arrivalphase>

<arrivalphase phase= "2" duration= "unit=" Minute ">

<users interarrival= "1" unit= "second" ></users>

</arrivalphase>

<arrivalphase phase= "3" duration= "unit=" Minute ">

<users interarrival= "0.1" unit= "second" ></users>

</arrivalphase>

</load>

The XML code above indicates that 2 users are generated per second at the start of the test in 10 minutes, 1 users per second in the second 10 minutes, and 10 users per second for the third 10 minutes.

You can also use arrivalrate instead of interarrival tags, but with different meanings:

<arrivalphase phase= "1" duration= "unit=" Minute ">

<users arrivalrate= "unit=" second "></users>

</arrivalphase>

Indicates that 10 new users are generated per second within the first 10 minutes of the start of a test. The tag can also maxuser limit the number of generated users, or use the loop loop tag to generate more users.

The duration of the load test is usually longer than the arrivalphase definition, because Tsung waits for all sessions to complete before it ends the load test.

3.3 <option>

Use the option tag in tsung.xml to set global variables. For example, the ThinkTime, SSL password, TCP/UDP cache size between HTTP request. The value of the attribute within the option tag overrides the value of the same attribute within the session tag as long as the value within the tag option is correct. For HTTP, the useragent value is usually set with the option tag.

<option type= "ts_http" name= "User_agent" >

<user_agent probability= ">"

mozilla/5.0 (X11; U Linux i686; En-us; rv:1.7.8) gecko/20050513 galeon/1.3.21

</user_agent>

<user_agent probability= ">"

mozilla/5.0 (Windows; U Windows NT 5.2; FR-FR; rv:1.7.8) gecko/20050511 firefox/1.0.4

</user_agent>

</option>

Probability represents the percentage of impersonation requests that are used by the user-agent during the entire load test, and if you set the User_agent usage percentage, all user_agent allocation percentages will be equal to 100%.

3.4 <Session>

The session tag describes the request that needs to be executed. Each pair of session tags has a given percentage. These percentages determine which session the newly generated user will perform, and the sum of all sessions must be equal to 100%. To count the response time for a set of requests, enclose this set of requests in a transaction tag pair. For example, to know the response time of a website login page, to include all requests to access the page into the transaction tag (including request html+ request home picture, etc.). The following describes an example of an HTTP script in the results statistics report in which the Index_request transaction will count the response time of the request index.en.html + header.gif. It is important to note that if the transaction contains ThinkTime, the responsetime in the results report also contains thinktime time.

There are several ways to set up ThinkTime:

<thinktime value= "" random= "true" ></thinktime>

Indicates that the thinktime is random, but the overall average is 20s.

To set the range of ThinkTime:

<thinktime min= "2" max= "random=" true "></thinktime>

3.5 HTTP

The following script represents the HTTP features commonly supported by Tsung, including GET, post requests, Basic authentication ...

URLs in the HTTP tag use an absolute path, overriding the URLs defined inside the server.

<sessions>

<session name= "Http-example" probability= "type=" >

<request>

<request>

Method= "GET" version= "1.1"

If_modified_since= "Fri, 2003 02:43:31 GMT" >

<thinktime value= "" random= "true" ></thinktime>

<transaction name= "Index_request" >

<request>

Method= "GET" version= "1.1" >

<request>

Method= "GET" version= "1.1" >

</transaction>

<thinktime value= "" random= "true" ></thinktime>

<request>

contents= "Bla=blu" >

<request>

contents= "Bla=blu&amp;name=glop" >

<www_authenticate userid= "Aladdin"

passwd= "Open Sesame"/>

</request>

</session>

<session name= "BackOffice" probability= "...>"

... </session>

</sessions>

Tsung 1.2. After the 2 version, provide the HTTP request header Add method:

<request>

<www_authenticate userid= "Aladdin" passwd= "open sesame"/>

Tsung 1.3.1 starts with the ability to manually add cookies:

<request>

<www_authenticate userid= "Aladdin" passwd= "open sesame"/>

</request>

However, the added cookie can only be used for the current request and requires the addition of cookie information to each request tag.

When using post or put, the content of the request is written in contents, and it is important to note that the XML escape character is required to convert the content into an XML encoding format, such as <, &, and%.

4. Tsung.xml use         4.1 New directory, copy configuration script

Create a new file under the root folder. Tsung directory for log and XML configuration, test configuration files can be referenced in the/usr/local/tsung/share/doc/tsung/examples/directory configuration.

[Email protected] local]#mkdir ~/. Tsung

[Email protected] local]#cp/usr/local/tsung/share/doc/tsung/examples/http_simple.xml ~/. Tsung/tsung.xml

The CP command copies the Http_simple.xml to the. Tsung folder and is named Tsung.xml, where the http_simple.xml is just a reference example and you need to edit the definition yourself.

You can actually upload the tsung.xml you have defined directly to the created. Tsung Directory and execute:

4.2 Executive Tsung.xml

[[email protected] local]# Tsung start

Starting Tsung
"Log directory is:/root/." tsung/log/20150812-1636 "
The report is generated in directory/root/. tsung/log/20150812-1636
4.3 Generating a chart file
Go to the directory where the report is located use the command/usr/lib64/tsung/bin/tsung_stats.pl to generate the report.
Depending on the installation directory, the command path differs, and you can use Find-name tsung_stats.pl in the root directory to find the directory where the tsung_stats.pl is located.

[Email protected] 20150812-1636]# /usr/local/tsung/lib/tsung/bin/tsung_stats.pl

Creating subdirectory Data

Creating subdirectory gnuplot_scripts

Creating subdirectory Images

No Data for Session

No Data for Perfs

No Data for transactions

No Data for Match

No Data for Event

No Data for Async

No Data for Size

SIZE_RCV is equal to 0!

Size_sent is equal to 0!

After execution, copy the entire 20150812-1636 to local, click report.html to view the load test results: Tsung is a hidden directory, it is recommended to copy the report to the/root/tmp temp directory and use WINSCP to get the local open.

Tsung HTTP Scripting Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.