Java Program Performance optimization

Source: Internet
Author: User

Java Program Performance optimization

Understand the performance of the computer know that performance response is slow to reflect: interface pauses, jitter, unresponsive, etc.
Performance features include:

    1. Execution Speed: whether the program is fast and the response time is short enough
    2. memory allocation: whether memory allocation is reasonable, excessive memory consumption or presence of leaks
    3. startup time: How long it takes for the program to process the business normally from running
    4. load carrying Capacity: when the system pressure rises, the system execution speed, the response speed of the rising curve is flat

The performance reference indicators are:

    • Execution Time: a period of code from start to finish, the time spent
    • CPU Time: The time of the function or thread CPU
    • memory allocation: memory space occupied by the program while it is running
    • Disk Throughput: describes the usage of I/O
    • Network throughput: Description of network usage
    • response Time: The response time that the system makes to a user's behavior or event. Shorter response times, better performance bucket principle and performance bottleneck

Also called the short board theory, its core idea: how much a bucket of water, does not depend on the barrel wall the highest wood, and depends on the shortest block, even if there is sufficient memory and the premise of the CPU, if I/O disk is low, then the overall system will run slowly, only to improve disk I/O performance to optimize the overall performance Therefore, disk I/O is a system performance bottleneck
Note: the quality of the system ultimately depends on the worst components, which must be optimized, not the components that perform best for the system
Optimal computer resources that can become a system bottleneck:

    • disk I/O: because disk I/O is slower to read and write than memory, inefficient I/O can slow down the entire system if the disk is finished I/O
    • CPU: computer applications that require high demands on computers, because of the time consuming, the CPU resources are constantly occupied, then the CPU contention causes the performance problem
    • Exceptions: exception capture and processing is very resource-intensive for Java applications, and program Gaoping rate for exception handling
    • database: Most applications do not need databases, and massive database reads and writes can be time consuming
    • lock contention: for highly concurrent programs, lock contention increases thread switching overhead if there is intense competition
    • Memory: in general, as long as the application is designed properly, memory read/write speed is unlikely to be a performance bottleneck. Unless the app improves memory swapping and scanning
    • AMDANHL Law


It defines the design formula and the theoretical limit of the parallel post-acceleration ratio of the serial system.
acceleration ratio definition: acceleration ratio = system consumption before optimization/optimization of System consumption
acceleration Ratios: time-consuming and time-consuming ratios before optimization. The higher the acceleration ratio, the more obvious the optimization
Second, the performance tuning level,
In addition to the software architecture, JVM virtual machine layer, database and operating system level through tuning to improve performance, design tuning in the upper layer of tuning, often need software development, because the software development design and architecture for the overall quality of software is determined, design tuning performance is also the largest.
The greatest feature of design optimization is the ability to circumvent a component rather than an improved component implementation. Therefore, developers must monitor the frequency and resource consumption of the balance between

Code Tuning

Need to be familiar with the relevant language API, and correctly use the API or class library, the algorithm structure flexible use of likelist and ArrayList random access performance, the same file read and write implementation, using stream mode and Java NiO way
JVM Tuning
Optimizations to JVM virtual machines have a certain level of rise in Java performance. The JVM parameters directly affect performance. JVM heap Size, garbage collection mechanism policy
Database Tuning
You can connect to a database using JDBC, tuning into 3 parts
The application layer optimizes SQL statements
Optimize your database
Optimization of database software
Optimize the database access layer, use JDBC to query, for a large number of SQL queries, you can use preparestatement instead of statement to improve the efficiency of database query data: SELECT statement Query column name, avoid using *
Database optimization, the main purpose is to establish a good table structure database, for example: with multi-table-level joint query efficiency can be reasonable redundant fields, for large tables using horizontal cutting or similar orcal partition table technology, in order to improve database query efficiency, can establish a reasonable index

Java Program Performance optimization

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.