Overview of Java performance tuning

  • 2020-06-03 06:24:35
  • OfStack

Main performance points of the program:

Speed of execution: Whether the program responds quickly and the response time is short enough Memory allocation: Is memory allocation reasonable, is memory being consumed too much, or is there a memory leak Startup time: How long does it take for a program to run until it can handle business properly Load bearing capacity: When the system pressure rises, whether the rise curve of system execution speed and response time is flat

Key metrics to measure program performance:

Execution time: The time taken for a program to run from end to end CPU time: Function or thread takes up CPU time Memory allocation: The space taken up by a program at run time Disk throughput: describes the usage of I/O Network throughput: Describes network usage Response time: The time it takes the system to respond to user actions or events. The shorter the response time, the better the performance

Several aspects that can become system performance bottlenecks:

Disk I/O: Disk I/O reads and writes much more slowly than content, and inefficient disk I/O operations can drag down the system if your program has to wait for disk I/O to process Network operation: Due to the uncertainty of the network environment, the operation of reading and writing network data may be slower than the local disk I/O. If the network operation is not handled properly, it will become the bottleneck of the system CPU: For applications with high requirements on computing resources, the competition for CPU will lead to system performance problems due to the large amount of CPU resources occupied for a long time without interruption Exceptions: Exception catching and handling in Java can be very resource-intensive, and if there is high frequency of exception handling in the code, the overall system energy of the code can be significantly reduced Database: It is quite time consuming to read and write a large amount of data to the database, and often many codes need to wait until the database operation can be completed before the subsequent operation, this slow synchronization operation will also become the system bottleneck Lock contention: For highly concurrent systems, lock contention is quite intense, which is a huge blow to performance. Lock contention can significantly increase the overhead of thread context switching, which is often unrelated to application requirements and consumes CPU resources without any benefit Memory: 1 In general, memory reads and writes are unlikely to be a performance bottleneck as long as the application is properly designed. Unless there is a high frequency of memory swapping and scanning in the program. The most likely scenario where memory becomes a system bottleneck is the memory size. If an application stores some commonly used core data in memory, this will reduce the performance of the application to a certain extent, so pay attention to 1 optimization when writing commonly used data to memory

Levels of performance tuning:

Design tuning: At the top of all tuning tools, prior to software development, software design and architecture have a decisive impact on the overall quality of the software, so design tuning has the greatest impact on system performance. Other optimizations are quantitative optimizations on the micro level, while design optimizations are qualitative optimizations on the macro level. A good system design can avoid many potential performance problems, so spending as much time as possible on system design is key to creating high-performance programs Code tuning: During software development, after software development and during software maintenance, code improvements and optimizations require developers to be familiar with the language API, to use the correct API in appropriate scenarios, and to be flexible with algorithms and data structures JVM tuning: You need to have a certain understanding of how JVM works and the basic memory structure, and then set reasonable JVM startup parameters according to the characteristics of the application Database tuning: Mainly includes the optimization of SQL statements in the application layer, the optimization of the database (design a database with good table structure), and the optimization of the database software (such as the use of Oracle database, the need to set a reasonable size of the Shared pool, cache buffer, etc.) Operating system tuning: Tuning methods and parameters may vary from operating system to operating system. In the mainstream UNIX system, Shared memory segment, semaphore, Shared memory maximum and Shared memory minimum are all system resources that can be optimized

Basic tuning strategies and tools

(First, locate the performance bottleneck of the system and determine the relevant code for code optimization. If there is no code optimization space, consider other aspects of optimization: JVM optimization, database optimization, operating system optimization, etc.) Performance optimization is rigorously tested

conclusion

Performance optimization has risks and drawbacks. Performance tuning must have clear goals. Don't tune just for tuning's sake!! Blind tuning, the risks far outweigh the benefits!!


Related articles: