11
GRINDER Open Source Approach in Performance Testing Jadumani Jena [email protected] Performance Testing Group Assurance Services Unit , About the Document: As open source tools have been gaining pace with commercial tools, this document will assist you to perform most of the functions in performance testing area using GRINDER, an open source jython based load testing tool released under GNU GPL. Document Navigation: I. Downloading Grinder, Installing and Set up II. Launching GUI III. Grinder Console IV. Script Recording V. Script Modelling View Server Response VI. Script Correlation VII. Parameterization VIII. Execution IX. Result Analysis GrinderAnalyzer Grinder Installation & Set up: The downloader is available at http://sourceforge.net/projects/grinder/ . Download the latest version and unzip it to local directory. The grinder version that I used to prepare this document was 3.4. Now to set up grinder, follow the below steps. Please ensure you have JDK 1.5 or latter in your machine and java PATH variable is set properly.

GRINDER - An Open Source Performance Testing Approach

Embed Size (px)

DESCRIPTION

This document will help on Grinder Load Testing, Grinder Scripting, Grinder Correlation, Grinder Parameterization. Pls leave your feedback after downloading.

Citation preview

Page 1: GRINDER - An Open Source Performance Testing Approach

GRINDER Open Source Approach in Performance Testing

Jadumani Jena

[email protected]

Performance Testing Group

Assurance Services Unit ,

About the Document:

As open source tools have been gaining pace with commercial tools, this document will assist you to

perform most of the functions in performance testing area using GRINDER, an open source jython

based load testing tool released under GNU GPL.

Document Navigation:

I. Downloading Grinder, Installing and Set up

II. Launching GUI

III. Grinder Console

IV. Script Recording

V. Script Modelling – View Server Response

VI. Script Correlation

VII. Parameterization

VIII. Execution

IX. Result Analysis – GrinderAnalyzer

Grinder Installation & Set up:

The downloader is available at http://sourceforge.net/projects/grinder/. Download the latest

version and unzip it to local directory.

The grinder version that I used to prepare this document was 3.4.

Now to set up grinder, follow the below steps. Please ensure you have JDK 1.5 or latter in your

machine and java PATH variable is set properly.

Page 2: GRINDER - An Open Source Performance Testing Approach

From /grinder_home/examples copy the grinder.properties to grinder_home. This file is

basically a grinder configuration file.

Create 4 batch files. Each batch file code is given below. Just change the local file path for

your system.

1. setGrinderEnv.bat : This is the batch file that should always be run first. If any

change is made to grinder.properties, then this file should be rerun.

Code:

set GRINDERPATH="C:\grinder-3.4"

set GRINDERPROPERTIES="C:\grinder-3.4\grinder.properties"

set

CLASSPATH=%GRINDERPATH%\lib\grinder.jar;%GRINDERPATH%\lib\python.jar;C:/

jython2.2.1/jython.jar

set JAVA_HOME="C:\Program Files\Java\jdk1.5.0_17"

PATH=%JAVA_HOME%\bin;%PATH%

2. startConsole.bat : This file should always run after setGrinderEnv.bat. This file will

launch the grinder GUI.

Code:

call "C:\grinder-3.4\setGrinderEnv.bat"

echo %CLASSPATH%

java -cp %CLASSPATH% net.grinder.Console

3. startAgent.bat : This file should run after startConsole.bat. This batch file will

start the grinder agents from where load will be generated. For the time, assume

that your own machine is grinder agent too. If you want to run a test, then only

you should run this file.

Code:

call "C:\grinder-3.4\setGrinderEnv.bat"

echo %CLASSPATH%

java -cp %CLASSPATH% net.grinder.Grinder %GRINDERPROPERTIES%

4. startProxy.bat : This file should run after setGrinderEnv.bat. It is used to start the

grinder proxy server for script recording purpose.

Code:

call "C:\grinder-3.4\setGrinderEnv.bat"

echo %CLASSPATH%

java -cp %CLASSPATH% net.grinder.TCPProxy -console -http > grinder.py

Page 3: GRINDER - An Open Source Performance Testing Approach

With these settings, Grinder is ready to serve now.

Launching Grinder:

Now to start the Grinder components, we need to run the batch files one after another.

Starting Grinder GUI:

Run setGrinderEnv.bat . Command prompt screen will blink for a moment.

Run startConsole.bat. Command prompt screen will be displayed without any error. Wait

for few seconds and the grinder GUI console will pop up.

Note:

In the picture above, see that below the file option, 2 options are inactive. They are meant to control

the test execution. Since agent (which generates the load) is not running, so they are not enabled.

Page 4: GRINDER - An Open Source Performance Testing Approach

Starting Grinder Agent:

If you want to run scripts, then first you need to start the console as above. Then run

startAgent.bat. If successfully run, then the below message must be displayed in cmd prompt. The

console machine ip shown below is set in the properties file.

Note: If a remote machine is required to generate load, then you can install the grinder in this

machine as said above. But in the properties file, change the console ip to other machine which runs

the console. Start the console in the console (controller) machine and then run the agent batch file

from the remote machine. This will connect the remote agent with the console.

Starting Grinder Recorder:

To record scripts, first run the environment batch file followed by startProxy.bat. A cmd prompt will

show up with below message if successful.

Above is the default port number that grinder will use for recording. Before recording, change the

browser proxy to localhost and 8001.

Another floating tool bar will be displayed which controls the script recording.

Note: If your organization uses a proxy, then refer this

(http://grinder.sourceforge.net/g3/tcpproxy.html#options-summary ) link to change the proxy

details in startProxy.bat.

Page 5: GRINDER - An Open Source Performance Testing Approach

Grinder Console:

In grinder console many options are available and explained as below.

Script: This tab is primarily a python script editor. It is useful to set the working scripts

directory, script editing, selecting scripts to run, selecting properties file. You need to set

the root directory when working for the first time.

Process: This tab will display the runtime status of the connected load generators along

with virtual user (thread) information. This tab will show information when agents are

connected to the console.

Results, Graphs: These tabs will display the runtime test results in tabular and graphical

format respectively. Usually the results tab will be of more importance as it has extended

result data where as Graphs tab is somewhat poor.

Action: The Action tab will control the test execution. If the agents are connected, then

only we can start the process (starting the execution) and reset the process. Stop process

Page 6: GRINDER - An Open Source Performance Testing Approach

will kill the agents and you need to reconnect them with the console. Stop collection will

stop the result samples collection without affecting the execution.

Recording:

You need to start the grinder startProxy.bat to get the floating recording tool bar shown below.

Before you start recording using this tool bar, first set the browser proxy to localhost and 8001 as

this is the default proxy that grinder uses to communicate between the client and the server.

Page 7: GRINDER - An Open Source Performance Testing Approach

Once above setting is done having the recording bar still running, restart the browser and type in the

url that you want to record. From here onwards, your browser activities will get recorded in python

language. You can also mark the start of new transactions/pages by inserting new comments from

the floating bar. When you stop the recorder, the generated script will be written into grinder.py

inside the home directory. You can edit startProxy.bat to generate script with other names too.

Script Modelling – View Server Response:

Once the script is ready, next task is to validate if the script is working fine. This requires us to see

how the server is responding to the requests in the script. For this, I have written the below function

(entire script is available in the attachment) which can be invoked to generate the response for each

page.

Note: In Grinder script, each component of a screen is recorded as page. So a scenario having 10

pages might have 20 pages in the script.

Response Saving Example:

Below is python function generated by grinder recorder. Now I will add a custom function to save

the response of page1.

class TestRunner:

"""A TestRunner instance is created for each worker thread."""

# A method for each recorded page.

def page1(self):

"""GET / (request 101)."""

result = request101.GET('/WebTours/')

return result

Modelled Script: syspath="C:/grinder-3.4/response/page" #path to save server response

class TestRunner:

"""A TestRunner instance is created for each worker thread."""

# A method for each recorded page.

def page1(self):

"""GET / (request 101)."""

result = request101.GET('/WebTours/')

x=self.output(result.text) # result.text is textual server response

return result

def output(self,response):

file = open(syspath + str(time.time()) + ".htm" , "w")

print >> file, response

file.close()

return

Page 8: GRINDER - An Open Source Performance Testing Approach

Note: Below statement will open a file with name page<current time>.htm in write mode in the path provided before the class. file = open(syspath + str(time.time()) + ".htm" , "w")

This is a reusable function and can be used at the end of all pages in the python script. But you must import the followings at the script top. import time

import sys

from java.lang import String Once the script is run for 1 user, you can verify the response from the given path and see the server error messages.

Script Correlation:

Once you know what values are to be correlated by examining the script and the server response, you need to correlate those values as explained below. This correlation is a sample test site called HP Webtours which comes freely with HP LoadRunner. The scenario is: Login -> Search Flight -> Select Flight -> Payment -> Logout. In this scenario, 2 values are to be correlated; i.e. sessionid and flight value. Below is correlation code to capture and reuse session id. response=result.getText()

searchstr = " name=userSession value="

#actual response: <input type=hidden name=userSession value=

#103131.719238558fDAtiDHpiAiDDDDDDVicQpAczif>

startCutPos = result.getText().find(searchstr) + len(searchstr)

endCutPos = startCutPos + 43 # 43 is the length of value to be extracted

self.flight = response[startCutPos:endCutPos]

print "out Flight Value=%s" %self.flight # will display in cmd prompt

return self.flight You can use above code piece by changing the “searchstr” and the length of the value to be correlated. Again while using “self.flight” in subsequent requests, you need to add below highlighted code. def page6(self):

"""POST login.pl (request 601)."""

self.token_sesid = \

self.subString

result = request601.POST('/WebTours/login.pl',

( NVPair('userSession', self.token_sesid),# hard coded value replaced

NVPair('username', 'lewis'),

NVPair('password', 'password'),

NVPair('login.x', '58'),

Page 9: GRINDER - An Open Source Performance Testing Approach

NVPair('login.y', '13'),

NVPair('login', 'Login'),

NVPair('JSFormSubmit', 'off'), ),

( NVPair('Content-Type', 'application/x-www-form-urlencoded'), ))

Script Parameterization:

To parameterize session specific data, please use the following piece of code along with changes specific to your data file location. Add the following code piece above the class TestRunner in the python script. You need to add an extra line “from java.util import Random” at the script top to use the random function. parampath="C:/grinder-3.4/data"

#Variables Used for Parameterization

users = []

passwds = []

# Creating the Data pool

temp = []

for line in open(parampath + "/login.csv", 'r'):

temp = line.split(',')

users.append(temp[0].strip())

passwds.append(temp[1].strip()) Above, a csv file with name “login” having user id and password with a comma separation must exist in the parampath. Before replacing the hard coded values, you need to insert the below random function code first. rand = Random()

number = rand.nextInt(len(users))

print users[number]

print passwds[number] Henceforth, you can replace the hard coded user id and password with “users[number]” and “passwds[number]” (without quotes) Note: Refer attached script to see working parameterization

Script Execution:

Test Execution is configured by “grinder.properties” file. The script that you want to execute should be added to grinder.script. You can change the no of virtual users by changing grinder.threads value. If more users are required, then grinder.processes can also be changed. If 100 users are required, then grinder.processes = 1 and grinder.threads = 100. But there is always trade off between these 2 values.

Page 10: GRINDER - An Open Source Performance Testing Approach

Note: From a 2GB RAM machine, it is noted that Grinder can run 800 virtual users (threads) Other important parameters like run duration, iterations can also be set. The properties file is self explanatory and can be changed as per requirement. To execute script, agent must be started first. Using grinder console, execution can be controlled as explained in the Grinder Console section. After the test is over, the log file (path specified in properties file) will have 2 output files (data<agent>.txt and out<agent>.txt) for each run and each agent. Sampling rate for result collection can be controlled using the given options in the console.

Result Analysis - GrinderAnalyzer:

After a grinder test is over, the output files are generated in the log path. These files will contain error information, debug messages, print messages and output test data as displayed in the results tab of the console. But these results is in raw format and cannot be presented to clients. Here comes GrinderAnalyzer, another open source initiative meant to generate graphs/reports from output log files of Grinder.

Installation: The downloader, set up instructions and all related information is available in http://track.sourceforge.net/ You should have jython copied in your machine and JYTHON_HOME path variable must be defined before. After downloading, unzip it to your local directory. Follow below instructions to generate report. 1. Copy data* and out* files generated by grinder to installation directory of grinderAnalyzer 2. CD to installation directory of grinderAnalyzer 3. Run below command for your log files. Syntax: jython ./analyzer.py "<grinder data File(s)>" <grinder out file>

[number of agents]

E.g: jython ./analyzer.py data_agent0-16.log out_agent0-16.log

After running this command, a folder “grinderReport” will be generated. This will contain basically 3 files for each page; i.e. *.bandwidth, *.perf, *.rtime. There will also be a consolidated report “Report” as shown below.

Page 11: GRINDER - An Open Source Performance Testing Approach