Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the Jmeter stress test method?

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "what is the method of Jmeter stress testing". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the Jmeter stress testing method"?

Step 1 install Jmeter

The version I use is version 3.1, why is it 3.1, because there is a problem with 3.2. It took me a while to know that version 3.2 is too new or something, and some functions just don't work. I suggest that you should not easily use the latest version. The next new version will be fine. After installation, there is a Jmeter.bat file in Jmeter's bin directory, which can be run by double-click.

Step 2 use Jmeter to test the unlogged-in page

After running the software, of course we have to find a link to test, here we take Baidu as an example, we right-click "test plan"-"add"-"Threads (Users)-thread group", so we build a thread group, what is this, of course, it is used to run threads. After we have the thread group, we right-click the thread group, "add"-- "configure components"-- "http request default". What is this default value? You can set some commonly used default settings (this is nonsense). In the http request defaults panel, we can enter the IP or domain name of the server to be tested. Here we enter "www.baidu.com" and the protocol is "https". If the URL you want to test starts with http, fill in "http". The other defaults do not matter. Click on the upper left corner to save and a save box will pop up. This allows you to save the test configuration you have done now, and then just open the saved jmx file if you need to test it again later. After saving, we right-click "thread group"-- "add"-- "Sampler"-- "http request". Hey, didn't you just add it? Just now that is not, just that is only the default value, just used to set some default configuration, the real request is the "http request", in the http request we enter the slash "/" in the "path" on the line, indicating the default path, the IP column does not have to enter, why? Because you have already lost the default value of http request, you can create multiple http requests later, as long as you modify the path, so that you can access different pages of the same website. This is the meaning of "default value of http request". Just write some common settings. Next, we right-click "thread group"-- "add"-- "listener"-- "View the number of results", where you can see the http request and results. Click Save every time you create a new component and modify the configuration information. OK, the page configuration figure is as follows:

Now we click the green run button on the toolbar and we can see the result in "View the result tree".

Our newly-built "http request" returns a result of 200, indicating that the request was successful. As can be seen from the green tick, the drop-down list box in the above picture can choose the display format. We choose HTML and switch to "response data" to see the return page, that is, Baidu home page.

Step 3 set the number of thread concurrency

We have just finished a simple test, you should also feel that you have not done anything, you can test, in fact, we click on "thread group" to see the thread group settings page, the default setting of 1 thread, 1 second start, loop 1 time. The number of threads indicates how many threads are started, Ramp-Up Period indicates how long it takes to start all threads, and the number of loops represents the number of execution of each thread. For example, I set the number of threads to 10, Ramptel up Period is 10, and the number of loops is 2, which means that the software will start 10 threads in 10 seconds, that is, 1 thread in 1 second, and each thread will execute requests twice.

In addition, we can also check the "scheduler", for example, I fill in the duration 100, start delay 0, check "forever" for the number of cycles, indicating that the thread starts immediately and stops after 100 seconds, note, if the duration and start delay are set, then the following start time and end time will not work, it doesn't matter, just click run.

Step 4 set up other listeners

Previously, we only set up the listener "View result Tree". We right-click "Thread Group"-"add"-"listener". There are many listeners to choose from, such as graphical results, viewing results in tables, aggregating reports, and so on. These are indicators that reflect the testing process. The graphical results show the throughput, offset, average and other information in the form of graphics, and the table results show the time of each request, return, number of bytes sent, connection time, etc., and the aggregate report shows the overall throughput of the request, error rate and so on. The following figure shows the style of the table results.

As you can see, the figure shows 20 Http requests executed by 10 threads, each of which executes twice, exactly in line with our setting for the thread group. The meaning of each column in the figure represents the request sequence number, start time, thread sequence number, request name, request time, request status, request bytes, number of bytes sent, waiting time, connection time.

As the aggregate report shows in the following figure, the meaning of each column represents the name of the request, the total number of requests, the average response time of the request (in milliseconds), 50% of the request response time, 90% of the request response time, 95% of the request response time, 99% of the request response time, the minimum response time, the maximum response time, the error request rate (number of error requests / total number of requests) Throughput (number of requests processed per second), rate of bytes received, rate of bytes sent.

Step 5 login test

The page we tested earlier does not require login. Now let's test the login operation. Since the login operation involves specific internal URLs and parameters, I will use the general URL and parameters instead, but the method is the same. For example, if our intranet IP is 1.1.1.1 and the login page is 1.1.1.1/login.do, we will fill in 1.1.1.1 with "http request default". Enter / login.do into the path of "http request". I would like to explain the parameters needed for login. Generally speaking, it is the user name and password, but other parameters are often needed. We can grab the package through the package grabbing tool Fiddler. After a normal login in the website, we can see the post parameters needed for login in Fiddler. For example, Fiddler shows that the login operation post parameter has username,password,type. Then you need to fill in the "http request", as shown in the following figure.

Click the "add" button to add parameters, after saving, we click run, we can see the page after successful login in the view result tree, the specific operation is the same as before.

Step 6 session persistence

After we enter the login page, I also want to access modules such as "my account" and "my Information". These pages need to be logged in successfully before they can be accessed, and here we need to maintain the session. We right-click "Thread Group"-- "add"-- "configuration components"-- "httpcookie Manager". We can see the content to be added in the "request" tab of the view result tree. You can see the cookie required for login, such as JSESSIONID. We enter JSESSIONID into the parameters of the cookie manager, as follows

At this point, we enter the URL of the login page in the http request, such as "my Information" and so on, and the request can be successful.

Step 7 File read URL

What we fill in in the path of "http request" is the web page we want to visit, only one page at a time. If I want to visit several web pages, such as home page, notification page, company introduction page, etc., in addition to creating a new http request, we can also store the addresses of these web pages in the TXT file, for example, I want to visit 1.1.1.1index.dom1.1.1.1andinformation.do 1.1.1.1/company.do, we can do this.

After filling in the URL, we in the Jmeter inside the "options"-"function assistant dialog box"-"StringFromFile", paste the full path of the TXT to the location in the picture, click generate, you can generate the read path of the TXT file in the box.

We can access all the web pages in TXT by pasting the path at the beginning of $to the path of "http request", as shown in the figure.

Step 8 Real-time monitoring of server status

Above we have introduced several listeners that come with Jmeter. I wonder if you feel a little weak, because the indicators shown in them do not seem to be what you particularly need. At least for me, I am more concerned about the changes in the state of the server during the execution of my request, such as CPU, memory, disk, network, TPS, response time graph, etc., because this is the purpose of the stress test. The change curve of server status with the increase of requests is what we need to see more. To see the graph of server changes, we need to download JMeterPlugins-Extras.jar and JMeterPlugins-Standard.jar, put these two jar packages under lib/ext/ under the installation path of Jmeter, restart Jmeter, and right-click "Thread Group"-- "add"-- "listeners". We can see a lot of listeners. For most listeners that start with "jp@gc", we choose "PerfMon Metrics Collector". The status information of the server will be displayed, but you can't see it yet. Why? because the server you want to test needs to install a package called ServerAgent.zip. For example, if my server is linux, we will decompress the ServerAgent in the server and run the startAgent.sh inside. After startup, you can see the following

The default port is 4444. I would like to insert a word here. After I was running, I could not display it by ping less than 4444 port through Telnet. Later, I just changed it to 4445 port to start. The specific server command is ServerAgent-2.2.3/startAgent.sh--udp-port 4445-tcp-port 4445. This means that serverAgent will be started on port 4445, and you can change 4445 to another port. If the default port 4444 does not work, partners can try other ports. All right, let's go back to the Jmeter software and press the figure below to fill in the address and port number of the server, as well as the hardware to be monitored, such as CPU, memory, disk, network, and so on.

All right, we click run, and we can see the state change curve of the server under chart.

At this point, I believe you have a deeper understanding of "what is the method of Jmeter stress testing?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report