1. Install the JDK and configure the environment variables
Take 1.8 as an example:
(1) installation of jdk1.8;
(2) In the system variable click New, variable name fill java_home, variable value fill JDK installation path "C:\Program files\java\jdk1.8.0_40", environment variable position 1
Figure 1
(3) In the system variable, click the new variable name to fill in the Classpath, the value of the variable filled ".; %java_home%\lib;%java_home%\lib\tools.jar ". Be careful not to forget the front dot and the middle semicolon.
(4) Find the path variable in the system variable, this is the system comes with, not new. Double-click Path, because the original variable value already exists, it should be appended to the existing variable after the ";%java_home%\bin;%java_home%\jre\bin". Note the preceding semicolon.
(5) Enter "Java-version" at the cmd command prompt of the system to see the appropriate help information indicating that the JDK installation was successful.
2. Install JMeter and configure environment variables
(1) Install JMeter, unzip "Apache-jmeter-2.11.rar" to the C Packing directory: "C:\apache-jmeter-2.11".
(2) In the user variable, the new variable name "Jmeter_home", the value of the variable is: "C:\apache-jmeter-2.11;".
(3) Modify "CLASSPATH", add: ";%jmeter_home%/lib/ext/apachejmeter_core.jar;%jmeter_home%/lib/logkit-2.0.jar;" If empty before "CLASSPATH", add ".; %jmeter_home%/lib/ext/apachejmeter_core.jar;%jmeter_home%/lib/logkit-2.0.jar; "
3. Running JMeter
Open C:\apache-jmeter-2.11/bin/jmeter.bat directly
4. Test steps
(1) Add thread Group, 2
Figure 2
After you add Page 3:
Figure 3
Figure of the data meaning: Run 10 threads every 1 seconds, loop 10 times, that is, every 1/10 seconds to send a request, a total request 100 times.
(2) Add an HTTP request
Figure 4
After the test content is filled in correctly:
(3) Add header information Manager, 6, Figure 7
Figure 6
Figure 7
(4) Adding listeners
Figure 8
5. Results analysis
(1) Aggregation report:
Note: The error here refers to the number of requests over 30 seconds.
Figure 9
Figure 10
Aggregation reports can be exported as Excel tables via the Save Table Data button:
Figure 11
(2) View result tree:
Note: During the run, the "View results tree" shows that the returned results of the check mark may also be incorrect, the statistical results should be noted, to ensure the correctness of the results of the operation, but also to focus on "request" data and "response data" whether the expected value.
(3) Use the table to view the results:
Figure 14
Parameter meaning:
Sample: Ordinal of each request
Start time: The start of each request
Thread Name: Name of each thread
Label:http Request Name
Sample time: Per request, in milliseconds
Status: The request state, if the tick indicates success, if the fork represents a failure.
Bytes: Number of bytes requested
Note:
The Open Test button is a green right-pointing arrow
Before each set of tests, you need to click the Clear button to clear the previous set of test data.
Figure 15
6. Random Parameters
To avoid the test errors caused by the use of fixed parameters, you need to randomly read the parameters used, the following steps:
Right-click Add-config component--cvs Data set config:
Figure 16
Then click on Add CVS data to do the following configuration:
Figure 17
filename for the location of the Params.csv file, Params.csv can build a text file, and then change the suffix name, the data is a line of a "empid,socialid,sn", the middle of a comma separated, the values do not need to quote, 18:
Figure 18
The parameter settings for the HTTP request are changed to the following settings:
Figure 19
When you clear the last test data, click on the "Start" button after the parameter is the random read value in the Params.csv file, you can see from the "View results tree" in the "request" to check whether each send data is random.
7. Recording Scripts
7.1 Recording script by JMeter itself
1. Create an HTTP proxy server (right-click on "Workbench"---> "add"---> "non-Test Components"---> "http proxy Server")
Figure 20
Make the following settings:
Figure 21
2. Setting Up IE browser
Internet Options---> Connections---> LAN settings
Figure 22
Figure 23
3, click on the "Start" button on the JMeter, open the browser input needs to record the Web project address, JMeter will automatically record a series of pages IE visits, click "Stop" end recording, the script automatically appears under the JMeter project.
Figure 24
7.2 through badboy recording script
1, install and open the Person Badboy tool, click on the Red Circle button on the work column, enter the address of the item being tested in the Address column.
Starting the access address, Badboy records the access process and forms the script.
2. After recording, click the Black button next to the toolbar to finish recording; Select "File"-"Export to Jmeter" to save the file.
3. Open the JMeter tool and select "File"--"open" to select the file (. JMX type) You just saved, and import the file in to execute it.
8. JMeter Writing custom Java test code for concurrency testing
To take a simple Java custom test code example, write the test code using the Java compiler, the function is: Enter any string before testing, determine whether the length of the string is greater than 5, if the test result is greater than the success, otherwise the test result fails, And then put it in the JMeter to simulate 10 user tests, and run this code at the same time, the implementation of the following:
1) Open the Java compiler, create a new project "Testlength", and then create a new package "Com.jmeter".
2) Copy two files "Apachejmeter_core.jar" and "Apachejmeter_java.jar" to "Testlength" from JMeter's installation directory Lib/ext, and then introduce the two jar files.
3) in the "Com.jmeter" package to create a new class, called "Testlength", but this class to inherit the "Abstractjavasamplerclient" class, if the project introduced in step two of the two files, you can find " Abstractjavasamplerclient "class.
4) The "Testlength" class inherits the "Abstractjavasamplerclient" class and inherits four methods, namely "Getdefaultparameters", "Setuptest", "Runtest" and " Teardowntest "method.
The U-Getdefaultparameters method is mainly used to set incoming parameters;
The U Setuptest method is the initialization method that is used to initialize each thread of the performance test.
The U-runtest method is the thread-running body of the performance test;
The U-teardowntest method is the test-ending method used to end each thread in a performance test.
5) The specific implementation code is as follows.
Package com.jmeter;
Import org.apache.jmeter.config.Arguments;
Import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
Import Org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
Import Org.apache.jmeter.samplers.SampleResult;
Import Org.apache.log.Logger;
/**
* Created with IntelliJ idea.
* USER:TANCP
* DATE:15-11-10
* Time: 11:12
* To change this template use File | Settings | File Templates.
*/
public class TestLength03 extends Abstractjavasamplerclient {
Log class output to the JMeter console
Private Logger Log=getlogger ();
Run results
Private Sampleresult results;
JMeter input parameters of the console
Private String teststr;
Set parameters that are passed in, can be set to multiple, and parameters that have been configured are displayed in the JMeter parameter list
Public Arguments getdefaultparameters () {
Log.info ("Execute getdefaultparameters!!!!!!");
Arguments params=new Arguments ();
Define a parameter that appears in the JMeter parameter list, the first parameter is the display name, the second parameter is the default value
Params.addargument ("Teststr", "" ");
return params;
}
Initialization method, executed once per thread, before the test method runs
public void Setuptest (Javasamplercontext arg0) {
Log.info ("Execute setuptest ...");
Results=new Sampleresult ();
Teststr=arg0.getparameter ("Teststr", "" "); Initialization
if (Teststr!=null&&teststr.length () >0) {
Results.setsamplerdata (TESTSTR);
}
}
Test Execution Loop Body
Public Sampleresult runtest (Javasamplercontext arg0) {
Log.info ("Execute runtest$$$$$$");
Used to set the success or failure of the run result, or false to indicate that the result failed, otherwise it would be successful
if (Teststr.length () <5) {
Log.info ("Fail ...");
Results.setsuccessful (FALSE);
}else{
Log.info ("[Email protected]@@@@@");
Results.setsuccessful (TRUE);
}
return results;
}
The end method, which is executed only once per thread at the actual run time and executed after the test method has finished running
public void Teardowntest (Javasamplercontext arg0) {
Log.info ("Execute teardowntest######");
}
}
6) Package The above example and copy the generated "Testlength.jar" file to the JMeter installation directory Lib/ext.
7) Open Bin\jmeter.bat run JMeter and go to Apache JMeter console.
Adds a group of threads.
Then add a Java request under the thread group (in sampler)
Figure 25
In the class name of the Java request, select the class "Com.jmeter.TestLength" that we just created, enter the string to test after "Teststr" in the parameter list below, and then add a listener (aggregated report).
Figure 25
Set the number of simulated users to test. If the test is unsuccessful, JMeter throws the string in its own output box.
8) View logs (logs containing jmeter self-logs and custom Java programs), log location
Figure 26
Log information
Figure 27
Note: This log file will be formatted every time JMeter is closed
Report
term meaning:
1. Thread Group: Each task in the test has to be processed by the thread, and all of our later tasks must be created underneath the thread group. You can build it with the Add->threads (Users), thread group, in the Test Plan (right-click), and then there are several input fields in the Thread Group panel: Number of threads, ramp-up Period (in seconds), number of loops, where Ramp-up Period (in seconds) indicates that all threads are created within this time. If there are 8 threads, ramp-up = 200 seconds, then the thread has a start interval of 200/8=25 seconds, and the benefit is that the server will not have too much load at first.
2, Sampler (Sampler): You can think that all test tasks are taken by the sampler, there are many kinds, such as: HTTP request.
3. Assertion: The result of the request returned by the sampler is correct.
4, Monitor: Its function is to the sampler request results display, statistics some data (throughput, kb/s ... ) and other
Number of samples: The total number of requests sent to the server.
Latest Sample: The number representing the time, which is the time the server responds to the last request.
Throughput (throughput): The number of requests that the server processes per minute.
Average: Total elapsed time divided by the number of requests sent to the server.
Median: The number of times that half of the server response time is below this value and the other half is above that value.
Deviation: The server response time change, the size of the discrete measure value, or, in other words, the distribution of the data.
Number of samples: that is, the number of requests mentioned above, the success of the case equals the number of concurrent numbers you set multiplied by the number of cycles.
Average: Average time requested by each thread
Latest Sample: Indicates when the server responded to the last request
Deviation: The response time of the server changes, the size of the discrete measure, in other words, the distribution of data.
JMeter Working with Documents (Windows)