Perform load (stress) testing on the Java Web using Jmeter __html5

Source: Internet
Author: User
Tags memory usage java web apache tomcat
The last one months is not to write a document is to knock JS, these two days rarely have a pressure test, finally with the Java hook. First talk about stress testing, this is definitely a very exciting thing to play the heartbeat, imagine, eyes staring at the performance of the server analysis data, while constantly increasing load, heart thump thump jump, really exciting.

First of all, thank the two brothers for their inspiration:
http://www.thegeekstuff.com/2015/02/jmeter-load-testing/
Https://www.digitalocean.com/community/tutorials/how-to-use-apache-jmeter-to-perform-load-testing-on-a-web-server

JMeter is a desktop application that can be used to perform functional testing and load testing. Although the JMeter application itself is designed as a pure Java application, it can be used to perform load tests on any type of Web application. The original intent of the application was to test Apache Tomcat performance, which is basically a Web server. Over the years, JMeter has become a viable performance test and load testing tool for enterprise Web applications as improvements to the user interface and other features have been made.

What is JMeter?

JMeter is part of the Apache Open source project.
It was originally written to test the performance of a Web server and is now used as an automated test tool and test data, as well as functional testing tools for Web applications, file servers, Web servers, and even databases. We will explore the important features of JMeter in this tutorial. You can configure to simulate N users and threads for a particular Web server or application. It generates a simulated load for the Web application to measure its performance. In addition, you can throw several iterations through the loop to get the average result, implement the assertion, and view the graphical and statistical representations of the test results.

Our stress tests are divided into the following steps:
1). Environmental preparedness
2). Download JMeter
3). Installation JMeter
4). Establish test Plan
5). View Test Results
6). Combined with test server analysis
7). Conclusion

1). Environmental Preparedness
Java environment, this needless to say, its own Baidu. This is tested with the window platform.

2). Download JMeter
Baidu input: Apache JMeter, point into the official website download, according to the native JDK version select JMeter version.

Here must choose Binaries version, installation will save a lot of things.

3). Installation JMeter
Unzip the JMeter that was downloaded in the previous step. For example decompression in D disk.
<1> create a new one in the environment variable:
Variable name: jmeter_home
Variable Value: D:\apache-jmeter-3.1

<2> in Classpath add:
;%jmeter_home%/lib/ext/apachejmeter_core.jar;%jmeter_home%/lib/jorphan.jar;%jmeter_home%/lib/logkit-2.0.jar

<3> in JMeter's Bin directory, double-click jmeter.bat

If there are two pop-up boxes, one of which is the JMeter graphical interface (swing does), that means the installation was successful.

Once the JMeter is installed and running, let's continue to build a test plan!

4). Establish Test Plan
The test plan consists of a series of test components that determine how to simulate the load test. We will explain how to use these components in our test plan.

Add a thread group
First, add a thread group to test the plan:
<1> Right-click Test Plan
<2> Mouse Add
<3> Mouse/thread (user)
<4> Click the Thread group
The thread group has three particularly important properties that affect the load test:
<1> Number of threads (user): JMeter The number of users attempting to impersonate. Set this 50
<2> acceleration Period in seconds: JMeter will assign the start of the thread to the duration of the thread. Set to 10.
<3> Loop Count: The number of times the test was performed. Set this to 1.

To add an HTTP request default value
The HTTP request default configuration element is used to set the default value for the HTTP request in the test plan. This is especially useful if we want to send multiple HTTP requests to the same server as part of the test. Now let's add the HTTP request by default to the thread group:
<1> Select Thread Group, and then right click it
<2> Mouse Add
<3> Mouse/sampler
<4> Click the HTTP request defaults
On the HTTP request by default, in the Web Server section, populate the server name or IP field with the name or IP address of the Web server you want to test. Set up the server here to make it the default server for the remaining items in the thread group.

Add view results in a table listener
In JMeter, the listener is used to output the results of the load test. There are many listeners available, and you can add additional listeners by installing Plug-ins. We will use the table because it is easy to read.
<1> Select Thread Group, and then right click it
<2> Mouse Add
<3> Mouse Listeners
<4> Click the view results in the table

5). View Test Results
Run the basic test plan
Now that we've built a basic test plan, let's run it and see the results.
First, save the test plan by clicking the file, save it, and then specify the file name you want. Then select View results in the left pane, then click Run from Main menu, then start (or click the Green start arrow below the main menu). You should see the test results run as a test in the table:

Explain the results
You may see that all requests have a status of "success" (represented by a green triangle with a check mark). After that, the columns you may be most interested in are sample time (ms) and latency (not shown in the example).
Latency: The number of milliseconds between JMeter sending a request and receiving an initial response
Sample time: The number of milliseconds that the server is fully serviced by the request (response + delay)
Number of samples: refers to the total number of requests made by the server during the testing process. A successful case equals the number of concurrent x cycles you set
Latest Sample: He represents time, indicating the time the server responded to the last request.
Throughput: Represents the number of requests processed by the server per minute.
Average: The total elapsed time divided by the number of requests sent to the server;
Deviations: Server response time changes, the size of the measurement of discrete degrees, or, in other words, the distribution of data.
Median: The number of times in which half of the server response time is less than the value and the other half is higher.

6). Combined with test server Analysis
SSH log on to the server to see CPU and memory usage, use top:

Parameter description
Cpu:
us-percentage of CPU consumed by user space.
sy-the percentage of CPU consumed by the kernel space.
ni-percentage of CPU per process that has changed priority
id-Idle CPU percent
Wa-io% of CPU waiting to be consumed
Men: Memory
total-Total Physical Memory
Total amount of memory in use by used-
free-Total Free Memory
Amount of memory in the buffers-cache

Unless you have a user actively attacking your server, you should see CPU (s)% User usage (US) should be very low or 0%, and CPU (s)% idle (ID) should be 99% +, so: Now, in JMeter, start the test again, Then switch back to the Web server's SSH session. You should see an increase in resource usage, starting with 50 threads, the average request time is 0.3s,cpu2%, increasing the load, let's try the same test with 80 threads in 10 seconds. In the thread group item in the left pane, change the number of threads (users) to 100. Now click the view results in the table and then run the test 100 is 2s, cpu13%,200 9s,cpu 28%, 500 19 seconds, cpu53%, to 1000 when cpu98% ... Bome. The test server collapsed. In fact I this increase thread too much, should slowly add, amplitude not too big, slowly measured in the requested time of the maximum number of threads.

7). Conclusion
<1>jmeter can be a valuable tool for determining how Web application server settings are improved to reduce bottlenecks and improve performance. Now that you are familiar with the basic usage of jmeter, you can create new test plans to measure the performance of servers in various scenarios.
The test examples we use do not accurately reflect the usage patterns of a normal user, but JMeter has tools to perform various tests that might be useful in your environment. For example, JMeter can be configured to simulate user logons to your application, client-side caching, and to process user sessions through URL overrides. There are a number of other built-in samplers, listeners, and configuration tools that can help you build the scenarios you need. In addition, there are jmeter plug-ins to enhance their functionality, can be downloaded in Http://jmeter plugins.org/.
<2> in the computer world, time space is always an irreconcilable contradiction. CPU used more, the faster the calculation, the greater the memory consumption, my test example above memory is not considered, most of the case, the CPU is the performance of the short board.

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.