Sahi Pro - Load Testing with Sahi Pro
abstract
Sahi Pro lets you run load tests on your application. There are 2 Sahi scripts involved in this. One is used to generate the load. This script is called the noise and is run on a headless browser. The steps in the noise file are generally in an infinite loop so that they never terminate. The other script is called the subject. The subject is the script whose steps you would like to measure periodically at different loads.
Setting up
-
Get the headless browser, PhantomJS. Read this article to add PhantomJS to Sahi.
-
Start Sahi Pro. PhantomJS should be visible on the Dashboard as one of the browsers.
warningPhantomJS is normally visible on the Dashboard even if it is not installed. Make suresahi/ext/phantomjs/phantomjs.exe
exists. -
On the dashboard, click on the 'Bin' link. This will open up a command prompt at userdata/bin.
-
On the command prompt, run
dload.bat demo/load/noise.sah demo/load/subject.sah http://sahitest.com/demo/training/ firefox
-
Run 1 (min) thread(s) of noise.sah on PhantomJS (This will not be visible)
-
Run subject.sah on firefox browser and store the time of steps. Subject will be run 3 (subjectRepeatCount) times for averaging.
-
Wait for 5 seconds (interval).
-
Run 2 (incrementBy) more threads of noise.sah on PhantomJS.
-
Run subject.sah 3 times on firefox and store results.
-
Keep incrementing the noise threads at periodic intervals, run the subject 3 times, and store results, till it reaches max noise threads. Once done, click on 'Logs' link on the Dashboard to view results.
Reporting
Reports show the most expensive steps and URLs in the load test.
Clicking on the circles in the graphs takes you to the step/URL which was expensive.
Most Expensive Steps Across Different Loads:
Most Expensive URLs Across Different Loads:
Steps:
info
Note: The table contents are truncated in this image. You should see entries for
Load: 9
as well, in the actual log.To test your application, go to userdata/scripts/demo/load folder.
-
Open
noise.sah
and add your sequence of steps. These steps should be representative of a normal user interaction.
Note that your steps should be in awhile(true){}
loop so that the threads don't die out. (Refer to existing noise.sah)
-
Open
subject.sah
and specify the sequence of steps whose reaction times you would like to measure at different loads.
-
The parameters
min
,max
,incrementby
,interval
,subjectRepeatCount
etc. can be edited indload.bat
file.
-
It is also possible to involve multiple machines in creating the load by modifying the
NODES
variable (Look indload.bat
)
-
To get HAR logs and URL timing information, use
_startHarLogging()
in your script to start logging HAR logs. To stop the logs, use_stopHarLogging()
.
Running load tests through ANT
Sahi supports load testing through an ANT target.Copy the following content to an empty file and save the file as an xml, say
dload.xml
in your <SAHI_INSTALLATION_FOLDER>
.You can now run the default ANT target in the xml file as
ant -f dload.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
* Copyright Tyto Software Pvt. Ltd.
*/
-->
<project name="demo" default="dloadrun">
<taskdef name="sahiload" classname="in.co.sahi.ant.DAntLoadRunner" classpath="lib/ant-sahi.jar"/>
<target name="dloadrun">
<sahiload scriptsPathMaster="scripts"
subject="demo/load/subject.sah"
baseurl="http://sahitest.com/demo/training/"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
browsertype="chrome"
noise="demo/load/noise.sah"
noiseBrowserType="phantomjs"
min="1"
max="9"
incrementBy="2"
interval="5"
subjectRepeatCount="3"
ignorePattern=".*(svn|copied).*">
<node host="localhost" port="9999"/>
<!--
<node host="machine2" port="9999"/>
<node host="machine3" port="9999"/>
-->
</sahiload>
<antcall target="failsahi"/>
</target>
<target name="failsahi" if="sahi.failed">
<fail message="Sahi tests failed!"/>
</target>
</project>
Attributes and their description
info
taskdef classpath is relative to where ant is run from.
scriptsPathMaster | Specifies the path to the scripts folder. Can be the absolute path or a path relative to the userdata folder |
subject | Path to the subject script. |
baseurl | Specifies URL which is the starting URL for the subject and noise scripts |
sahihost | Hostname of the server where Sahi is running (Can be IP as well). Leave this as localhost |
sahiport | Port on which Sahi is running |
browsertype | The browser on which the subject script is run (can be IE, Firefox etc.) |
noise | Path to the noise script. |
noiseBrowserType | The browser on which the noise script is run (default phantomJS) |
min | The minimum number of noise browsers to run initially |
max | The maximum number of noise browsers to run finally |
incrementBy | The number of noise browsers to be run incrementally after the specified interval |
interval | The interval after which to increment the noise browsers by |
subjectRepeatCount | Number of times the subject script should be run at every noise level. It is good to run it more than 1 time to average out any random behaviour. |
node | Each node attribute specifies a machine on which the noise browsers should run. Add as many node entries as there are machines to run. The nodes may or may not include the Master machine (localhost). If the Master machine is not included, the noise browsers will not be run on the Master . There can be 1 or more nodes. |
Command to execute the above ANT target
ant -f dload.xml