Using JMeter for HTTP interface performance testing

Source: Internet
Author: User

in the Web page or the application background interface development, it is generally necessary to test the development of the interface to correctly receive and return data, for a single test, The Postman plugin is a good Http request emulation tool.  

but postman can only simulate single-client requests, and for performance testing such as simulating multiuser concurrency, other tools are required, and a powerful JMeter automation test tool is recommended.

Apache JM e ter -Apache JM Eter ?

Apache JMeteris aApachethe organization developed based onJavapressure test Tool. Used to stress the software.Test, which was originally designed toWebApplication Testingbut later extended to other test areas.  It can be used to test static and dynamic resources such as static files,JavaSmall Service Program,CGIscripts,Javaobjects, databases,FTPServer, and so on. JMeter can be used to simulate huge loads on servers, networks, or objects, test their strength and analyze overall performance from different pressure categories.

The following is an example of a restful type of interface, which provides a simple way to use JMeter for interface testing.

Gets the basic information for a specific gateway device.

Request

Method: GET

URI : /api/gateway/<gateway_id>

Parameters:

Add the UserID and Token fields as user authentication fields in the header of the HTTP request (the header)

Name of parameter

Necessary

Type

Description

gateway_id

True

Int

Gateway ID, placed within URL

Response

return Value: JSON Gateway information in the format

Parameters:

Name of parameter

Type

Description

Id

Int

Gateway ID

Name

String

Name of the Gateway

Mac

String

The MAC address of the Gateway

Fw_ver

String

Firmware version number of the gateway

Sub_dev

unsigned int

Number of sub-devices

Did

String

Did of the Gateway

Pscode

String

Gateway Pscode


1. Start JMeter: Run Jmeter.bat under bin as Administrator, start JMeter

2. Create a test plan:

The default startup JMeter will load a test technology template , Save the test plan: Modify the name of Apitest, click Save, select Save Path, the following steps, each time you add or modify some options, the software is not automatically saved to the Jmx file, so after testing, If you need to save this test option, manually save it to the File menu.

3. Add a thread group

Right-click on the test plan "apitest" node in the left tree, "add " →"Threads" → "Thread Group"

After adding the success, the "Apitest" node has more "thread Group" node, of course, the name of this thread group can be set by itself.

4. Add HTTP Default request : (Used to configure public parameters, not HTTP requests)

Right-click the thread group, select "Add" → "Configure components" → "http request defaults", after clicking on "HTTP request default Value"

After the add succeeds, the thread group node is more than the HTTP request Defaults node

you can set the host address here, wait a minute. Public parameters , for example, in our example, the request path is preceded by the host address +index.php, can be unified in the "HTTP request default value" set

Fill in the default request name, server, default request path, and save the test plan.

5. Add the HTTP request Information header

This is not required, except in our example, where UserID and token are used as user authentication in the HTTP request header

Right-click "Apitest" and select "Add" → "Configure symbol" → "HTTP header manager"

6. Add an HTTP request

Right click "Apitest", select "Add" → "Sampler" → "http request"

After the successful addition, a new node "HTTP request" will be available to fill in the specific request parameters.

Complete, save the test plan

7. Add a listener :

Right-click Thread Group, select "Add" → "listener" → "xxxxxxxxx"

There are a number of listeners you can add, you can add multiple listeners, and here we add a few common "graphical results," "View result trees," "aggregated reports."


After the add succeeds, several nodes are added under "Thread Group"

8. Trial run

Click Execute

You can view the results of each "listener"

Label: Each JMeter Element (for example , HTTP Request) has a Name Property , the value of the Name property is shown here

#Samples: Indicates how many requests you have made in this test, and if you simulate 10 users, each user iterates 10 times, then this shows a 100

Average: Average response time--the average response time of a single Request, by default, when using the Transaction Controller , the average response time can also be displayed in transaction units

Median: Median, which is the response time of the 50% user

90%Line: 90% User's response time

Note: For the meaning of 50% and 90% concurrent users, please refer to the following

Http://www.cnblogs.com/jackei/archive/2006/11/11/557972.html

min: Minimum response time

Max: Maximum response time

error%: Number of requests with errors in this test/total number of requests

Throughput: Throughput--By default, indicates the number of requests completed per second (request per Second), when Transaction Controller is used, can also represent a loadrunner - like Transaction per Second number

kb/sec: The amount of data received from the server side per second, equivalent to throughput/sec in LoadRunner

9. Modify the thread number of thread group and other parameters for stress testing

Click "Thread Group" in the tree navigation on the left


Set the above parameters, the total number of requests to simulate is: number of threads * cycle times. Take a look at the graphical results listener


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: 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.


Using JMeter for HTTP interface performance testing

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.