Technology Sharing

jmeter distributed (IV)

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

1.gui

Jmeter's GUI is mainly used to debug scripts

1. Create a script first

Make a script first
Demonstration: How to script a hybrid scene?
The proportion of 211 business

①Start the database service

Database services: including mysql, redis
The default mysql port is 3306

netstat -lntp | grep 3306
  • 1

In listening state, 6379 is the default port of redis

netstat -lntp | grep 6379
  • 1

Project service port 18089

netstat -lntp | grep 18089
  • 1

②Access the interface document swagger

211 can convert two stress testing services

One is to register, the other is to register and log in to add products
The two are 50% respectively.

③Add thread group

jmeter - add thread group - add - thread - user - thread group

Convert two stress testing services

④Add throughput controller

jmeter --add-logic-controller-throughput-controller

Convert two stress testing businesses.
The first stress test business includes registration, login, and adding products
The second stress test service is registration

insert image description here

50% each
insert image description here

⑤Add sampler http request

jmeter --add-sampler-http-request
Convert two stress testing services
insert image description here

The first stress test business includes registration, login, and adding products

insert image description here

insert image description here

The second business is registration

According to the registration swagger, write and enter the parameters
insert image description here
Generally, you don't need to fill in the ID.
Addtime is not required.
Copy and paste the input data into jmeter
insert image description here

Path according to url
insert image description here

insert image description here

insert image description here

⑥Add http header manager,

All are passed json
insert image description here

insert image description here

⑦Add default value for http request

Fill in the IP and port according to the interface document
insert image description here
insert image description here

⑧Add a listener and view the result tree

insert image description here

⑨Add assertions

It is best to add assertions

insert image description hereinsert image description here

2. Non-gui

-n Execute jmeter in non-gui mode
-t executes the test file location, specifies the script to run jmeter, is not in the current path, the full path needs to be written out
-l specifies the generated result file, which is the jtl file
-eAfter the test is completed, generate a test report
-o specifies the storage location of the test report html
-r remote start

1. Single machine press

① Apply for a press

Install jdk and jmeter on linux press
Install in usr/local
Directly upload the jmeter on the window to the Linux press, because the plug-ins involved in the debugging script can also be used
insert image description here

②Upload the script to the press

Note: If the script involves a csv parameter file, you need to upload the csv' parameter file to the bin directory of jmeter under linux
Aggregate reports and listeners need to be disabled before uploading

5 threads, one thread added every 30 seconds, that is 150

The duration needs to be greater than the Rang up time of 150, and then run for another 50 seconds, so set it to 200
insert image description here

After jmeter is uploaded successfully, verify the jmeter version and whether it is available

insert image description here

③ Initialization

There are two places
First, the path to store the test script needs to create a directory to store the HTML report

insert image description here
Before running the script, the res directory must be empty
Second, clean up the data in the database table without considering the existing data.
insert image description here

④Execute the script

insert image description here

⑤ View the results

result
548 requests completed in 13 seconds

insert image description here
insert image description here

Open Aggregate Report
The number of failed requests

insert image description here
resopntime response time
insert image description here

tps

insert image description here

How to view jtl files?
JTL can be opened in any listener, such as viewing result tree, aggregate report, tps, response time.
If opened in aggregate report, click Browse
insert image description here

insert image description here
Such as tps, response time
Look at tps first
Add tps
Click to browse

insert image description here
insert image description here
insert image description here

insert image description here

Response timeinsert image description here

insert image description here

2. Distributed

Sometimes a single press cannot achieve the desired result and a distributed press is needed.
After all, the resources of a single machine are limited, and it is difficult to support large concurrency. The press of a single machine also has bottlenecks.

2.1 Distributed Principle

Official website:https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html

A server machine as a control machine
The rest of the machines are used as load machines
Target requested service
The controller remotely controls the start and stop of the load machine by sending signals, and collects and summarizes the load machine data.
The load machine mainly starts threads to access the server and the target server under stress test.
Generally, the worker starts the jmeter-server control machine to remotely control the load machine. The load machine starts a thread to request the target to obtain data and then sends it back to the control machine.

Where to put the script when distributed?
One controller with multiple workers
When executing non-gui, the script is transferred to the server. Now it is distributed, where should the script be transferred to?
The script will be transferred to the controller machine. When executed, the script will be sent to each load machine, that is, each worker. After the load obtains the script, it starts to execute the script. After execution, the data will be transferred to the control machine for aggregation.

2.2 Distributed Stress Testing Notes

(https://img-blog.csdnimg.cn/e3de7b8b65a1447db3bc3618876f62d3.png)
The firewall needs to be closed. If the firewall is not closed, the port needs to be opened.
All clients must be on the same subnet.
Make sure jmeter can access the server
Make sure the jmeter and java versions are the same
Disable SSL

2.3 Environmental Preparation

Requires 3 virtual machines
Use 181 as Controller
Use 182 and 183 as Workers (load machines)
At the same time, jdk and jmeter must be installed on these three virtual machines.
insert image description here
insert image description here
insert image description here
insert image description here
Check the JDK version
insert image description here
Install jmeter on three virtual machines
The local jmeter is transferred to the usr/local directory of the virtual machine
Check the jmeter version after uploading
insert image description here

2.4 Distributed Configuration

①Worker

182、182
First back up the configuration file jmeter.properties
insert image description here

server_port can be modified or not modified. The default value is 1099
insert image description here

Disable SSL
server.rmi.ssl.disable=false, change false to true
insert image description here

Start jemter
./jmeter-server
insert image description here
Check whether the port is in listening state on 182

insert image description here

verify
The control machine telnets the load machine to see if the port is connected
insert image description here
insert image description here

②Controller

Before configuring the control machine, debug on jmeter on window
win: for debugging
First back up the configuration file jmeter.properties
insert image description here
By default, this machine is used as the load machine.
The current load machine is a remote load machine, change remote_hosts=127.0.0.1 to remote_hosts=192.168.117.182:1099
You must enter the remote load machine's IP and port here. Separate multiple with commas.
insert image description here
insert image description here
Disable SSL
Change server.rmi.ssl.disable=false to server.rmi.ssl.disable=true
insert image description here

Debug it first on this machine
Restart jmeter and re-read the configuration file
insert image description here
After debugging on window, go to linux to configure

Configuring on 181
First back up the configuration file jmeter.properties

insert image description here

The current load machine is a remote load machine.remote_hosts=127.0.0.1Change toremote_hosts=192.168.117.182:1099
You must enter the remote load machine's IP and port here. Separate multiple with commas.

insert image description here

insert image description here

server.rmi.ssl.disable=false
Willserver.rmi.ssl.disable=falseChange toserver.rmi.ssl.disable=true
insert image description here
Once the script is transferred to the control machine, it will be automatically distributed to each load machine.
Separate test single scenario login
insert image description here
After uploading the script, execute the script
Execute via remote load

/usr/local/apache-jmeter-5.1.1/bin/jmeter -n -r -t test.jmx
  • 1

insert image description here

Each workload machine (press machine) has 5 threads, and the total control machine has 10 threads
insert image description here

Environment Preparation
Two virtual machines. One master and two slaves. The Windows machine is used as the master, and the slaves are virtual machines.
原理:https://jmeter.apache.org/usermanual/jmeter_distributed_testing_step_by_step.html

Problems:
java.rmi.RemoteException: Cannot start. localhost.localdomain is a loopback address

Created remote object: UnicastServerRef2 [liveRef: [endpoint:127.0.0.1:43474,objID:[-5a8dd143:17e2852fe88:-7fff, 3673082414768940798]]]
Server failed to start: java.rmi.RemoteException: Cannot start. localhost.localdomain is a loopback address.
An error occurred: Cannot start. localhost.localdomain is a loopback address.
insert image description here
Exception information: Server startup exception: Java remote method call threw an exception: Unable to start the service. localhost.localdomain is a local loopback address

The host name obtained by the hostname command is localhost
Use the command cat /etc/hosts to view the hosts configuration. localhost localhost.localdomain localhost4... points to 127.0.0.1
insert image description here
Solution:
Specify the IP address of the remote server host (rmi.server.hostname)
Start by specifying a terminal command
./jmeter-server -Djava.rmi.server.hostname=192.168.2.2
insert image description hereinsert image description here