JAVA advanced programming: J2EE performance testing and Optimization

Source: Internet
Author: User
JAVA advanced programming: J2EE performance testing and Optimization-general Linux technology-Linux programming and kernel information. For details, see the following. The purpose of this article is to explain how to implement scalability testing, performance testing, and Optimization in a typical J2EE environment.

?? Definition

?? Response time: the time between the initial request and the completion of the response download (refresh the entire page.
?? Load: the scale used by the system. When the application of the server can withstand heavy traffic, it is called being able to withstand "high load ".
?? Scalability-A Scalable Application should have a response time that increases linearly with the load. Such applications can increase hardware facilities linearly (not exponentially) to process more and more data.
?? Automated testing tools-tools that simulate user requests to webpages or traverse pre-programmed workflows (LINKS) on your website (such as the Silk and WebLoad of Segue software ).
?? Load testing tools-most automated testing tools are also load testing tools, such as WebLoad. These tools can simulate the use of your site by any number of users, and provide important analysis data, such as average response time.
?? Profiler-Profiler is a program that is detected when your application is running. It provides useful runtime information such as the running time of special code blocks, memory/heap utilization, and the number of instances of Special Objects in memory.

?? Performance Testing Process

?? 1) function testing. Most applications first test the function. Ensure that all test cases/workflows in the application work properly.
?? 2) load and scalability tests. There are two ways to test the load and scalability:
??? ☆Test the response time while increasing the database data volume.
??? ☆Test the response time while increasing the number of current users.
?? 3) Explain the results. After testing the response time under various database capacities and different loads, you can explain it based on the average response time of these tests and the resource utilization rate of servers in the tests.
?? 4) optimization. After the previous step is completed, identify the problem, explain the result, and capture the problem.

?? Load and scalability tests

?? The purpose of the load and scalability test is to ensure that your application has a good response time during peak hours of use. You can also test the behavior of your applications during overload (because the database on your site has more and more data ). Before testing, write some scripts to fill the database with the average data volume, run the performance test, and measure the response time. Then fill the database with a large amount of data (about three to four times the expected data volume in three years) and run the performance test again. If the response time for the second test is particularly long, there must be a problem.

?? During performance testing, you may want to simulate the server usage under different loads. Based on experience, you can simulate low load (1-5 concurrent users), medium load (10-50 concurrent users), large load (100 concurrent users), and heavy load (more than 1000 concurrent users ). Note that these figures are uncertain, depending on your business needs. In addition, simulating 10 concurrent users using the load testing software does not really represent 10 concurrent users, because in the load testing, each "robot" will wait several milliseconds before hitting the server again. In this way, the use of load testing tools to simulate 10 concurrent users almost represents 30-40 users in the actual online surfing.

?? After testing these three load levels, you can compare the average response times in these cases and check whether your server can withstand large traffic volumes, whether the average response time increases linearly.

?? Explanation result

?? The most interesting part of the performance test process is to explain the results of the load test. Let's take a look at several different possibilities:

?? 1. When the amount of data in the database increases to a certain extent, the response time is extended.

?? When the number of records in the database increases from 100 rows to 50,000, the response time should not increase significantly. The database indexing technology allows it to take only a few milliseconds to query a record from a table, even if the table has thousands of records. This means that when you increase the response time from a database with moderate data volume to a database with excessive data volume, if the response time is greatly extended, you may not have indexed the appropriate columns.

?? 2. The response time increases exponentially when the load increases.

?? If the system becomes unavailable when you increase the number of concurrent users, your system is not scalable. This result is difficult to explain, because the cause may be hardware, platform configuration, system architecture, and so on. Be sure to monitor the following server resources during the test:
?? ☆Monitor memory requests.
?? ☆Monitor CPU usage.

?? If the CPU is overloaded, it requires faster or more processors. If the CPU usage is low, it may be related to the input and output problems. Check the database connection, thread count, and network configuration of the test system.

?? Check the configuration to identify that it is not a hardware bottleneck and the architecture and code have been optimized. If the problem persists, you should monitor the code during runtime (using profiler ).

?? Optimization

?? Database, architecture, configuration, and hardware are all objects to be optimized. As mentioned above, the simplest mistake that causes low server load tolerance is that the database has not been optimized. Database Administrators (DBAs) are critical to any development group. If not, consider doing so:

?? Check all ejbs and verify that the database does not perform linear search for any encoded SQL statements. You can copy the SQL statements in the Code to the SQL query tool window of the database and execute the EXPLAIN clause:

?? Explain select * from table where tablefield = somevalue

?? Although the Explain syntax varies with different databases, there are always something similar. The database will tell you whether the statement is based on index query or linear query. Make sure that each SQL statement in the database uses an index. If not, create an index.

?? Optimize the hardware configuration after the database is optimized, and then use profiler to optimize the code.

?? The Profiler program analyzes it when your application is running and provides you with information that cannot be obtained using other methods, such:

?? 1. The number of objects in the memory and the spam collector behavior of each class.

?? ☆This information helps you identify the classes that should be cached.
?? ☆It helps you adjust the Java memory heap.

?? 2. How long does an application spend in a specific class.

?? This is a very important feature. Profiler can point out that class is a bottleneck.

?? There is such a profiler program called Optimize-It. Optimize-It can be used for any Java program or Java-based application server. It can be easily configured with WebLogic or used to analyze applications on the remote server.

?? Optimizing the architecture is inseparable from specific projects. However, there are some tips:

?? (1) ensure that the Network calls are minimal, especially database calls.
☆A large database call is much better than many small calls.
☆Ensure that ejbStore does not save any information for read-only operations.
☆Use Details Objects to get the Entity Bean status.

(2) ensure that the Cache is used whenever possible.
The Application Server may allow the use of Entity Bean caching in memory to ensure that these features are used because it can significantly reduce database calls and accelerate data access.

(3) ensure that Session Bean is used as the encapsulation of Entity Bean.
A complete instance workflow can be encapsulated into a network call and used as a Session Bean (and a transaction) method.

   Conclusion

Testing and optimizing application performance is a challenge. Fortunately, there are many tools on the market that can make the process simple. Using these tools, follow the simple steps mentioned in this article to effectively capture system bottlenecks.

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.