Java program performance optimization-performance tuning level

Source: Internet
Author: User

Java program performance optimization-performance tuning level
 

To improve system performance, developers can optimize the system from all aspects and layers of the system. In addition to the most common code optimization, the software architecture, JVM Virtual Machine layer, database, and operating system layer can all be tuned through various means to improve the overall system performance.

 

Design Optimization

Design Optimization is at the top of all optimization methods. It usually needs to be performed before software development. At the beginning of software development, software architects should evaluate various potential problems in the system and provide reasonable design solutions. Because the software design and architecture have a decisive impact on the entire software, the design optimization has the biggest impact on the system performance. If code optimization and JVM optimization are both on the microscopic level of the system, the design optimization is on the macro level of the system.

A major feature of design optimization is that it can avoid performance problems of a component rather than improve the implementation of the component. For example, in the system, component A needs to wait for event E to start an action. If component A continuously detects event E Through cyclic monitoring, its monitoring behavior will inevitably occupy part of system resources. Therefore, developers must strike A balance between the monitoring frequency and resource consumption. If the monitoring frequency is too low, although the resource consumption is reduced, the system's real-time response will decrease. If you optimize the code layer, You need to optimize the implementation of the monitoring method and obtain an appropriate monitoring frequency.

If you leave this issue at the design layer, you can use Event Notification to put the system action upside down. If the observer design mode is used, when the event eoccurs, the event enotifies component A to trigger the action of component. This design method discards Cyclic Monitoring with potential performance risks and fundamentally solves this problem.

To some extent, design optimization directly determines the overall quality of the system. If there are too many potential problems in the design layer, these "quality" problems may no longer be remedied through code layer optimization. Therefore, developers must carefully consider the performance of the software system at the beginning of the software design.

During design optimization, the designer must be familiar with common software design methods, design patterns, basic performance components, and common optimization ideas, and organically integrate them into the software system.

Note:A good system design can avoid many potential performance problems. Therefore, it is critical to create high-performance programs to spend as much time as possible on system design.

 

Code optimization

Code optimization 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 many coding techniques. developers need to familiarize themselves with the APIs of relevant languages and use related APIs and class libraries correctly in appropriate scenarios. Meanwhile, flexible use of algorithms and data structures is also an important part of code optimization.

Although the performance is adjusted from the micro perspective during code optimization, a "good" implementation and a "bad" implementation have a great impact on the system. For example, as a List implementation, the performance of the random List and ArrayList on random access can be several orders of magnitude different. For example, it is also the implementation of file read/write, the performance of Stream and Java NIO may differ by an order of magnitude.

Therefore, although compared with design optimization, code optimization is called micro-level optimization, it is the most direct impact on system performance.

 

JVM Optimization

Because Java software always runs on the JVM virtual machine, optimizing the JVM virtual machine can also improve the performance of Java programs to a certain extent. JVM tuning can usually be performed later in software development, such as after software development or a milestone in software development.

As the running platform of Java software, JVM parameters directly affect the performance of Java programs. For example, the JVM heap size and garbage collection policy.

To perform JVM-level optimization, developers must have a certain understanding of the JVM operating principle and basic memory structure. For example, the heap memory structure and GC type. Then, set reasonable JVM startup parameters based on the characteristics of the application.

 

Database Optimization

Databases are an essential part of most application systems. Java programs can use JDBC to connect to the database. Database optimization can be divided into three parts:

□Optimize SQL statements at the application layer;

□Optimize the database;

□Optimize the database software.

Optimizing database access at the application layer involves a lot of programming skills. For example, when you use JDBC for query operations, you can use PreparedStatement to replace Statement for a large number of SQL queries with the same structure to improve database query efficiency. In Select statements, display the name of the specified column to be queried. Avoid "*".

The main purpose of database optimization is to establish a database with a good table structure. For example, to improve the efficiency of Multi-Table cascading queries, redundant fields can be reasonably used. For large tables, horizontal row cutting or similar Oracle partition tables can be used. To improve database query efficiency, an effective and reasonable index can be created.

Database software optimization varies with different databases, such as Oracle, MySQL, or SQL Server. Taking Oracle as an example, setting a reasonable size of the Shared Pool, cache buffer, or PGA has a great impact on the Running Performance of Oracle.

 

Operating System Optimization

As a basic platform for software operation, the performance of the operating system also has a great impact on the application system. Different types of operating systems may have different optimization methods and parameters. For example, in mainstream UNIX systems, shared memory segments, semaphores, shared memory maximum values (shmmax), and shared internal capacity minimum values (shmmin) are all system resources that can be optimized. In addition, parameters such as the maximum number of file handles, virtual memory size, and disk block size may affect the performance of the software.

 

A system with performance problems is caused by a system bottleneck. You only need to find the performance bottleneck, analyze the cause of the bottleneck, take the right medicine, and use a reasonable method to solve the performance bottleneck, which can fundamentally improve the performance. Therefore, the most important part of system performance optimization is to find and solve performance bottlenecks. However, it is worth noting that performance optimization often involves making major changes to the original implementation. Therefore, it is difficult to ensure that these changes will not introduce new problems. Therefore, before performance optimization, you need to make overall arrangements for performance optimization goals and methods.

To optimize the software system, you must first have a clear performance goal and clearly point out the optimized object and the final goal. Secondly, the software should be tested on the target platform. Various performance monitoring and statistical tools should be used to observe and confirm whether the current system has achieved the relevant objectives, there is no need to optimize the system. If the current system performance has not reached the optimization goal, you need to find the current performance bottleneck.

 

 

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.