martes, 29 de mayo de 2012

Deploying Tsung in a Cluster

Tsung is a load testing tool that allows you to simulate heavy loads of users. Installing it in a single node, its an easy task. However, when the load achieved by a single node its not enough for testing purposes, then it is necessary to deploy Tsung in different nodes, which makes the process a bit complicated.

This post attempts to explain you, how to deploy Tsung in multiple nodes (3 nodes). 1 controller and 2 secondary nodes. Notice that the controller manages/collects the information of the whole simulation process.

/*
* author Huber Flores
*/
# Install on each Node
$ su
# Perl Templating-Toolkit and the Gnu plotting utility to create HTML and graphical reports with the result data set.
$ apt-get install gnuplot-nox libtemplate-perl libhtml-template-perl libhtml-template-expr-perl
# download Tsung
#http://tsung.erlang-projects.org/dist/
$ tar -xvf tsung-1.3.3.tar.gz
$ cd tsung-1.3.3
# You need erlang-dev and erlang-src to compile tsung on ubuntu
$ apt-get install erlang-dev
$ apt-get install erlang-src
$./configure && make && sudo make install
#directory
/usr/local/share/tsung/
# create the .tsung/ directory in ~/.tsung (/home/huber/.tsung)
$ mkdir ./tsung
# create the configuration file and executed
$ tsung -f huberflores_example.xml start
#Configuration file is below this script
$ cd .tsung/log/20110614-21:58/
# Configure Each Node Communication
Change name to the host
$ nano /etc/hosts
172.17.x.x tsung1
172.17.x.x tsung2
172.17.x.x tsung3
# alternative
$ nano /etc/hostname
$ nano /etc/resolv.conf
local node
$ cd /root/.ssh
Create keys in each node
$ ssh-keygen -t dsa
$ chmod 600 .ssh/id_dsa
install the key in the remote node
$ cat id_dsa.pub >> /root/.ssh/authorized_keys
connecting ssh without a password
$ ssh-agent sh -c 'ssh-add < /dev/null && bash'
#try each node
$ ssh tsung1
$ ssh tsung2
$ ssh tsung3
# Each connection must be perfomed without password
# If this error emerged, then repeat "#Configure Each Node Communication" section.
Host key verification failed
Host key verification failed Host key verification failed
This is because tsung search by host name (not ip address).
view raw tsungconf.as hosted with ❤ by GitHub
Configuration file huberflores_example.conf
<!--
author Huber Flores
-->
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<!-- Client side setup -->
<clients>
<client host="tsung-node1" weight="1" maxusers="500">
<ip value="172.17.x.x"></ip>
</client>
<client host="tsung-node2" weight="1" maxusers="500">
<ip value="172.17.x.x"></ip>
</client>
<client host="tsung-node3" weight="1" maxusers="500">
<ip value="172.17.x.x"></ip>
</client>
</clients>
<!-- Server side setup -->
<servers>
<server host="172.17.x.x" port="80" type="tcp"></server>
</servers>
<!-- to start os monitoring (cpu, network, memory). Use an erlang
agent on the remote machine or SNMP. erlang is the default -->
<monitoring>
<monitor host="myserver" type="snmp"></monitor>
</monitoring>
<load>
<!-- several arrival phases can be set: for each phase, you can set
the mean inter-arrival time between new clients and the phase
duration -->
<arrivalphase phase="1" duration="2" unit="second">
<users interarrival="0.00125" unit="second"></users>
</arrivalphase>
</load>
<options>
<option type="ts_http" name="user_agent">
<user_agent probability="80">Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Galeon/1.3.21</user_agent>
<user_agent probability="20">Mozilla/5.0 (Windows; U; Windows NT 5.2; fr-FR; rv:1.7.8) Gecko/20050511 Firefox/1.0.4</user_agent>
</option>
</options>
<!-- start a session for a http user. the probability is the
frequency of this type os session. The sum of all session's
probabilities must be 100 -->
<sessions>
<session name='zompopo' probability='100' type='ts_http'>
<request><http url='/Uploader/uimage' version='1.1' contents_from_file='/root/.tsung/tsung_recorder20110713-15:50-1.bin' content_type='multipart/form-data; boundary=---------------------------12060338813221352851214549942' method='POST'></http></request>
</session>
</sessions>
</tsung>

How to Bundle an Amazon Instance (instance store)

A detailed tutorial for bundling an Amazon instance.


/*
* author Huber Flores
*/
# Upload your keys to your instance (*.pem files)
$ scp -i your_PrivateKeyFile.pem -r /PrivateKeysPath/huberfloresPrivateCertKeys.zip ubuntu@ec2-x-x-x-x.compute-1.amazonaws.com:/home/ubuntu/
# Connect to your instance (local keys)
$ ssh -i your_PrivateKeyFile.pem ubuntu@ec2-x-x-x-x.compute-1.amazonaws.com
$ sudo su
$ mkdir /mnt/img-mnt
# put cert.pem and *.pem in /mnt/img-mnt or another folder depending on the AMI
$ chmod 777 /mnt/img-mnt/
$ cd img-mnt/
# Bundle the image
$ ec2-bundle-vol -r i386 -d /mnt/ -p "myami" -u 111222333 -k /mnt/img-mnt/your_PrivateKeyFile.pem -c /mnt/img-mnt/your_PrivateKeyFile_cert.pem
# AmazonID is a long number. For example 111-222-333, you have to remove the hyphens 111222333
# issues that can emerged
# if fails due to limited space, then delete smt from disk
# also, this process will create an image in ./tmp/image, you have to delete it
# Notice that "-d /mnt" specifies the bundling point, thus this can solve the problem if /tmp has small space
Copying / into the image file /mnt/myami...
Excluding:
/sys/kernel/debug
/sys/kernel/security
/sys
/proc
/dev/pts
/dev
/dev
/media
/mnt
/proc
/sys
/etc/udev/rules.d/70-persistent-net.rules
/etc/udev/rules.d/z25_persistent-net.rules
/mnt/myami
/mnt/img-mnt
1+0 records in
1+0 records out
1048576 bytes (1.0 MB) copied, 0.0098151 s, 107 MB/s
mke2fs 1.41.11 (14-Mar-2010)
warning: Unable to get device geometry for /mnt/myami
Bundling image file...
Splitting /mnt/myami.tar.gz.enc...
Created myami.part.00
Created myami.part.01
Created myami.part.02
Created myami.part.03
.
.
.
Creating bundle manifest...
ec2-bundle-vol complete.
# Upload to S3 (use the keys not the files)
$ ec2-upload-bundle -b MyInstanceBucket -m /mnt/myami.manifest.xml -a AccessKey -s SecretKey
The specified bucket is not S3 v2 safe (see S3 documentation for details):
MyInstanceBucket
Are you sure you want to continue? [y/N]y
Uploading bundled image parts to the S3 bucket TNodeBucket ...
Uploaded myami.part.00
Uploaded myami.part.01
.
.
.
Uploaded myami.part.90
Uploaded myami.part.91
Uploading manifest ...
Uploaded manifest.
Bundle upload completed.
# Register image
$ ec2-register MyInstanceBucket/myami.manifest.xml -n myinstance -K your_PrivateKeyFile.pem -C your_PrivateKeyFile_cert.pem
IMAGE ami-cxxxxxab
view raw amazonbundle.as hosted with ❤ by GitHub
This is a working document. If there are any errors, or if you disagree with anything which I have said, or have any suggestions for improvements please email me kyoraul@gmail.com.