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. 13 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

  4. Thanks for mentioning and reviewing on of releases of GrinderStone.
    Recently we have released a new version of GrinderStone 2.0.0 which has several issues fixes and improvements.
    It would be very nice if you would be able to take a look at it here: http://grinderstone.googlecode.com/files/com.googlecode.grinderstone_2.0.0.zip

    Thanks,
    Andrey.

    By Andrey Isaev on Sep 30, 2008

  5. We are glad to announce that finally GrinderStone 2.0 is released: http://code.google.com/p/grinderstone

    GrinderStone is a plugin for Eclipse IDE that allow users of The Grinder tool (Java load-testing framework) to debug created for it scripts. Along with debugging capabilities GrinderStone provided following features:
    - Dramatically decrease time needed to develop complex frameworks for testing Web application using The Grinder
    - Significantly improve ability to locate and correct Script errors
    - Almost all those features that are available in Eclipse IDE during Py scripts developments including auto-complete, syntax highlighting and etc
    - Ability to view and access variables used in Test Scripts for The Grinder
    - Ability to use breakpoints in Test Scripts

    What’s new in this release:
    - Proved compatibility with Eclipse IDE version 3.4
    - Compatibility with PyDev Eclipse IDE plug-in versions 1.3.19 and 1.3.20
    - Compatibility with release versions of The Grinder (version 3.0.1 and 3.1)
    - Ability to install GrinderStone via Eclipse IDE Software Update or manually
    - Bug fixes and improvements

    System Requirements:
    In order to work with GrinderStone plug-in it is required to:
    - Have any operating system that is supported by Eclipse IDE
    - Have The Grinder version 3.0.1 or 3.1 installed
    - Have JDK 1.5+ installed

    Download Link:
    http://grinderstone.googlecode.com/files/com.googlecode.grinderstone_2.0.0.zip

    Support group:
    http://groups.google.com/group/grinderstone-support

    ——————————————-
    Andruschuk Borislav
    Andrey Isaev

    By Andrey on Sep 30, 2008

  6. I have a question actually – this looks like it’d be right up our alley, as I’m looking to set the Grinder up at our site. I’m having difficulty with your instructions however – this is my first foray in to Jython, Python, and Eclipse.

    When you say “Here is a very basic Grinder script”, I assume I’m making that in Eclipse – and I named it “script.py” just by accident, but that seems to be right… what are the next steps here?

    By Kyle on Sep 30, 2008

  7. Kyle- the next steps are to create/modify your scripts and run them. See this page for more about running scripts using grinderstone: http://code.google.com/p/grinderstone/wiki/Usage

    You can also run them using the Grinder console, if you prefer, but during script development, I find it much easier to use the combination of Eclispe & grinderstone

    By charlie on Sep 30, 2008

  8. I am having issues getting data files to work in my grinder script(s).

    If I run the script as record, it works no problem. but I recorded a single user login to my webapp. Basically, I want to use a list of username,pass pairs from a data file.

    I also have a list of ’sites under test’ that I need to feed into the test script(s) so they itterate over the sites.

    My final goal is to be able to configure X number of users concurrently active across Y sites concurrently…

    can anyone point me to an example of how to use a datafile to feed a test script?

    also, love to see that code to setup a ramp-up / ramp-down rate.

    By steveo on Nov 11, 2008

  9. I am not being able to configure the eclipse with the grinder in this way. Kindly help.

    By suvendu kumar mohapatra on Mar 12, 2009

  10. Suvendu – You’ll have to provide a little more information about what you’ve tried and where you are having problems

    By charlie on Mar 15, 2009

  11. So I eventually got all this sorted out. It was a matter of specifying full paths in the config files for grinder.

    Ramp up/down is also not so hard, depending how much control you need. There are some great examples that don’t require too much re-working to integrate into custom scripts.

    I haven’t tried eclipse-based grinder install, I choose to install it and Jython manually, but I’ve no complaints about the integration — only that the errors and stack traces are somewhat misleading, only because they’re called through grinder.

    I consistently have to shell-out to run the scripts manually when there’s a problem – the stack traces I see in eclipse are not useful in most cases.

    By steveo on Mar 15, 2009

  12. I am new to both The Grinder and GrinderStone. I used the update manager to install GrinderStoner after manually downloading and installing Jython and The Grinder.

    I am running the following configuration:

    Jython 2.2.1
    The Grinder 3.2
    Pydev 1.4.6.2788
    GrinderStoner 2.0.0
    JDK1.5.0_16

    After having followed the instructions above I right click on my GoogleHomePageTest.py file (which I created under the /src folder) and click ‘Grinder Run’. Nothing happens, i.e. nothing appears in the console.

    When I go into the run configuration context menu and attempt to create a new ‘Grinder Run’ I get the following error message:

    Plug-in com.googlecode.grinderstone was unable to load class com.googlecode.grinderstone.debug.ui.GrinderTabGroup

    Can someone please help me?

    Thanks.

    Mark.

    By Mark on Jun 18, 2009

  13. Steveo did you managed to use a datafile to feed a test script? If yes, could you point me some details?

    By Fiat filip on Jun 22, 2009

  14. Hi Steveo,

    If you are still interested in The Grinder and GrinderStone, we’ve recently released new version 2.0.1.

    What new:
    support for Eclipse 3.4 and 3.5
    support for The Grinder 3.1 and 3.2
    support for latest versions of PyDev Eclipse plugin

    New Features:
    Ability to add and pass to script arguments via JVM parameters
    Select grinder.property file dialog: should allow to select any file rather than “grinder.properties” only

    What was fixed:
    Eclipse 3.4.1 support
    Eclipse 3.3 compatibility is broken
    Unable to create new Grinder Run Configuration (PyDev 1.4/Grinderstone 2.0.0)
    Grinderstone does not launch script (NoSuchMethodError – IpythonPathNature.getProjectSourcePath()Ljava/lang/String)
    An internal error occurred during “Launching”

    Download information:
    GrinderStone home site: http://code.google.com/p/grinderstone/

    Andrey.

    By Andrey Isaev on Sep 1, 2009

Post a Comment