Example of JMeter stress test HTTP & TCP

Source: Internet
Author: User
Tags http request

Installation and startup

Download Address: http://jmeter.apache.org/download_jmeter.cgi
JMeter is developed based on Java and requires the JDK environment to be installed in the system. Decompress the package and enter the bin directory. Click jmeter. bat. If it runs normally, it will enter the JMeter control panel. The interface is as follows:

General test-HTTP

1. Add a Thread Group
Test Plan-> Add-> Threads (User)-> Thread Group, and then enter the following interface:

Number of threads:Indicates how many users will be simulated for testing.
Ramp-Up Period (in seconds ):Thread startup interval. All threads will start in sequence during this time.
Cycles:The execution of all threads is a loop.

The default value is 1 thread, which is executed once. You can modify it after the request is called.

2. Add a sampler
The probe can be understood as what needs to be done for the previously created thread. Here we use adding an HTTP request as an example.
Thread Group-> Add-> Sampler-> HTTP request, and then enter the following interface:

We can see from the interface that we can perform stress tests on GET and POST respectively. At the same time, you must set the request domain name, IP address, port, request path, and other parameters. You can also upload files and set proxies.

3. Add a monitor
The monitor can be understood as different viewing methods for the results. JMeter provides multiple result representations. You can choose HTTP request> Add> monitor> view result tree and aggregate report.

4. Run
Switch to the view results tree page and click the green execution button on the toolbar. If the request is correct, the green icon of the HTTP request is displayed.

Check whether the request and response are correct. After ensuring the correctness, you can clear all (toolbar broom button) and delete the page (it is slow to clear the page later), and then set the thread attributes in the thread Group. Re-execute the task and view the pressure test results on the aggregation report page, as shown in the following figure:

Aggregate report indicators:

Label:Each JMeter element (such as HTTP Request) has a Name attribute. The value of the Name attribute is displayed here.

# Samples:Indicates the total number of requests you sent in this Test. If you simulate 10 users and each user iterates 10 times, 100 is displayed here.

Average:Average response time-the average response time of a single Request by default, in milliseconds. When Transaction Controller is used, the average response time can also be displayed in units of Transaction.

Median:Median, that is, the response time of 50% users

90% Line:90% user response time

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, it indicates the number of requests completed per Second (Request per Second). When Transaction Controller is used, it can also represent the number of transactions per Second similar to LoadRunner.

KB/Sec:The amount of data received from the server per second, which is equivalent to the Throughput/Sec in LoadRunner.

TCP pressure test

Official TCP documentation: https://wiki.apache.org/jmeter/UserManual/Reference/TcpSampler
Same as the HTTP request process, establish a Thread Group, add a TCP sampler, and configure the TCP sampler according to the actual situation.

TCPClient classname has three settings:

TCPClientImpl: text data
BinaryTCPClientImpl: transmits binary data and specifies the package Terminator.
LengthPrefixedBinaryTCPClientImpl: the first two bytes in the data packet are the data length. You can set tcp. binarylength. prefix. length in the bin/jmeter. properties configuration file.

TCP Interactive data packets generally have two protocols. The Protocol header returns the data length or specifies the Terminator. The following uses the specified Terminator as an example to transmit data in binary format.
1. Set TCPClient classname: org. apache. jmeter. protocol. tcp. sampler. BinaryTCPClientImpl
2. Set the End of line (EOL) byte value.
3. Convert the data content into a hexadecimal format and write it in the text area to be sent.

Then you can test whether the request is normal. Most of the time, the protocols that come with the protocol may not meet the requirements, so you need to write scripts to implement them yourself.

The above is just a simple use of JMeter. JMeter is far more powerful than this. In Linux, JMeter can also be used to test databases, FTP, REDIS, and perform pre-and post-processing on request settings, you can expand it according to your own needs.

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.