More On Deploying With JMeter - Shell Scripting Deployment

The other day I expanded on someone else's blog about load testing Drupal with JMeter, by writing about how one can submit forms, and as such potentially handle deployments, with Drupal.

This entry continues on that theme, but looks at scripting your JMeter plans from Linux shell, to make deployment of many JMeter scripts across many different potential environments much, much easier.

So, you've written about seventeen different JMeter deployment scripts (test plans) for your release, tried them and they work ... on your laptop. But here's the rub: you don't really want to have to edit them all and put in your stage server domain name (if you're lucky enough to have a stage server) even if it's only a case of changing the HTTP Request Defaults - it's still a hassle! And you certainly don't want to have to do it all *again* for production after that. And you don't really want three copies of every test plan either.

Well the good news is you don't have to. With JMeter it's possible to execute your scripts, on Windows or Linux, from the command line and pass in variables, for example the server domain name. The command looks like this:

(Windows)
"c:\Program Files\jakarta-jmeter-2.3.2\bin\jmeter" -n
-Jserver.name=stage.mysite.com -t "c:\Documents and Settings\gharvey\Desktop\mytest.jmx"

(Linux)
/opt/jakarta-jmeter-2.3.2/bin/jmeter -n
-Jserver.name=stage.mysite.com -t /home/gharvey/mytest.jmx

Nearly the same, as you can see. The first bit is just executing JMeter. (If you add JMeter to path, in Linux or Windows, then you just need to type 'jmeter', but I'll leave you to Google that one.) The -n means in non-GUI mode. Then you've got the -J - notice there is no space after it. server.name is the name of the variable you will call inside your JMeter plan (we'll see that shortly) and obviously the =stage.mysite.com is the value of that variable to be passed in. Finally, -t points us to the test plan we want to execute.

Alright, so we're firing our test plan, 'mytest.jmx', from the command line, but right now its values are hardwired into it. I want to put 'stage.mysite.com' in to the HTTP Request Defaults, so how do I do that?

Simple - you just open your test plan, select the HTTP Request Defaults, delete the Server Name value (it's probably something like 'localhost' right now) and replace it with this:

${__P(server.name)}

Save and re-run the script, from the command line, placing what ever you want ${__P(server.name)} to be in the test plan after the 'equals' in -Jserver.name=, without spaces. Your JMeter plan will now execute on the server name (or IP address) you pass it from the command line.

We can take this further, for example, I have functional test scripts that login and logout as users of various roles. I can pass the user credentials in too, something like this (Linux only example, but you can translate it to Windows):

/opt/jakarta-jmeter-2.3.2/bin/jmeter -n -Jserver.name=stage.mysite.com -Jdrupal.password=password -Jdrupal.username=greg -t /home/gharvey/mytest.jmx

And in my test plan, I just change the values of the login form for username and password to:

${__P(drupal.username)}
${__P(drupal.password)

You can do this anywhere in any test plan.

Finally, here's an example shell script we use here, which executes all the JMX plans in a given directory, passing variables to JMeter that are set in the shell script. This will only work on Linux, but if you're on Windows you can do a similar thing with a batch script.

#!/bin/bash

# set variables
INPUTDIR="/path/to/jmeter/tests"
JMETERLOCATION="/path/to/jmeter/bin"
SERVERNAME="stage.mysite.com"

cd $INPUTDIR
 
# locate each JMX files in input dir
for file in *.jmx
do
  # run jmeter script
  $JMETERLOCATION/jmeter -n -Jserver.name=$SERVERNAME -t $INPUTDIR/$file

done

exit 0

Copy that script in to a file called something like 'run_jmeter_scripts.sh', make it executable, change INPUTDIR to the location of your test plans ,JMETERLOCATION to the 'bin' directory of JMeter and set SERVERNAME to the URL of the site you want to execute against. Now all you have to do is execute your shell script to run all your tests/deployment plans. Switching server is now just a case of changing one variable in a shell script. =)

Drupal Login Failes in JMeter Script

I have recorded the script and modified to extract the form_build_id. Even then the Login fails. Could not figure out how to make login work.
Can you provide a sample script with login step would be of great help.

Thanking in advance.

Care to share your jmx?

Hey Greg,

We're starting to do some heavy D7 profiling, and would really love to take a look at your jmx to get started.

Can you share this?

Thanks,
Jacob

Ach, I don't have them

I just checked the project I was working on when I wrote that blog, and I only have the application, not the jmx files. It was a contract, so it's not in my repository. If you ping me an email via the contact form, I can give you the email of a guy who *does* have them. =)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.