JMeter automated stress test-http

download:

Apache JMeter - Download Apache JMeterhttps://jmeter.apache.org/download_jmeter.cgi

Install:

JDK version requirement is 1.8.

1. Introduction to Jmeter


1.1. What functions does Jmeter have?
Apache JMeter is an open source, pure Java, and excellent performance testing tool

Ability to test many different application/server/protocol types:

HTTP、HTTPS

REST、SOAP

JDBC

FTP

LDAP

JMS message class

Mail class (SMTP, POP3, and IMAP)

command or shell script

TCP

Java request extension

Main features:

Visual design, complete functions (visualization)

Quickly design test plans, build and debug programs easily (simplicity)

Built-in eight major components, powerful, highly flexible design (high flexibility)

Full, fast portability and 100% Java purity (cross-platform)

The core function is highly scalable and can be quickly developed for secondary development (high expansion)

1.2. Comparison between Jmeter and LoadRunner

Summary:

In the current market, Jmeter is a necessary skill, and LoadRunner is an enhanced skill (personal skill)

Jmeter is a lightweight, cross-platform, and powerful performance testing tool, which is now more popular than LoadRunner

1.3. Commonly used performance testing tools
Currently there are dozens of performance testing tools on the market. The author has selected several more practical testing tools for your reference.

Performance testing tools Protocols Supporting protocols Supporting scenarios Main purpose Explanation
Jmeter open source multi-protocol is http testing, other testing JMeter is a completely open source performance testing tool provided by the Apache Open Source Foundation, designed to load test functional behavior and measure performance. It was originally designed for testing web applications, but has since expanded to other testing capabilities
LoadRunner Commercial Multi-Protocol is http testing, other testing LoadRunner is a load testing tool for predicting system behavior and performance. By simulating tens of millions of users to implement concurrent load and real-time performance monitoring to confirm and find problems, LoadRunner can test the entire enterprise architecture
Kylinpetl/kylinTOP domestic commercial multi-protocol is http test, other tests : kylinPET, performance emulation tool) is a powerful performance testing tool; friendly interface, easy operation, low resource usage; very similar to LoadRunner ApacheBench open
source http No Simplicity http ApacheBench is a lightweight tool. It is mainly used for performance testing of the HTTP protocol. Very simple and fast, does not support scenario testing
Webbench open source http No Simplicity http Webbench is a well-known website stress testing tool, very simple and fast, does not support scenario testing
Sysbench open source multi-protocol # Database benchmark sysbench is an open source multi-thread A performance testing tool that can perform performance tests on CPU/memory/thread/IO/database, etc.
Locust Open Source http is http testing Locust is an easy-to-use distributed user load testing tool. It is designed to load test a website and determine how many concurrent users the system can handle. Very easy to use. It is convenient to implement script expansion and business request realization based on Python


1.4. How to select performance testing tools

ab (ApacheBench), Webbench Usage scenario: simple interface test, no scenario, no parameterization processing, command line tool Jmter
Usage scenario: free + complex scenario
LoadRunner usage scenario: business + complex scenario
Kylinpet/kylinTOP usage scenario: with Similar to LoadRunner, some functions are more powerful
Locust usage scenarios: high familiarity with Python, no UI design interface, use of lightweight coroutines, high concurrency tools
are just a form, whether it is performance testing or functional automation testing, after learning , the essence is a kind of test programming, the tool only simplifies some functions, but it cannot completely replace; Jmeter, LoadRunner can master any one, even if you need to learn others in the future, it will become much easier

1.5. Learning Jmeter's requirements for Java programming


Script programming in Jmeter is essentially Java programming, which requires a certain grasp of Java

Write Jmeter scripts and be familiar with basic Java programming, such as variable definitions, data types, conditions, loops, Map and List structures...

Jmter's secondary development pays more attention to Java requirements, and requires familiarity with the use of Java and third-party protocols, such as Kafaka, Redis, etc.

2. Configuration and use

2.1, JDK environment configuration

Environment variable setting under Linux system

export JAVA_HOME=/home/xiangsl/softwares/jdk1.8.0_161
PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar


Environment variable settings under windows

JAVA_HOME=D:\Program Files\Java\jdk1.8.0_261;
PATH=%JAVA_HOME%\bin;.......
CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar;


2.2. Three modes of Jmeter
Jmeter mode Design test plan Performance pressure test Role description Explain
GUI mode √ √ Graphical terminal and stress machine are on this machine Design test plan, and can do lightweight performance testing at the same time
Client mode √ Command line mode Command line Mode to perform performance pressure test, fast and convenient to use, cross-platform
remote mode √ The graphics terminal is separated from the press machine, and the remote mode can be expanded horizontally, generally used with the graphical interface
2.4, main configuration introduction
2.4.1, setenv configuration
win .bat exists, and setenv.sh exists under linux. It does not exist by default. It needs to be manually created mainly to configure some system environment variables, such as JVM startup parameters, default language, etc.

For configuration details, see the official website (1.4 Running JMeter): https://jmeter.apache.org/uscrmanual/get-started.htmI#frunning


2.4.2. Almost all configurations of jmeter.properties can be modified through this file. The more commonly used ones are: 19.7 Remote hosts and RMl configuration

For configuration details, see the official website: https://jmeter.apache.org/usermanual/properties_reference.html

2.4.3, user.properties
user-defined parameters, generally used for test plans; here, we can define any parameters we need

2.4.4. Commonly used commands introduce
windows commands, which are generally used in graphical interfaces. The main commands are as follows:

The startup command is used
to start the interface in jmeter.bat graphical mode (with cmd command box), if there are console messages, it is recommended to use
jmeterw.cmd to start the interface in graphical mode (without cmd command box)
jmeter-server.bat in server mode Start
mirror-server.cmd Start a mirror server
linux command, generally used on the server side, the main commands are as follows:

The startup command is used
to start the interface of jmeter in graphical mode (with a terminal command box). If there is a console message, it is recommended to use
jmeter.sh to start the interface in graphical mode (without a terminal command box). jmeter-server starts mirror-server
in server mode
.sh Start a mirror server
2.5, Jmeter graphic terminal installation
2.5.1, pre-conditions
Operating system: no limit, usually win system

JDK: 1.8+

Unzip to a folder after downloading

2.5.2. Parameter modification
(1), add the setenv.bat file under the bin directory

rem This is the content of bin\setenv.bat,rem it will be called by bin\jmeter.bat
set JVM_ARGS=-Xms2g -Xmx2g -Dpropname=longge


Here, adjust the memory size according to yourself, the default is 1024m, and start 4G for other reference options when doing large-scale tests. For details, see the official website (1.4 Running JMeter)
https://jmeter.apache.org/usermanual/get-started.html#running
 
(2 ), modify the jmeter.properties configuration file

server.rmi.ssl.disable=true
sampleresult.default.encoding=UTF-8 // If not set, the sampler result may be garbled

2.5.3, start/detect
(1), run jmeter.bat or jmeterw.cmd start

(2) After startup, open cmd and use the following command to detect the process in detail. The following indicates that the process exists and the parameter configuration takes effect

wmic process where caption="java.exe" get processid,caption,commandline /value
wmic process where caption="javaw.exe" get processid,caption,commandline /value
 


2.6. Jmeter server installation
2.6.1. Preconditions
Operating system: no limit, generally Linux system

JDK: 1.8+

Unzip to a folder after downloading

2.6.2, parameter modification
(1), add setenv.sh file under the bin directory

#This is the content of bin\setenv.sh,
#it will be called by bin\jmeter.sh
export JVM_ARGS="-Xms2g -Xmx2g -Dpropname=longge"


Here, adjust the memory size according to yourself, the default is 1024m, and start 4G for other reference options when doing large-scale tests. For details, see the official website (1.4 Running JMeter)
https://jmeter.apache.org/usermanual/get-started.html#running

(2 ), modify the jmeter.properties configuration file

server.rmi.ssl.disable=true
sampleresult.default.encoding=UTF-8
1
2
(3), modify jmeter-server file

RMI_HOST_DEF=-Djava.rmi.server.hostname=192.168.128.166

Here modify

2.6.3 according to the host address, start & detect
(1), run sh jmeter-server start

(2) After starting, use the following command to detect the process in detail. The following indicates that the process exists and the parameter configuration takes effect

ps -ef|grep longge

Missing picture

2.6.4. Modification on the graphics side
Modify the jmeter.properties file, and separate multiple hosts with commas

remote_hosts=192.168.128.166:1099,192.168.128.167:1099,192.168.128.168:1099

After the graphics terminal is started, you can see the relevant host in Run/Remote Start, indicating that the installation is successful
 
.

(2) Understanding the application scenarios of the three modes of Jmeter has a better guiding significance for our follow-up

3. Jmeter general configuration
3.1, setting Chinese
3.1.1, temporarily setting Chinese
Click Options <<< Choose Languse <<< Chinese (Simplified)

3.1.2. Permanently set Chinese
Enter the bin directory of the jmeter installation path and find the jmeter.properties file


Open the jmeter.properties file, find #language=en, modify it to language=zh_CN, and remove the "#" in front, and finally save the file


Finally, reopen jmeter and it will become Chinese.
3.2. Set the appearance (white)
and click the option <<< Appearance<<< Windows

3.3, Chinese garbled characters
(1), enter the bin directory of Jmeter, find the jmeter.properties file

(2), find #sampleresult.default.encoding=UTF-8, remove the # in front, and save

(3), restart Jmeter

Test case creation

Create a test group

Use one group for each project, such as one for APP and one for Web, or the current company's projects can also be grouped by module.

 Create a thread pool group

This grouping can be divided according to module functions, such as: login, or user management, and use a thread pool group to manage tests uniformly.

After the creation is successful, generate a sub-level thread group in the current TestPlan, save: ctrl + s, or click the save button on the toolbar:

1) Number of threads: the number of virtual users. How many threads to set is the number of virtual users to set

(2) Ramp-Up time (seconds): Set the time for all virtual users to start. If the number of threads is 20 and the preparation time is 10 seconds, then it takes 10 seconds to start 20 threads. That is, an average of 2 threads are started per second.

(3) Number of cycles: the number of requests sent by each thread. If the number of threads is 20 and the number of loops is 10, then each thread sends 10 requests. The total number of requests is 20*10=200. If "Infinite (unlimited times)" is checked,
all threads will send requests until the stop button on the toolbar is manually clicked, or the set thread time ends.

Add Http request

After the module thread pool is determined, there is an http interface test requirement for the current login. Next, create a specific http request interface for testing.

To start the Http interface stress test, click the start button:

I accidentally checked it when configuring just now, Infinite (Infinite), you need to manually click the Stop button to terminate the test, or watch the back-end service receive requests all the time. 

Judging test results: adding assertions

After configuring the interface information, configure assertions to check whether the test results meet expectations.

After the creation is successful, as shown in the figure above, this item is at the sub-level of the http request interface, because the above assertion is only for the current login interface.

Assertion writing configuration

 For example, my test returns a string: Person{name="lani", age="18"}, and the response header looks like this:

 So I add an assertion, as follows, there is 200 in the Response Code, then my test is OKb 

View the current interface test results 

Configure the expected results, and then configure the results of the tests that listen to the stress of this interface

 This item is at the sub-level of the http request interface, as shown in the figure below, View Result Tree is at the sub-level of the serial port that is currently logged in to http, and each result has a test result set. 

Check the test results of my running this interface, it shows that they are all successful, and each test result header has: 200, this code. 

Guess you like

Origin blog.csdn.net/LlanyW/article/details/130558573