Correlation using The Grinder

Lately I have been using The Grinder to simulate some http user traffic. Its a great little free tool.  Here are a few tips to help you with correlating data from server responses.

Firstly, make sure that you can interrogate data for your server responses if they are compessed responses, you will need to decompress them. Keep in mind this will have an impact on your performance.

At the top of your script place these 2 lines

connectionDefaults.useTransferEncoding = 1
connectionDefaults.useContentEncoding = 1

Now to assist with your debugging create an instance of the log output to allow dumping of server responses to the normal output logs. This will assist with interrogating the server response for correlation purposes. Here is code snippet

log = grinder.logger.output

"""GET / (request 101)."""
result = request101.GET('/')
log(result.getText())

Finally to simplify your correlation you can use this little function which I enhanced from Ainars Galvans. By the way to find out what to correlate using the standard process of recording 2 scripts, following the exact same process and then executing a diff on the 2 outputs. This is a good starting point. Anyhow heres the little correlation function and an example of its use.

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('/')
   log(result.getText())
   self.jsessionid = findVar(result.getText(), 'jsessionid', '"')
   return result

def page2(self):
   """GET blank.gif (request 201)."""
   self.token_jsessionid = \
   self.jsessionid
   result = request201.GET('/wm_cafshared/ui/img/blank.gif;jsessionid=' +
   self.token_jsessionid)

def findVar(text, searchstring, endchar):
   #Calculating at which character the substring begins
   startCutPos = text.find(searchstring) + len(searchstring)

   #Now scanning characters one-by-one until encounter the End character.
   x = 0
      while (text[startCutPos + x] <> endchar):
      x=x+1
   endCutPos = startCutPos + x

   #Now it’s time to cut the substring
   subString = text[startCutPos:endCutPos]
   # this line for debug
   print 'jsessionid: ' + subString

   return subString

Correlate to your hearts content.

9 thoughts on “Correlation using The Grinder

  1. Hi Nick,

    Thanks a million for this post.

    I get following error while running the script.

    5/7/10 9:19:08 AM (thread 0 run 0 test 401): Aborted run due to Jython exception: AttributeError: find [calling TestRunner]
    AttributeError: find
    File “C:\Users\jadu_cr23\Documents\PT\grinder-3.4\.\localhost-file-store\current\grinder.py”, line 263, in findVar
    File “C:\Users\jadu_cr23\Documents\PT\grinder-3.4\.\localhost-file-store\current\grinder.py”, line 481, in __call__.

    Do I need to import any specific library for this ?

    Regards
    Jadumani

  2. Thanks Jadumani,

    Looks like there was a problem locating findvar function. No, you don’t have to import any libraries. You need to make sure that findvar function is defined OK and you haven’t accidentally violated the indents with the copy of code.

    If nothing obvious from then I would probably have to look at the code if you can send.

    cheers

    Nick

  3. Great article! The Grinder is the best tool for performance testing. I’ve working on GrinderStone – IDE for Grinder scripts which allows debug scripts using Eclipse and provides some interesting features for development like modularity and pretty useful logging in debug mode. This project you can download from official project site:

    http://code.google.com/p/grinderstone

    we also have Eclipse Update site for simple plugin installation into Eclipse platform. All details you can obtain on our site and support group. Look thru GrinderStone, it gives you more power to develope Grinder scripts.

  4. I have the same problem with error: “Aborted run due to Jython exception: NameError: findVar [calling TestRunner]”

    I edited within eclipse with GrindStone and I don’t get any syntax error, but I get this error when I run it.

    This is the code:


    def findVar(text, searchstring, endchar):
    startCutPos = text.find(searchstring) + len(searchstring)

    x = 0
    while (text[startCutPos + x] endchar):
    x=x+1

    endCutPos = startCutPos + x

    subString = text[startCutPos:endCutPos]

    print 'jsessionid: ' + subString

    return subString

    # A method for each recorded page.
    def page1(self):
    """GET userguide (requests 101-102)."""

    # Expecting 302 'Moved Temporarily'
    result = request101.GET('/zkdemo-all/userguide')

    # NEW -------------------------------------
    log(result.getText())
    self.jsessionid = findVar(result.getText(), 'jsessionid', '"')
    log('jsessionid 1' + self.jsessionid)

    return result

    def page2(self):
    """GET normie.css.dsp (requests 201-208)."""

    # NEW -------------------------------------
    self.token_jsessionid = self.jsessionid
    log('jsessionid 2' + self.token_jsessionid)

    result = request201.GET('/zkdemo-all/zkau/web/zul/css/normie.css.dsp;jsessionid=' +
    self.token_jsessionid)

    Thanks for any advice!

      • Hi,

        The indentation wasn’t the problem. I had to put the function “finVar()” out of the class. Only then it worked. I don’t know why. Thanks again!

Comments are closed.