JMeter Simple Performance Test Example

Source: Internet
Author: User
Tags http file upload md5 hash keep alive

JMeter Basics-A simple performance test

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 include at least one thread group, and of course you can create multiple thread groups in a single plan, so what is the sequential execution (serial or parallel) between multiple thread groups? 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 name or IP address of the destination server 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 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 The active 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 with current thread group (shared): basically the same as all active threads in the current thread group, the only difference being that each active Threads wait for a reasonable time after the last run of all active threads to run again.

For example, the component is only used 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.

Aggregated report analysis

--------------------------------------------------------------------------------

To view the results of the aggregation report:

Ok! At the end of this complete performance test, if you have something to gain, recommend a record ~!



Tip: If the above display blank or page layout confusion, content display is not complete and other issues affecting the reading, please click here to view the original

Back to Script Blackstone homepage If you like the IT industry or interested in IT industry, welcome to join the official QQ Group: 246889341, in the group to meet new friends and communication technology ^_^


JMeter Simple Performance Test Example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.