Java performance optimization authoritative guide Reading Notes and java performance optimization authoritative guide
In addition to the above four mind maps, we can extract the following parts:
2.3CPU scheduler run queue
If the length of the running queue has been more than twice the number of virtual processors for a long period of time, you need to pay attention to it, but you do not need to take immediate action yet. For a long time, the length of the running queue can reach 3 to the number of virtual processors ~ 4 times or higher, you need to immediately get attention or take action.
There are two ways to solve the problem of running queues. One is to increase the CPU to share the load or reduce the amount of load processed. Another method is to analyze the applications running in the system and improve the CPU usage. In other words, research can reduce the CPU cycle required for applications to run, such as reducing the garbage collection frequency or using algorithms that fully agree to the task but have fewer CPU instructions.
2.5.4 considerations for Application Performance Improvement
Applications with a small amount of read/write data and a large amount of network read/write consume a large amount of system-state CPU, resulting in a large number of system calls. For such applications, the policy to reduce the system-state CPU is to reduce network read/write system calls. In addition, using non-blocking Java NIO instead of blocking java.net. Socket can reduce the number of threads for processing requests and sending them, and improve application performance.
The policy for reading data from a non-blocking Socket is that the application reads as much data as possible during each read request. Similarly, when writing data to a Socket, each write call should write as much data as possible.
2.6 disk I/O usage
If the disk I/O usage of the application is high, it is worthwhile to analyze the performance of the system disk I/O subsystem in depth, view the expected load, disk service time, track time, and service I/O event time. To improve disk usage, you can use some policies. In terms of hardware and operating systems, the following are some policies for improving disk I/O usage:
One method that is often overlooked about disk performance is to check whether the disk cache is enabled. Some systems disable the disk cache. Enabling disk cache can improve the performance of applications that depend heavily on disk I/O. However, if you find that the disk cache is disabled by default, you should note that, once the disk cache is enabled, unexpected power failure may cause data damage.
3.2.7 Exception Handling
When semantic constraints conflict with Java, the Java Virtual Machine will use an exception notification program. For example, an exception occurs when you try to obtain elements outside the array range. Exceptions lead to non-local transfer of program control, from where exceptions occur or directly throws, to where programmers specify or where exceptions are caught. Exception Handling is implemented by the HotSpot VM interpreter, JIT compiler, and other HotSpot VM components in collaboration. Exception Handling involves two main scenarios: throwing and capturing exceptions in the same method, or capturing exceptions by calling methods. The latter case is more complex, so you need to roll back the stack to find a suitable exception processor. Exceptions can be caused by throwing bytecode, returning from an internal VM call, returning from a JNI call, or returning from a Java call. The last case only happens after the first three cases. When the VM encounters an exception, the system will call the HotSpot VM runtime to find the processor closest to the exception. There are three types of information that can be used to find the exception processor: current method, current bytecode, and exception object. As mentioned above, if no exception processor is found in the current method, the current active stack frame will be rolled back, repeat this process until the exception processor is found. Once an appropriate exception processor is found, the execution status of the HotSpot VM is updated and jumps to the abnormal processor to continue executing Java code.