Introduction to The Grinder

June 4, 2008 – 3:32 pm

The Grinder is:

The Grinder is a JavaTM load testing framework that makes it easy to run a distributed test using many load injector machines.

Until recently, I had been reluctant to investigate The Grinder because I was unfamiliar with Jython/Python, and hesitant to dig into a new language. I was wrong.

Not only am I happy to have discovered that Python and Jython are not too difficult to pick up, but The Grinder is quite a flexible tool that has a lot of potential and I would say a nearly capable replacement for LoadRunner from a load generation perspective.

In this article I’ll review how to setup The Grinder and use Eclipse to edit your scripts. 

Install Software   

The Grinder comes with its own console application and primitive IDE, but I found using Eclipse and grinderstone to be much easier for creating and debugging scripts. 

Here’s how I set it up:

  1. Install Java 5 
  2. Install jython
  3. Install Eclipse IDE
  4. Install Grinder
  5. Install Grinderstone

Configure Eclipse   

After downloading, unzipping and installing the above software, the next step is to configure Eclipse.  In ‘Windows’ -> ‘Preferences’ -> ‘Pydev’ -> ‘Interpreter - Jython’ set the Juthon interpreter to the jython.jar where you have installed jython:

eclipse_jython_prefs

Create Project

Next, create a new Pydev project, call it GrinderIntro, specify a location where you want to save your grinder projects, and be sure to select the project type as “jython 2.1″ and deselect “Create default ’src’ folder…”:

eclipse_new_pydev_project

 

Set Project Properties

Next we need to add grinder.jar to the PYTHONPATH.  Right-click your new project and select ‘Properties’.  In the project properties dialog, select ‘PyDev - PYTHONPATH’ and click the ‘Add jar’ button for the bottom section, External Source Folders (and jars if jython).  Navigate to your grinder installation and select grinder.jar

eclipse_grinder_project_properties

Create Initial Folder Structure and Batch Files

We’re almost ready.  Next create some folders to hold batch files.  Create two top-level folders in the project named ‘bin’ and ‘logs’.

In the ‘bin’ directory, create 4 DOS batch files, which will be used to run The Grinder scripts outside of Eclipse using The Grinder console and agents:

1. setGrinderEnv.cmd


set GRINDERPATH=C:\Tools\grinder-3.0.1
set JYTHON_HOME=C:\Tools\jython2.2.1
set GRINDERPROPERTIES=..\grinder.properties
set CLASSPATH="%JYTHON_HOME%\jython.jar"
set CLASSPATH=%CLASSPATH%;%GRINDERPATH%\lib\grinder.jar
set JAVA_HOME="C:\Program Files\Java\jdk1.5.0_14"
PATH=%JAVA_HOME%\bin;%PATH% 

2. startAgent.cmd


pushd ..
call bin\setGrinderEnv.cmd
echo %CLASSPATH%
java -cp %CLASSPATH% net.grinder.Grinder %GRINDERPROPERTIES%
popd 

3. startConsole.cmd


call setGrinderEnv.cmd
echo %CLASSPATH%
java -cp %CLASSPATH% net.grinder.Console

4. startProxy.cmd


call setGrinderEnv.cmd
java -cp %CLASSPATH% net.grinder.TCPProxy -console -http > ..\grinder.py

Create grinder.properties and test script

The last step to getting a working grinder project is to create the ginder.properties file and a sample grinder test script in the top level of the project.

grinder.properties:


grinder.processes=1
grinder.threads=1
grinder.runs=1

grinder.useConsole=false

grinder.logDirectory=logs
grinder.numberOfOldLogs=0

grinder.script=script.py

Here is a very basic Grinder script that calls Google home page:


# ******************************************************
# IMPORTS
# ******************************************************
from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
from HTTPClient import NVPair
import random
import string

# ******************************************************
# MAIN
# ******************************************************
class TestRunner:
    def __call__(self):

        test = Test(1,"google.com Homepage")

        requestURL = 'http://www.google.com/'
        request = HTTPRequest(url=requestURL)
        request = test.wrap(request)
        response = request.GET()

        grinder.sleep(1000)

        return

    def __init__(self):
        # initialization
        defaultHeaders = \
            (NVPair('Accept-Encoding', 'gzip,deflate'),
             NVPair('Accept-Language', 'en,en-us;q=0.8,de-de;q=0.5,de;q=0.3'),
             NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
             NVPair('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12'),
             NVPair('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'),)

        connectionDefaults = HTTPPluginControl.getConnectionDefaults()
        connectionDefaults.setDefaultHeaders(defaultHeaders)
        connectionDefaults.setFollowRedirects(1)
        connectionDefaults.useContentEncoding = 1

        return

Next steps

From here, you can create and debug your Grinder scripts in Eclipse, then use the DOS batch files to run the agents and console for test execution. See the Grinder User Guide for more on how to create Grinder scripts.

In the next article, I’ll show how to create some library functions to create data files and LoadRunner-esque parameters. Stay tuned…

  1. 2 Responses to “Introduction to The Grinder”

  2. great post.
    looking forward to giving the Grinder a try. I tried with a much earlier version like 5 years ago.. but it looks totally revamped.
    thanks!

    By Corey on Jun 5, 2008

  3. thanks for the guide… look forward to the next one.

    By Joe on Jul 22, 2008

Post a Comment