We all know that jmeter can be used for interface testing and performance testing, and now most performance tests in enterprises use jmeter. Docker is a container deployment tool that has become popular in recent years. It can create a container, and then put the project into the container to build an independent operating environment.
So, some people thought, can they be used together?
Today, I will tell you how to use them together.
First, choose a linux machine, install docker
, then visit the gitee open source website, search for "nmb-jmeter-docker" to find this project
, then git down all the code of the project and upload it to the /opt path of the linux system
Create a jmeter container with docker (ordinary jmeter)
Enter the base-jmeter-docker folder
Execute sh build.sh to build a local jmeter image
The default version is jmeter5.1.1
After the build is successful, upload the jmx script file created with jmeter to the base-jmeter-docker path of the Linux machine, and execute
sh jmeter.sh -n -t YouJMX_file \
-l JTL_date +%Y%m%d_%H%M%S.jtl \
-j jmeter.log \
-e -o Report_date +%Y%m%d_%H%M%S
If you want to learn interface automation testing, here I recommend a set of videos for you. This video can be said to be the number one interface automation testing tutorial on the entire network at station B. At the same time, the number of online users has reached 1,000, and there are notes to collect and use. Technical exchanges of various masters: 798478386
You can also upload your jmx file to other paths, specify the jmx file path when running the jmeter.sh command
This command is the same as the CLI mode command of jmeter, and the related parameters of cli can also be used.
Create an enhanced jmeter container (jmeter with plug-ins)
-
Download all files in the [jpgc-jmeter-docker] folder
-
Build a local image: sh build.sh
-
Run the jmx file using the built image
sh jmeter.sh -n -t YouJMX_file \
-l YouJTL_date +%Y%m%d_%H%M%S.jtl \
-j jmeter.log \
-e -o report_date +%Y%m%d_%H%M%S
The default jmeter version is 5.1.1
If you want to change to another version, modify it in turn: the version number 5.1.1 in the Dockerfile, build.sh, and jmeter.sh files
Note: Please do not specify a version lower than 5, below 5, the generated HTML report may have problems
In this version, the HTML report is modified and the jpgc plug-in is introduced. If you want to introduce other plug-ins, you can pack and compress them into the JmeterPlugins-jpgc.zip file package. Then, execute sh build.sh to build a new image,
Create a distributed jmeter container (slave)
When doing performance testing, it is generally encountered that jmeter cannot generate a sufficient number of concurrent users, and we need to use distributed to create a sufficient number of concurrent users. However, in reality, we may not be able to obtain a sufficient number of computers.
Use docker to create jmeter assist services, so that it can be realized. In theory, any number of jmeter assist services can be created on one computer to generate a sufficient number of concurrent users. In addition, the maintenance of the assist machine has also become simpler, because all the assist machine containers are created based on the same image, and in theory, all containers are the same.
-
Download all files in the [slave-jmeter-docker] folder
-
Build a local slave image: sh build.sh
-
Create a slave container
docker run -itd --name slave1 nmb/jmeter-slave:5.1.1 server
# 重复执行时,修改容器名称name值,则可创建多个slave容器
The default jmeter version is 5.1.1
If you want to change to another version, modify it in turn: Dockerfile, version number 5.1.1 in the build.sh file
Notice:
1. Add the jpgc plug-in to the image, and change the HTML report template
2. Please do not specify a version lower than 5. If it is lower than 5, there may be problems with the produced HTML report
3. Assist service port 1099, 5000, because the master uses link to connect to the container later, so it is not necessary to map the port
To create multiple slave containers, you only need to modify the specified container name in the create container command.
The ports of each assist service are 1099 and 5000. If they are directly mapped to the host, there will definitely be port conflicts. Therefore, we don’t have to worry about port conflicts if we use the master to link each slave container.
Create a distributed jmeter container (master)
-
Download all files in the [master-jmeter-docker] folder
-
Build a local master image: sh build.sh
-
Modify the number and name of --link in the run-master.sh file
Before the colon is the name of the slave container, after the colon is the custom alias
-
Use the master container to execute distributed scripts
sh run-master.sh -n \
-R 助攻机别名(多个时用逗号分隔) \
-t YouJMXfile \
-l YouJTL_date +%Y%m%d_%H%M%S.jtl \
-j jmeter.log \
-e -o report_date +%Y%m%d_%H%M%S
The default jmeter version is 5.1.1
If you want to change to another version, modify it in turn: Dockerfile, version number 5.1.1 in the build.sh file
Note: Please do not specify a version lower than 5, below 5, the generated HTML report may have problems
Notice:
-
After the image is built successfully, it will have a jpgc plug-in, which can execute scripts written using the jpgc plug-in
-
The mirror also transforms the HTML report produced by jmeter, and the produced report will be converted into Chinese
-
jmeter is distributed, the jmeter of the master and assist machine must be the same, so the jmeter version of the master and slave must be the same
Well, the technology of using docker to create jmeter for performance testing has been finished, and the code has been open sourced to gitee. If you find it useful, please help to order ZAN!