Java Program Performance Optimization-Performance tuning hierarchy

Source: Internet
Author: User


To improve system performance, developers can optimize the system from every angle and level of the system. In addition to the most common code optimizations, the software architecture, the JVM virtual machine layer, the database, and the operating system layer can be tuned in a variety of ways to improve overall system performance.

Design Tuning

Design tuning is at the top of all tuning methods, and it often needs to be done before software development. At the beginning of software development, the software architect should evaluate the potential problems of the system and give a reasonable design plan. Because software design and architecture have a decisive impact on the overall software, design tuning has the greatest impact on system performance. If the code optimization, JVM optimization is to the system micro-level "Quantity" optimization, then design optimization is to the system at the macro level of "quality" optimization.

One notable feature of design optimization is that it avoids the performance problems of a component, rather than improving the implementation of the component. For example, component A in the system needs to wait for an event E to start a behavior. If component A continuously detects the occurrence of event e through cyclic monitoring, its monitoring behavior inevitably consumes some system resources, so developers must strike a balance between monitoring frequency and resource consumption. If the monitoring frequency is too low, although the resource consumption is reduced, the real-time responsiveness of the system will be reduced. If the code layer is tuned, it is necessary to optimize the implementation of the monitoring method and to obtain an appropriate monitoring frequency.

If you reserve this issue at the design level, you can use event notifications to invert system behavior. If the observer design pattern is used, the event E notifies component A at the moment the event e occurs, triggering the behavior of component A. This design method discards the existence of the performance hidden danger of the circular monitoring, fundamentally solves this problem.

In a way, design optimization directly determines the overall quality of the system. If the design layer is poorly considered, leaving too many hidden problems, then these "quality" problems, may not be able to pass the code layer optimization to compensate. Therefore, developers must carefully consider the performance of software systems at the beginning of software design.

Design optimization, designers must be familiar with the common software design methods, design patterns, basic performance components and common optimization ideas, and organically integrated in the software system.

Note: a good system design can circumvent many potential performance issues. Therefore, spending as much time as possible on system design is the key to creating high-performance programs.

Code Tuning

Code tuning is the improvement and optimization of the program code during the software development process, or after the software development is completed, during the software maintenance process. Code optimization involves a number of coding techniques that require developers to familiarize themselves with the APIs in the relevant language and use the relevant APIs and class libraries correctly in the appropriate scenario. At the same time, the flexible use of algorithms and data structures is also an important part of code optimization.

While code optimization is a micro-tuning of performance, a "good" implementation and a "bad" implementation have a significant impact on the system. For example, the same as the implementation of the list, LinkedList and ArrayList on the random access performance can be a few orders of magnitude, as well as the implementation of the file read and write, the use of stream mode and Java NIO, its performance may be a different order of magnitude.

Therefore, although compared with the design optimization, the author referred to the Optimization of code optimization at the micro level, but it is the most direct impact on the system performance optimization method.

JVM Tuning

Because Java software is always running on top of the JVM virtual machine, optimizing the JVM virtual machine can also improve the performance of the Java program to some extent. JVM tuning can often be done later in software development, such as in software development, or at a milestone stage in software development.

As a running platform for Java software, the parameters of the JVM will directly affect the performance of the Java program. For example, the JVM's heap size, garbage collection policy, and so on.

For JVM-level tuning, developers need to be aware of how the JVM works and the basic memory structure. such as the structure of heap memory, the type of GC, etc. Then, based on the characteristics of the application, set reasonable JVM startup parameters.

Database tuning

For most applications, databases are an essential part of the system. Java programs can connect to a database using JDBC. Tuning a database can be divided into 3 parts:

-Optimization of SQL statements at the application level;

-Optimize the database;

-Optimize the database software.

Optimizing database access at the application level involves a lot of programming skills. For example, when using JDBC for query operations, for a large number of SQL queries that have the same structure, you can use PreparedStatement instead of statement to improve the query efficiency of the database; In the SELECT statement, display the name of the column that specifies the query, and avoid using "*".

When optimizing the database, the main purpose is to establish a database with a good table structure. For example, in order to improve the efficiency of multi-table cascading queries, redundant fields can be used reasonably, and for large tables, horizontal cutting of rows or similar techniques for Oracle partitioned tables can be used, and effective and reasonable indexes can be established to improve the efficiency of database query.

For database software optimization, depending on the database, such as Oracle, MySQL, or SQL Server have different ways. In Oracle, for example, setting a reasonably sized shared pool, cache buffer, or PGA can have a significant impact on the performance of Oracle.

Operating system tuning

As the basic platform of software operation, the performance of operating system has a great impact on the application system. Different types of operating systems, optimized means and parameters may vary. For example, in mainstream UNIX systems, shared memory segments, semaphores, shared memory maximums (SHMMAX), shared internal ability minimums (Shmmin), and so on are all system resources that can be optimized. In addition, parameters such as maximum file handle count, virtual memory size, disk block size, and so on, can have an impact on the performance of the software.

In a system with performance problems, Ten is caused by a system bottleneck. As long as the performance bottleneck is found, analysis of the causes of bottlenecks, the right remedy, the use of reasonable methods to solve performance bottlenecks, can fundamentally improve performance. Therefore, the most important system performance optimization is to find and solve the performance bottleneck problem. However, it is also worth noting that performance optimizations often involve large modifications to the original implementation, so it is difficult to ensure that these changes do not introduce new problems. Therefore, before the performance optimization, it is necessary to optimize the performance of the objectives, methods to coordinate arrangements.

To optimize the software system, it is necessary to have a clear performance target, and clearly point out the optimized object and the final goal. Second, the software needs to be tested on the target platform, through various performance monitoring and statistical tools to observe and confirm whether the current system has reached the relevant targets, if already achieved, there is no need to optimize; If the current system performance has not yet reached the optimization target, you need to look for current performance bottlenecks.


The above text is organized from: [Java Program Performance Optimization-. Make your Java program faster and more stable]. Ge Yi and other authoring

"Reproduced use, please specify the Source: Http://blog.csdn.net/mahoking"


Java Program Performance Optimization-Performance tuning hierarchy

Related Article

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.