From: http://www.cnblogs.com/fnng/archive/2012/12/22/2829479.html Author: Insect Master
In the previous section, we learned about the main components of jmeter, and how these components are used in performance testing. This section creates a simple test plan to use these components. The test requirements for the program.
1) test target site is fnng.cnblogs.com and tt-topia.rhcloud.com
2) The test is intended to be the response time of the site when the load reaches the QPS.
QPS explained
Qps:query per Second query rate. is the number of queries that a query server can process per second. On the Internet, the performance of a machine as a domain Name System server is often measured in terms of query rate per second.
In order to achieve the desired goal, a test plan needs to be established in the JMeter. Because this test only requires the completion of the fnng.cnblogs.com and tt-topia.rhcloud.com two blog home page requests, so only need to use the HTTP request Sampler.
set up a test plan
When JMeter is started, JMeter automatically generates an empty test plan that allows users to build their own test plans based on the test plan.
Add a thread group
A performance test request payload is done based on a thread group. A test plan must have a group of threads. A test plan to add a thread group is very simple. Select the thread group in the test plan right-click Pop-Up drop-down menu (add-->threads---> Thread Group).
Each test plan in JMeter needs to contain at least one thread group and, of course, multiple thread groups can be created in a single plan, and then the sequence (serial or parallel) between multiple thread groups will be executed. Under the test plan, multiple threads are executed in parallel, meaning that these thread groups are simultaneously initialized and execute the sampler under the thread group at the same time.
The thread group consists of three parameters: the number of threads, the length of preparation (ramp-up Period (in seconds)), and the number of cycles.
Number of Threads : Number of virtual users. A virtual user occupies a process or thread. Set how many virtual users here is the number of threads set.
Preparation Time : The number of virtual users that are set up takes a long time to start all. If the number of threads is 20 and the preparation time is 10, then 10 seconds will be required to start 20 threads. That is, starting 2 threads per second.
Number of cycles : The number of times each thread sends a request. If the number of threads is 20 and the number of cycles is 100, then each thread sends 100 requests. The total number of requests is 20*100=2000. If "Forever" is checked, then all threads will continue to send the request, one to choose to stop running the script.
Setting a reasonable number of threads can have a decisive impact on meeting the test target. In this example, the response time of the site's first page in the case of a QPS load is required, and if the number of threads is set too small, it is likely that the set QPS requirement will not be met. In addition, it is important to set a reasonable number of cycles, in addition to the number of fixed cycles described above, and the flexible choice of setting test run time. Tick "Scheduler" to configure the scheduler.
add an HTTP request
After adding the completion thread group, select the HTTP request on the right-click menu (Add--->sampler--->http request) on the threaded group. For JMeter, a sampler (Sampler) is a unit that interacts with the server. A sampler typically works in three parts:
Send a request to the server
Record the server's response data
Record corresponding time information
An HTTP request has many configuration parameters, which are described in more detail below:
name : This property is used to identify a sampler and it is recommended to use a meaningful name.
Note : For tests that do not have any effect, only users record user-readable comment information.
server name or IP : The destination server name or IP address sent by the HTTP request.
Port Number : The port number of the destination server, the default value is 80.
protocol : The protocol that sends an HTTP request to the destination server, either HTTP or HTTPS, with the default value HTTP.
methods: Methods for sending HTTP requests, including GET, POST, HEAD, PUT, OPTIONS, TRACE, delete, and so on.
Content Encoding : Encoding the contents, the default value is iso8859
path : Destination URL path (excluding server address and port)
Automatic redirection: If this option is selected, JMeter automatically redirects to the new page when the response is 302/301 when the HTTP request is sent.
Use keep Alive : When this option is selected, HTTP communication is used keep-alive between JMeter and the target server, which is selected by default.
Use Multipart/from-data for HTTP POST : When sending an HTTP POST request, it is sent by using the Multipart/from-data method, which is not selected by default.
send parameters with the request: the URL parameter is sent in the request, and for the URL with the parameter, JMeter provides a simple method for parameterization. The user can set all parameters in the URL in this table, and each row in the table is a parameter value pair (the name 1= value 1 in the corresponding Rul).
send a file with the request: Send the file in the request, usually, the HTTP file upload behavior can be simulated in this way.
get all the included resources from the HTML file : When this option is selected, jmeter the HTML file content of the HTTP request and gets the response, and also parse the HTML and get all the resources contained in the HTML (pictures, flash, etc.). By default, if the user only wants to get specific resources on the page, you can fill in the embedded URLs must match text box below with a specific resource expression that needs to be downloaded, so that only URLs that match the specified regular expression are directed to the resource to be downloaded.
as a monitor : This sampler is treated as a monitor, and the graphical statistics based on the sampler can be seen directly in monitor Results Listener. The default is unchecked.
Save response as MD5 hash? : Select to record only the MD5 value of the service-side response data at execution time, not the full response data. It is recommended that the item be checked to reduce the cost of the sampler recording the response data when a very large amount of data is required for testing.
Here we add two HTTP requests, respectively, to send requests to fnng.cnblogs.com and tt-topia.rhcloud.com.
set the QPS limit
The purpose of this performance test is to "understand the response time of a blog's home page when the load reaches QPS", so you need to control the load of 20QPS to send requests to the blog home page.
One way to do this is to gradually adjust the number of thread calculations in the test plan and add a timer to the sampler (Sampler) to keep the HTTP sampler's request for QPS at around 20. However, this method is time consuming and requires several attempts to achieve, and the other method is to control the QPS completely by setting a timer, and once the response time of the sampler changes (the network environment changes), the timer's wait time needs to be re-adjusted.
The jmeter provides a very useful timer, called the constant throughput timer (constant throughput timer), which can conveniently control the throughput of a given sampler sending a request.
Right click on fnng.cnblogs.com, pop-up menu (Add---> Timer--->constant throughput timer) Select Constant Throughput Timer
The main properties of the Constant throughput Timer are:
name : Name of the timer
Target throughput (in samples per minute): Destination throughput. Note that this is the number of requests sent per minute, so the value should be 1200 for the QPS required in the test requirements.
Calculate throughput based on: There are 5 options, namely:
This thread is only: controls the throughput of each thread, when this mode is selected, the total throughput is the set target throughput multiplied by the number of threads.
All active threads: The target throughput set is allocated on each active thread, and each active thread waits a reasonable time after the last run to run again. An active thread is a thread that runs concurrently at the same time.
All active threads in the current thread group: The set target throughput will be allocated on every active thread in the group of threads, and when there is only one thread group in the test plan, this option and all active The threads option works exactly the same.
All active threads (shared): The option for all active threads is basically the same, except that each active thread waits for a reasonable time after the last run of all active threads to run again.
All cative threads in the current thread group (shared): basically the same as all active threads in the current thread group, except that each active thread will be at all active After the last run of the thread, wait for a reasonable time to run again.
As shown above, the component is used only for fnng.cnblogs.com, set the timer's target throughput to 1200/min (QPS), set the value of calculate throughput based on to all active Threads.
Of course, the Constant throughput timer only makes sense if the threads in the thread group generate enough request, so even if the value of the Constant throughput timer is set, the number of threads in the thread group may be insufficient. or the timer set unreasonable and so on, cause the overall QPS can not achieve the desired goal.
Add Listener (Listener)
After the main part of the script is set up, the test results in the performance test need to be obtained in some way, in this case we are concerned with the response time of the request.
The listener component is used in Jmeter to collect data recorded by the sampler and render it visually. JMeter has a variety of different listener types, because on HTTP requests, we can add aggregated reports to view test results more intuitively.
Add an aggregated report, right-click on the thread group, and select Aggregate Report in the popup menu (Add---> Listener---> Aggregate report).
Run the script
After adding the completed aggregation report, let's run the script and later describe the parameters of the aggregated report.
Before shipping the script, let's take a look at the parameter settings for each component:
---------------------------------------------------------------
Thread Group:
Number of Threads: 20
Preparation time: 10
Number of cycles: 10
---------------------------------------------------------------
HTTP request:
Name: fnng.cnblogs.com.
Server name or IP:fnng.cnblogs.com
Port number: 80
Implementation:java
Protocol: HTTP
Method: GET
Path:/
---------------------------------------------------------------
Constant Throughput Timer:
Target throughput (in samples per minute): 1200.0
Calculate throughput based On:all active threads
---------------------------------------------------------------
Click the Run button on the toolbar, or click the menu bar "Run---> Start" or use the shortcut key ctrl+r to run the program.