You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

The JMeter FAQ TableOfContents

How to do remote testing the 'proper way'?

Answer: Here are a few notes to help you on your way.

You have:

  1. Your application server. You shouldn't run anything on this machine that you wouldn't have running on it in your proposed or actual production environment (if you are running anything else, including JMeter, you will be adding load to the server and thus tainting your results).
  2. One or more machines running jmeter-server (the ["JMeterEngine"]). You want these machines to be reasonably close (network wise) to the application server. By "reasonably close" I mean on the same Ethernet segment or at least with no low speed links between them. The JMeter User Manual provides reasonable information about doing this.

  3. A single machine running the JMeter GUI that you use to control the machines running the ["JMeterEngine"].

While you are developing your scripts and for only moderate levels of user testing (assuming you are "close" to the application server) you do not need to involve any ["JMeterEngine"] machines.
The reason you have these are to:

  1. Eliminate the impact of slow network connections when you are not "close" to the application server.
  2. Execute more test threads than your local machine is capable of handling.

How to run JMeter test plan programatically, such as from an Ant script?

Answer: Quick answer, go here: http://www.programmerplanet.org/ant-jmeter/. I have permission from the author of this ant task to add it to JMeter's distribution, which I will do as soon as I have the time. (It should now be in the extras folder).

How can I do stress testing of EJBs?

Answer: You can use the JavaSampler classes to write your own class that runs your EJB's, and then JMeter will take over the threading and reporting. This, however, is not ideal. Someone needs to write a good EJB Sampler implementation for JMeter (hint, hint).

Why do HTTP 3xx redirects appear as errors ? Is there a way to make them appear as HTTP 200 OK

Answer: Quick answer: They appear as an error because 302 != 200, at least in v 1.8.1.

Long answer: try using v1.9RC1, the code in [http://cvs.apache.org/viewcvs.cgi/jakarta-jmeter/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSampler.java?rev=1.40&content-type=text/vnd.viewcvs-markup HTTPSampler] seems to take into account the result code for the redirect instead of the redirect result code.

How do I parameterize my JMeter test cases?

Answer: Parameters can be set at both the Test Plan and Thread Group levels.

At the Test Plan level, parameters can be used as constants to minimize changes throughout the test plan when a server or port changes, for example. [N.B. functions are not currently supported at Test Plan level.]

Within Thread Groups, the User Parameters Pre-Processor can be used to set different parameters for each simulated user.

Note: if only one user (i.e. User_1) is defined, the value will be used for all threads. Functions ARE supported here. See later FAQs for more information.

The following example parameterizes the pet category from the [http://java.sun.com/blueprints/code/index.html#java_pet_store_demo/ Java Pet Store]. Thanks to [http://www.jwebhosting.net/ jWebHosting.net] for allowing us to run the example on their server.

  1. Start JMeter
  2. Click the Add button to add the following user defined variables to the Test Plan node:
    1. server: www.jboss.jwebhosting.net
    2. port: 80
    3. protocol: http
  3. Add a Thread Group to the Test Plan setting:
    1. Number of Threads: 2
    2. Clear the forever checkbox
    3. Loop Count: 1
  4. Add Config Element > HTTP Cookie Manager to Thread Group
  5. Add Pre Processors > User Parameters to Thread Group
  6. Click Add User to add an additional user to the User Parameters
  7. Click Add Variable and set name to category, User_1 to DOGS and User_2 to FISH
  8. Add Sampler > HTTP Request to Thread Group with the following settings:
    1. Server Name or IP: ${server}
    2. Port Number: ${port}
    3. Protocol: ${protocol}
    4. Path: /estore/control/category
  9. Click the Add button to add a parameter to the request:
    1. Name: category_id
    2. Value: ${category}
  10. Add Listener > View Results Tree to Thread Group
  11. Save
  12. Run > Start

When you view the results in the View Results Tree, you can see the ${category} value was replaced with the value from the User Parameters. Each thread will use the category from the User Parameter setting automatically. If there are more than two threads, they will reuse the values in these settings, so the third thread would use DOGS.

How do I make parameters dynamic, reacting to the unique server responses of each test run?

Answer: You can use the Regular Expression Post Processor to extract a value from a response, and then reuse this response in another request. Looking at the previous question in this FAQ, you could extract the product id from the result and use it in the following request:

  1. Load Test Plan created in previous FAQ question
  2. Add Post Processor > Regular Expression Extractor to thread Group with following values:
    1. Reference Name: product
    2. Regular Expression: product_id=(\w*\w*\w*)
    3. Template: $1$
    4. Match No.: 0 (Setting this parameter to 0 returns a random match)
  3. Copy the HTTP Request we created in the previous question and paste to the thread group after the previous HTTP Request
  4. Change the following values:
    1. Path: /estore/control/product
    2. Add Parameter and set name to product_id, value to ${product}
  5. Save Test Plan
  6. Run > Start

When you view the results in the View Results Tree, you can see the ${product} value was replaced with the value extracted by the regular expression.

How do I pass parameters into my Test scripts? I want to be able to use the same script to test with different numbers of threads and loops, and I don't want to have to change the script each time.

*Answer:*as explained above, you can use functions and variables just about anywhere in the test plan. So if you want to pass in a value a run-time, just use the __property() function, which reads the value of a JMeter property.

In order to define the property so JMeter can read it, define it on the command line as follows:

 jmeter -Jproperty_name=property_value 

For example:

 jmeter -Jhost2=www.zzzyy.com -Jhost1=www.jmeter-rules.net 

These values can then be read in the test plan using:

 ${__property(host1)} and 
 ${__property(host2)} 

Note: Thread Groups are slightly different from other test elements, because their settings have to be determined before the test starts. This means that you cannot use variables defined in a User Parameters form["as far as I could tell"]. But the __property() function works in Thread Groups.

Elsewhere, you can use function calls, or variable references to User Parameters (which in turn could be functions), or variable references to variables set up by functions earlier in the test. There's more than one way to do it.

Suppose you want to be able to vary the number of threads in a test plan. Choose a suitable property name, say group1.threads. Replace the thread count in the GUI (or the JMX, if you're feeling brave!) with the following function call:

 ${__property(group1.threads)} 

Then, when starting JMeter, define the property on the command line:

 jmeter -Jgroup1.threads=12345 

It can be useful to put default settings into the jmeter property file, so you only need to supply differences on the command line.

 # defaults in jmeter.properties 
 group1.threads=10 
 group1.loops=100 
 group1.rampup=10 

Then just do jmeter -Jgroup1.loops=1000 for example.

Versions of JMeter after 1.9.1 have a new version of the __property() function which allows a default value to be supplied, in case the property is not found:

 ${__property(group2.threads,,defaultvalue)} 

There is also a shorthand version called __P(), which you can use as follows:

 ${__P(group2.threads,100)} 

if you omit the value, it defaults to 1

How do I use external data files to in my Test scripts?

*Answer:*One way to do this is to create a User Parameters Pre-Processor in which you list all the values that you want to read from files. You can then use the variable names later in the script.

For example:

  1. Start JMeter
  2. Add a Thread Group to the Test Plan
    1. set the appropriate number of threads and iterations
  3. Add Pre Processors > User Parameters to Thread Group
  4. Click Add Variable
    1. Set Update once per iteration
    2. Set the Name to the name of the variable (e.g. ACCOUNTID)
    3. Set the value (under User_1) to ${_StringFromFile(accounts.dat)}
  5. Add Sampler > HTTP Request to Thread Group:
  6. Click the Add button to add a parameter to the request:
    1. Name: account_id
    2. Value: ${ACCOUNTID}
  7. Add Listener > View Results Tree to Thread Group
  8. Save
  9. create the file accounts.dat containing one line per account id. [In the bin directory, unless you add a path to the parameter to _StringFromFile]

  10. Run > Start

Each iteration, the ACCOUNTID variable will be set to the next line in the file, and the HTTP Request will use its value to set the account_id parameter.

When the end of the file is reached, StringFromFile starts reading again at the beginning.

N.B. If using such a script in client-server mode, make sure that any data files are copied to the appropriate place on the server host, as the files will be opened by the server process, not the client.

I'm having difficulty getting JMeter to work with SSL (HTTPS). What's the problem?

Answer: Check out the documentation [http://jakarta.apache.org/jmeter/usermanual/get-started.html item 2.2.4]. [A lot of people struggle with this, either because of private certs or whatever - I'm looking for a page that details common trip-ups and solutions for them. - MikeStover]

I'm having difficulty building Jmeter from NetBeans IDE. It is looking for a org.apache.log.Hierarchy, which log util is it looking for?

Answer: Make sure to mount all of the jars in the lib folder.

Has anyone out there used JMeter as part of junit testing? I'd like to think that by using assertions with a custom JUnit listener JMeter could be run in as part of functional testing.

Answer: It's a great idea to write some glue between JMeter and JUnit for just this purpose. It doesn't exist currently, though there is an Ant task for JMeter that you might find useful.

Can JMeter record HTTPS requests using the recording proxy?

*Answer:*No. JMeter would never be able to decipher the encrypted requests the browser sends. SSL Proxies create a tunnel from the browser to the destination server but do not and cannot read the messages. Check out [http://www.badboy.com.au/ BadBoy] for a possible solution.

How can I display the response text my assertation runs against?

*Answer:*You can display your server's response text in the View Results Tree listener.

Is there a JMX Schema/DTD available?

*Answer:*No. Don't plan on having one either at this point. Changes would be too frequent to realistically keep up with.

What happens with redirects when asserting HTTP responses?

*Answer:*Assertions aren't smart enough to do the right thing with redirected requests - currently the 302 response would be asserted against. You can get around this by recording your test plans and leaving "follow redirects" off.

Alternatively, the latest JMeter release (after 1.9.1) has an option to allow the redirects to be handled by the Java libary routines. Earlier versions of Java did not support redirects properly, but if you want to try, just define the following JMeter property:

 HTTPSampler.delegateRedirects=true 

JMeter will then not see the redirects at all.

I've set the CLASSPATH, but JMeter is not picking up my Jars

*Answer:*The CLASSPATH variable is ignored when using the -jar flag. For some further information on this, see:[http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html#userclass How the Java launcher finds user classes ]

JMeter currently knows to look for jars/classes in two places only:

  • lib/ext, where the ["ApacheJMeter"]_*.jar files live

  • lib, where the 3rd party jar files live

Additional jars should normally be placed in the lib directory; however, if you have written an add-on for JMeter itself, that should be put in the lib/ext directory.

If you want your jar file to be available to all Java applications, it can be placed in the [http://java.sun.com/j2se/1.4.2/docs/tooldocs/findingclasses.html#extclass JVM extensions directory]

Another possible solution is to take a copy of the jmeter startup script, and replace:

 -jar ["ApacheJMeter"].jar 

with

 org.apache.jmeter.NewDriver 

after adding ["ApacheJMeter"].jar to the classpath

What Pattern matching (regexen) does JMeter support?

*Answer:*JMeter includes the pattern matching software [http://jakarta.apache.org/oro/ Apache Jakarta ORO]. There is some documentation for this on the Jakarta web-site. There is also documentation on an older incarnation of the product at [http://www.savarese.org/oro/docs/OROMatcher/index.html OROMatcher User's guide], which might prove useful. The pattern matching is very similar to the pattern matching in Perl. A full installation of Perl will include plenty of documentation on regular expressions - look for perlrequick, perlretut, perlre, perlreref. O'Reilly sell a book called "Mastering Regular Expressions" by Jeffrey Friedl which will tell you all you need to know (and a lot more) about regular expressions. There are a couple of chapters available on their web-site covering REs in Java and .NET, and the Java chapter has a [http://www.oreilly.com/catalog/regex2/chapter/ch08.pdf section on ORO (PDF)] - worth a look.

It is worth stressing the difference between "contains" and "matches":

  • "contains" means that the regular expression matched at least some part of the target, so 'alphabet' "contains" 'ph.b.' because the regular expression matches the substring 'phabe'.
  • "matches" means that the regular expression matched the whole target. So 'alphabet' is "matched" by 'al.*t'. In this case, it is equivalent to wrapping the regular expression in ^ and $, viz '^al.*t$'. However, this is not always the case. For example, the regular expression 'alp|.lp.*' is "contained" in 'alphabet', but does not match 'alphabet'.

Why? Because when the pattern matcher finds the sequence 'alp' in 'alphabet', it stops trying any other combinations - and 'alp' is not the same as 'alphabet', as it does not include 'habet'.

Note: unlike Perl, there is no need to (i.e. do not) enclose the regular expression in //. So how does one use the Perl modifiers ismx etc if there is no trailing /? The solution is to use Perl5 extended regular expressions, i.e. /abc/i becomes (?i)abc

For a useful Regex tester, see http://weitz.de/regex-coach/

I want to use “Monitor Results” of JMeter

Currently I am using WAS 5.0 Application Server . For “Monitor Results” , JMeter shows the example for TOMCAT 5.0 WebServer.

“”””( Followings from JMeter doc )

Add the HTTP Request to the Thread Group element (Add --> Sampler --> HTTP Request). Then, select the HTTP Request element in the tree and edit the following properties):

Change the Name field to "Server Status". Enter the IP address or Hostname Enter the port number Set the Path field to "/manager/status" if you're using Tomcat. Add a request parameter named "XML" in uppercase. Give it a value of "true" in lowercase. Check "Use as Monitor" at the bottom of the sampler
“””””
Please let me know how I can set “Monitor Results” of JMeter in WAS5.0.

  • No labels