Detailed architect Ali P8 Java performance tuning strategy

Detailed architect Ali P8 Java performance tuning strategy

First, the performance test


Ⅰ. Test Method

  1. Micro-benchmarks

    • Precise positioning may be a module or the performance problems of a method, for example, a method of using comparative performance difference asynchronous and synchronous implementation to achieve
  2. Macro benchmarks
    • Acer is a comprehensive benchmark tests, need to take into account the test environment, test scenarios and test objectives
    • Test environment: real-world analog line
    • Test scenario: When testing an interface, the interface if there are other businesses are run in parallel, thereby causing interference
    • Test target
    • It can be measured by whether the target system throughput and response time, if not standard, it needs to be optimized
    • If the standard, continue to increase the number of concurrent test, the bottom of the interface TPS
    • In addition to concerns of throughput and response time interfaces, but also need to focus on utilization of CPU, memory and the IO

Ⅱ. Confounding factors

1. warm-up problem

After ①. In the Java programming language and environment, .java files compiled into .class files, you need to convert bytecode to native machine code to run through the parser

②. In order to save memory and execution efficiency, the initial code is executed, the parser will parse the lead in the implementation of this code

③. With the increase in the number code is executed, when the JVM found a method or block of code to run very frequently, these codes will be recognized as a hotspot Code

  • In order to improve the efficiency of the hot code at run time, JVM will compile the code into the relevant through time compiler (JIT) and native platform machine code
  • And at all levels of optimization, and then stored in memory, when the code after each run directly from memory

④. Therefore, in the beginning stages of operation, JVM will take a long time to fully optimize the code, will be able to run at peak performance behind the

2. Test results are unstable

① instability: the machine affect other processes, network fluctuations, JVM GC uncertainty
. ① solutions: through multiple tests, the test results are averaged, the average long as the guarantee within a reasonable range, and volatility is not to

3. Multi-JVM

①. Any JVM has a right to use the resources of the entire system
②. If only deployed on a single machine a JVM, when doing performance testing, test results will be good, but there are multiple JVM on a machine, not necessarily
③. try to avoid a machine-threaded environment to deploy multiple JVM

Second, the performance analysis


1. After completion of the performance test, a performance test report needs to be output, the test results need to include

  • Test interface throughput and response time (average, maximum, minimum)
  • Server CPU, memory, disk IO, IO network usage, GC case of the JVM

2. By observing the performance indicators, performance bottlenecks can be found, re-analysis to find the problem by bottom-up approach

  • First, from the operating system level, CPU, memory, disk IO, network IO system usage to see whether there is an abnormality
  • Find exception log command again, by analyzing the log for the cause of performance bottlenecks
  • You can also start from the JVM level, Java applications, GC frequency and memory allocation to see whether there is abnormal JVM
  • If the system JVM level and are not abnormal situation, you can view the performance bottleneck if there is an application service business layer
    • Such as the Java programming problem, reading and writing data bottlenecks

3. analysis to find performance problems bottom-up approach can be used, and the way to solve performance problems, generally use a top-down level by level optimization

Third, performance tuning


Ideas : Business tuning -> Tuning Programming -> System Tuning

Ⅰ. Optimized code

1. The application layer code in question because often run out of system resources exposed

2. For example a piece of code cause a memory leak, which is often the JVM runs out of memory

  • This will lead to GC JVM occur frequently, resulting in high CPU, this time the system will run out of CPU resources

3. There are a number of non-performance issues caused by problems in your code more difficult to find

  • For example if LinkedList be for looping through, get the elements of each cycle, will traverse a list, reading is very low efficiency
  • Optimization: can be used Iterator

Ⅱ. Optimized design

1. There are many object-oriented design patterns can be used to optimize the design of the business layer and the middleware layer codes, and then to streamline and improve the overall performance of the code object

2. For example singleton objects in the scene frequently created, you can share an object, reduce the frequency of creation and destruction caused by the performance overhead objects

Ⅲ. Optimization algorithm

1. Suitable algorithms can greatly enhance the system performance

2. For example, in different scenarios, using a suitable search algorithm can be reduced complexity time

Ⅳ. Time for space

1. If the system does query high demands on speed, but the storage space demanding, may be considered a time for space

2. String e.g. the intern method, high repetition rate of data is stored in the constant pool, to reuse the same object, saving memory space

  • However, due to the constant pool using HashMap type, if too much data to store, query performance will lead to decline

Ⅴ. Space for time

1. Use the storage space to improve access speed
2. For example MySQL sub-library sub-table

Ⅵ. Tuning Parameters

1. According to business scenarios, a reasonable set JVM memory space and GC algorithm
2. In addition, a reasonable set kernel parameters Web container thread pool size and the Linux operating system

Fourth, the fallback strategy


1. Performance optimization strategies, mainly in order to improve system performance, and fallback strategies, mainly to ensure the stability of the system

2. limiting

  • An inlet to the system maximum access is provided, with reference to performance tests bottom interface TPS
  • At the same time adopt measures fuse friendly return request was not successful

3. Intelligent lateral expansion

  • When the traffic exceeds a certain threshold value, the system can automatically lateral expansion according to the requirements

4. ahead of expansion

  • Commonly used in highly concurrent systems, such as transiently snapped
  • At this time, smart large lateral expansion can not satisfy the request at the instant of

5.Kubernetes can achieve intelligent lateral expansion and advance expansion Docker Service

V. Summary


Detailed architect Ali P8 Java performance tuning strategy

Written in the last


Detailed architect Ali P8 Java performance tuning strategy

Guess you like

Origin blog.51cto.com/14409778/2412948