mirror of https://github.com/apache/jmeter.git
648 lines
21 KiB
HTML
648 lines
21 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!--
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
this work for additional information regarding copyright ownership.
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
(the "License"); you may not use this file except in compliance with
|
|
the License. You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
-->
|
|
|
|
<!-- Content Stylesheet for Site -->
|
|
|
|
|
|
<!-- start the processing -->
|
|
<!-- ====================================================================== -->
|
|
<!-- Main Page Section -->
|
|
<!-- ====================================================================== -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
|
|
|
|
|
|
|
|
<title>JMeter - User's Manual: Best Practices</title>
|
|
</head>
|
|
|
|
<body bgcolor="#ffffff" text="#000000" link="#525D76">
|
|
<table border="0" cellspacing="0">
|
|
<!-- TOP IMAGE -->
|
|
<tr>
|
|
<td>
|
|
<!-- Need to specify height otherwise iframe seems to grab extra -->
|
|
<iframe src="http://www.apache.org/ads/halfbanner.html" height="102"
|
|
style="border-width:0; float: left" frameborder="0" scrolling="no"></iframe>
|
|
</td>
|
|
<td align="left">
|
|
<a href="http://jakarta.apache.org"><img width="505" height="48" src="../images/jakarta-logo.gif" alt="Jakarta" title="Jakarta" border="0"/></a>
|
|
</td>
|
|
<td align="right">
|
|
<a href="http://jakarta.apache.org/jmeter/"><img width="221" height="102" src="../images/logo.jpg" alt="JMeter" title="JMeter" border="0"/></a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<table border="0" width="100%" cellspacing="4">
|
|
<tr><td colspan="2">
|
|
<hr noshade size="1"/>
|
|
</td></tr>
|
|
|
|
<tr>
|
|
<!-- LEFT SIDE NAVIGATION -->
|
|
<td width="20%" valign="top" nowrap="true">
|
|
<p><strong>About</strong></p>
|
|
<ul>
|
|
<li> <a href="../index.html">Overview</a>
|
|
</li>
|
|
<li> <a href="../changes.html">Changes</a>
|
|
</li>
|
|
<li> <a href="../known_bugs.html">Known Bugs</a>
|
|
</li>
|
|
<li> <a href="../license.html">License</a>
|
|
</li>
|
|
<li> <a href="http://wiki.apache.org/jakarta-jmeter/JMeterCommitters">Contributors</a>
|
|
</li>
|
|
</ul>
|
|
<p><strong>Download</strong></p>
|
|
<ul>
|
|
<li> <a href="http://jakarta.apache.org/site/downloads/downloads_jmeter.cgi">Download Releases</a>
|
|
</li>
|
|
<li> <a href="../nightly.html">Developer (Nightly) Builds</a>
|
|
</li>
|
|
</ul>
|
|
<p><strong>Documentation</strong></p>
|
|
<ul>
|
|
<li> <a href="../usermanual/index.html">User Manual</a>
|
|
</li>
|
|
<li> <a href="../api/index.html">Javadocs</a>
|
|
</li>
|
|
<li> <a href="../localising/index.html">Localisation (Translator's Guide)</a>
|
|
</li>
|
|
<li> <a href="../building.html">Building JMeter and Add-Ons</a>
|
|
</li>
|
|
<li> <a href="http://wiki.apache.org/jakarta-jmeter">JMeter Wiki</a>
|
|
</li>
|
|
<li> <a href="http://wiki.apache.org/jakarta-jmeter/JMeterFAQ">FAQ (Wiki)</a>
|
|
</li>
|
|
</ul>
|
|
<p><strong>Tutorials (PDF format)</strong></p>
|
|
<ul>
|
|
<li> <a href="../usermanual/jmeter_distributed_testing_step_by_step.pdf">Distributed Testing</a>
|
|
</li>
|
|
<li> <a href="../usermanual/jmeter_proxy_step_by_step.pdf">Recording Tests</a>
|
|
</li>
|
|
<li> <a href="../usermanual/junitsampler_tutorial.pdf">JUnit Sampler</a>
|
|
</li>
|
|
<li> <a href="../usermanual/jmeter_accesslog_sampler_step_by_step.pdf">Access Log Sampler</a>
|
|
</li>
|
|
<li> <a href="../extending/jmeter_tutorial.pdf">Extending JMeter</a>
|
|
</li>
|
|
</ul>
|
|
<p><strong>Community</strong></p>
|
|
<ul>
|
|
<li> <a href="http://jakarta.apache.org/site/getinvolved.html">Get Involved</a>
|
|
</li>
|
|
<li> <a href="http://jakarta.apache.org/site/mail.html">Mailing Lists</a>
|
|
</li>
|
|
<li> <a href="http://jakarta.apache.org/site/cvsindex.html">SVN Repositories</a>
|
|
</li>
|
|
</ul>
|
|
</td>
|
|
<td width="80%" align="left" valign="top">
|
|
<table>
|
|
<tr>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="index.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Index</font></a></div>
|
|
</td>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="boss.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Next</font></a></div>
|
|
</td>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="remote-test.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Prev</font></a></div>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="best_practices"><strong>16. Best Practices</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="limit_threads"><strong>16.1 Limit the Number of Threads</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
Your hardware's capabilities will limit the number of threads you can effectively
|
|
run with JMeter. It will also depend on how fast your server is (a faster server
|
|
gives makes JMeter work harder since it returns request quicker). The more
|
|
JMeter works, the less accurate its timing information will be. The more work
|
|
JMeter does, the more each thread has to wait to get access to the CPU, the more
|
|
inflated the timing information gets. If you need large-scale load testing, consider
|
|
running multiple non-GUI JMeter instances on multiple machines.
|
|
</p>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="put_cookie_manager"><strong>16.2 Where to Put the Cookie Manager</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
See
|
|
<a href="build-web-test-plan.html#adding_cookie_support">
|
|
Building a Web Test
|
|
</a>
|
|
|
|
for information.
|
|
</p>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="put_auth_manager"><strong>16.3 Where to Put the Authorization Manager</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
See
|
|
<a href="build-adv-web-test-plan.html#header_manager">
|
|
Building an Advanced
|
|
Web Test
|
|
</a>
|
|
for information.
|
|
</p>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="proxy_server"><strong>16.4 Using the Proxy Server</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
Refer to
|
|
<a href="../usermanual/component_reference.html#HTTP_Proxy_Server">HTTP Proxy Server</a>
|
|
for details on setting up the proxy
|
|
server. The most important thing to do is filter out all requests you aren't
|
|
interested in. For instance, there's no point in recording image requests (JMeter can
|
|
be instructed to download all images on a page - see
|
|
<a href="../usermanual/component_reference.html#HTTP_Request">HTTP Request</a>
|
|
).
|
|
These will just clutter your test plan. Most likely, there is an extension all your files
|
|
share, such as .jsp, .asp, .php, .html or the like. These you should "include" by
|
|
entering ".*\.jsp" as an "Include Pattern".
|
|
</p>
|
|
<p >
|
|
Alternatively, you can exclude images by entering ".*\.gif" as an "Exclude Pattern".
|
|
Depending on your application, this may or may not be a better way to go. You may
|
|
also have to exclude stylesheets, javascript files, and other included files. Test
|
|
out your settings to verify you are recording what you want, and then erase and start
|
|
fresh.
|
|
</p>
|
|
<p >
|
|
The Proxy Server expects to find a ThreadGroup element with a Recording Controller
|
|
under it where it will record HTTP Requests to. This conveniently packages all your samples under one
|
|
controller, which can be given a name that describes the test case.
|
|
</p>
|
|
<p >
|
|
Now, go through the steps of a Test Case. If you have no pre-defined test cases, use
|
|
JMeter to record your actions to define your test cases. Once you have finished a
|
|
definite series of steps, save the entire test case in an appropriately named file. Then, wipe
|
|
clean and start a new test case. By doing this, you can quickly record a large number of
|
|
test case "rough drafts".
|
|
</p>
|
|
<p >
|
|
One of the most useful features of the Proxy Server is that you can abstract out
|
|
certain common elements from the recorded samples. By defining some
|
|
|
|
<a href="functions.html">
|
|
user-defined variables
|
|
</a>
|
|
at the Test Plan level or in
|
|
|
|
<a href="../usermanual/component_reference.html#User_Defined_Variables">User Defined Variables</a>
|
|
elements, you can have JMeter automatically
|
|
replace values in you recorded samples. For instance, if you are testing an app on
|
|
server "xxx.example.com", then you can define a variable called "server" with the value of
|
|
"xxx.example.com", and anyplace that value is found in your recorded samples will be replaced
|
|
with "${server}".
|
|
|
|
|
|
<p><table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
|
|
<tr><td> Please note that matching is case-sensitive.
|
|
</td></tr>
|
|
</table></p>
|
|
|
|
|
|
|
|
</p>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="user_variables"><strong>16.5 User variables</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
|
|
Some test plans need to use different values for different users/threads.
|
|
For example, you might want to test a sequence that requires a unique login for each user.
|
|
This is easy to achieve with the facilities provided by JMeter.
|
|
|
|
</p>
|
|
<p >
|
|
For example:
|
|
</p>
|
|
<ul >
|
|
|
|
|
|
<li >
|
|
Create a text file containing the user names and passwords, separated by commas.
|
|
Put this in the same directory as your test plan.
|
|
|
|
</li>
|
|
|
|
|
|
<li >
|
|
|
|
Add a CSV DataSet configuration element to the test plan.
|
|
Name the variables USER and PASS.
|
|
|
|
</li>
|
|
|
|
|
|
<li >
|
|
|
|
Replace the login name with ${USER} and the password with ${PASS} on the appropriate
|
|
samplers
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
<p >
|
|
The CSV Data Set element will read a new line for each thread.
|
|
|
|
</p>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="lean_mean"><strong>16.6 Reducing resource requirements</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
|
|
Some suggestions on reducing resource usage.
|
|
|
|
</p>
|
|
<ul >
|
|
|
|
|
|
<li >
|
|
Use non-GUI mode: jmeter -n -t test.jmx -l test.jtl
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Rather than using lots of similar samplers,
|
|
use the same sampler in a loop, and use variables (CSV Data Set) to vary the sample.
|
|
Or perhaps use the Access Log Sampler.
|
|
[The Include Controller does not help here, as it adds all the test elements in the file to the test plan.]
|
|
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Don't use functional mode
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Use CSV output rather than XML
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Only save the data that you need
|
|
</li>
|
|
|
|
|
|
<li >
|
|
Use as few Assertions as possible
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="beanshell_server"><strong>16.7 BeanShell server</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
|
|
The BeanShell interpreter has a very useful feature - it can act as a server,
|
|
which is accessible by telnet or http.
|
|
|
|
</p>
|
|
<p><table border="1" bgcolor="#bbbb00" width="50%" cellspacing="0" cellpadding="2">
|
|
<tr><td>
|
|
There is no security. Anyone who can connect to the port can issue any BeanShell commands.
|
|
These can provide unrestricted access to the JMeter application and the host.
|
|
|
|
<b >
|
|
Do not enable the server unless the ports are protected against access, e.g. by a firewall.
|
|
</b>
|
|
|
|
|
|
</td></tr>
|
|
</table></p>
|
|
<p >
|
|
|
|
If you do wish to use the server, define the following in jmeter.properties:
|
|
|
|
</p>
|
|
<pre >
|
|
|
|
beanshell.server.port=9000
|
|
beanshell.server.file=../extras/startup.bsh
|
|
|
|
</pre>
|
|
<p >
|
|
|
|
In the above example, the server will be started, and will listen on ports 9000 and 9001.
|
|
Port 9000 will be used for http access. Port 9001 will be used for telnet access.
|
|
The startup.bsh file will be processed by the server, and can be used to define various functions and set up variables.
|
|
The startup file defines methods for setting and printing JMeter and system properties.
|
|
This is what you should see in the JMeter console:
|
|
|
|
</p>
|
|
<pre >
|
|
|
|
Startup script running
|
|
Startup script completed
|
|
Httpd started on port: 9000
|
|
Sessiond started on port: 9001
|
|
|
|
</pre>
|
|
<p >
|
|
|
|
As a practical example, assume you have a long-running JMeter test running in non-GUI mode,
|
|
and you want to vary the throughput at various times during the test.
|
|
The test-plan includes a Constant Throughput Timer which is defined in terms of a property,
|
|
e.g. ${__P(throughput)}.
|
|
The following BeanShell commands could be used to change the test:
|
|
|
|
</p>
|
|
<pre >
|
|
|
|
printprop("throughput");
|
|
curr=Integer.decode(args[0]); // Start value
|
|
inc=Integer.decode(args[1]); // Increment
|
|
end=Integer.decode(args[2]); // Final value
|
|
secs=Integer.decode(args[3]); // Wait between changes
|
|
while(curr <= end){
|
|
setprop("throughput",curr.toString()); // Needs to be a string here
|
|
Thread.sleep(secs*1000);
|
|
curr += inc;
|
|
}
|
|
printprop("throughput");
|
|
|
|
</pre>
|
|
<p >
|
|
The script can be stored in a file (throughput.bsh, say), and sent to the server using bshclient.jar.
|
|
For example:
|
|
|
|
</p>
|
|
<pre >
|
|
|
|
java -jar ../lib/bshclient.jar localhost 9000 throughput.bsh 70 5 100 60
|
|
|
|
</pre>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#525D76">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="bsh_scripting"><strong>16.8 BeanShell scripting</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#828DA6">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="bsh_overview"><strong>16.8.1 Overview</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
|
|
Each BeanShell test element has its own copy of the interpreter (for each thread).
|
|
If the test element is repeatedly called, e.g. within a loop, then the interpreter is retained
|
|
between invocations unless the "Reset bsh.Interpreter before each call" option is selected.
|
|
|
|
</p>
|
|
<p >
|
|
|
|
Some long-running tests may cause the interpreter to use lots of memory; if this is the case try using the reset option.
|
|
|
|
</p>
|
|
</blockquote>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table border="0" cellspacing="0" cellpadding="2" width="100%">
|
|
<tr><td bgcolor="#828DA6">
|
|
<font color="#ffffff" face="arial,helvetica,sanserif">
|
|
<a name="bsh_variables"><strong>16.8.2 Sharing Variables</strong></a>
|
|
</font>
|
|
</td></tr>
|
|
<tr><td>
|
|
<blockquote>
|
|
<p >
|
|
|
|
Variables can be defined in startup (initialisation) scripts.
|
|
These will be retained across invocations of the test element, unless the reset option is used.\
|
|
|
|
</p>
|
|
<p >
|
|
|
|
Scripts can also access JMeter variables using the get() and put() methods of the "vars" variable,
|
|
for example:
|
|
<code >
|
|
vars.get("HOST"); vars.put("MSG","Successful");
|
|
</code>
|
|
.
|
|
The get() and put() methods only support variables with String values,
|
|
but there are also getObject() and putObject() methods which can be used for arbitrary objects.
|
|
JMeter variables are local to a thread, but can be used by all test elements (not just Beanshell).
|
|
|
|
</p>
|
|
<p >
|
|
|
|
If you need to share variables between threads, then JMeter properties can be used:
|
|
|
|
<pre >
|
|
|
|
import org.apache.jmeter.util.JMeterUtils;
|
|
String value=JMeterUtils.getPropDefault("name","");
|
|
JMeterUtils.setProperty("name", "value");
|
|
|
|
</pre>
|
|
|
|
The sample .bshrc files contain sample definitions of getprop() and setprop() methods.
|
|
|
|
</p>
|
|
<p >
|
|
|
|
Another possible method of sharing variables is to use the "bsh.shared" shared namespace.
|
|
For example:
|
|
|
|
<pre >
|
|
|
|
if (bsh.shared.myObj == void){
|
|
// not yet defined, so create it:
|
|
myObj=new AnyObject();
|
|
}
|
|
bsh.shared.myObj.process();
|
|
|
|
</pre>
|
|
|
|
Rather than creating the object in the test element, it can be created in the startup file
|
|
defined by the JMeter property "beanshell.init.file". This is only processed once.
|
|
|
|
</p>
|
|
</blockquote>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
</blockquote>
|
|
</p>
|
|
</td></tr>
|
|
<tr><td><br></td></tr>
|
|
</table>
|
|
<table>
|
|
<tr>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="index.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Index</font></a></div>
|
|
</td>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="boss.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Next</font></a></div>
|
|
</td>
|
|
<td bgcolor="#525D76">
|
|
<div align="right"><a href="remote-test.html"><font size=-1 color="#ffffff" face="arial,helvetica,sanserif">Prev</font></a></div>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<br>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr><td colspan="2">
|
|
<hr noshade size="1"/>
|
|
</td></tr>
|
|
<tr><td colspan="2">
|
|
<div align="center"><font color="#525D76" size="-1"><em>
|
|
Copyright © 1999-2008, Apache Software Foundation
|
|
</em></font></div>
|
|
</td></tr>
|
|
</table>
|
|
</body>
|
|
</html>
|
|
<!-- end the processing -->
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|