Performance Tuning 02

Hello, I'm Liu Chao.
Last lecture, I introduce the importance of tuning the time, he referred to the performance test. The face of increasingly complex systems, to develop a reasonable performance testing, performance bottlenecks can be found in advance, and then targeted to develop tuning strategies. It boils down to this "test - Analysis - tuning" three steps.
Today, we are on this basis, a good chat, "how to make the system tuning strategy."

Performance Test Raiders

Performance testing is to find performance bottlenecks early to ensure the necessary measures to stabilize the system performance. Let me give you introduce two commonly used test methods to help you test the performance of the system from the point to the ground surface.

1. Micro benchmark

Micro-benchmarks can be precisely positioned to a module of a method or performance problems, particularly suitable for a performance comparison function block or a method in different implementations. For example, a comparative method used to achieve synchronization and non-synchronization performance achieved.

2. Macro benchmark

Acer is a comprehensive benchmark tests, need to take into account the test environment, test scenarios and test objectives.
First look at the test environment, we need to simulate real-world line.
Then look at test scenarios. We need to determine when testing an interface, whether there are other service interfaces while also running in parallel, creating interference. If so, please pay attention, because once you ignore this interference, the test results will be deviation.
Finally, look at the test target. Our goal is to have performance tests, where the system can be measured by whether the target throughput and response time. Non-compliance, it is optimized; compliance, continue to increase the number of concurrent tests, bottom TPS (transactions per second maximum) interface, to do so, can insight into the performance of the interface. In addition to test interface throughput and response time, we also need to interface testing cycle can lead to performance problems, observe the various changes server CPU, memory and I / O usage.
Detailed These are the two test methods. It is worth noting that there is interference factor performance testing, test results will be inaccurate. So, when we do performance testing, but also pay attention to some problems.

1. warm-up problem

When we do performance testing, our system will run faster and faster, faster than the speed of access to the back of our first visit to the faster times. This is how it happened?
After the Java programming language and environment, .java files compiled into .class files, the machine still can not run directly .class file byte code interpreter will need to convert bytecode to native machine code to run. To save memory and execution efficiency, while the code is executed first, the first to explain the implementation of interpreter code.
With the increase in the number of times code is executed, when the virtual machine code block found a method or function very frequently, these codes will be recognized as a hotspot codes (Hot Spot Code). In order to improve the efficiency of the hot code at runtime, the virtual machine will by time compiler (JIT compiler, just-in-time compiler) to compile the code into machine code associated with the native platform, and all levels of optimization and then stored in memory, when the code after each run, to obtain directly from memory.
So in the beginning stages of operation, the virtual machine takes a long time to fully optimize the code behind the highest performance can be performed.
This is the warm-up process, if during the performance tests, warm-up time is too long, it will lead to the first access speed is too slow, you can consider optimization, and then tested.

2. Performance Test Results unstable

We found that when doing performance tests each processed data sets are the same, but there are differences in the test results. This is because the test, along with the many uncertainties, such as the impact of different machines other processes, network fluctuations and JVM garbage collection every stage and so on.
We can pass a number of tests, test results are averaged, or a statistical graph, as long as our average is within a reasonable range, but volatility is not large, in this case, the performance test is passed.

3. Multi-JVM under the influence case

If our server has multiple Java application services, deployed in different Tomcat, which means that our servers have multiple 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 are good or very good tune your results, but in the case of a machine multiple JVM's might not be. So we should try to avoid a machine online environment to deploy multiple JVM.

Rational analysis, strategy formulation tuning

Here I will analyze and tune the "three-step" in the combined stresses.
After the completion of our performance testing, performance testing needs to output a report, we help analyze system performance testing. Wherein the test results need to include average, maximum and minimum test interface throughput, response time, CPU, memory, I / O, network IO utilization, the JVM frequency of GC server.
By observing these standard tuning, performance bottlenecks can be found, we'll find the problem by analyzing bottom-up approach. First, from the operating system level, view the system's CPU, memory, I / O, network utilization if there is an abnormality, then look for abnormal log command, and finally by analyzing the log to find the cause of a bottleneck; also available from the Java application JVM level, see the JVM garbage collection frequency and memory allocation if there is an abnormality, log analysis, to find the cause of a bottleneck.
If the system JVM level and are not unusual happens, we can see whether there are application service layer business performance bottlenecks, such as the Java programming problem, reading and writing data bottlenecks and so on.
Analysis to find the problem is a complex and delicate process, a performance problem may be a cause, or it may be the result of a common cause of several reasons. We find the problem analysis bottom-up approach can be used, and we resolve system performance problems, the top-down level by level optimization can be used. Let me several tuning strategies from the application layer down to the operating system layer to introduce.

1. optimized code

Code in question because the application layer often run out of system resources exposed. For example, we have a piece of code cause a memory overflow, often in the JVM runs out of memory, system memory resources depleted at this time, and will also lead to JVM garbage collection occurs frequently, leading to more than 100% CPU high this time they consume CPU resources system.
There are a number of non-performance issues caused by problems in your code, which is often more difficult to find, need to rely on our experience to optimize. For example, we often use LinkedList set, if the container is used for loop iterates, the reading efficiency is greatly reduced, but the reduction of the efficiency of the system performance parameter is difficult to cause abnormal.
Then there is the experience of the students, will use Iterator (iterators) iteration of the loop the collection, because LinkedList is a linked list to achieve, if you use a for loop to obtain elements at each cycle to obtain elements, will go to traverse a List this will reduce the efficiency of reading.

2. Optimize Design

There are a lot of object-oriented design patterns that can help us optimize the code design business layer and the middleware layer. After optimization, not only streamline the code, but also improve overall performance. For example, Singleton in frequent calls to create objects in the scene, you can create a shared objects, thus reducing the frequently create and destroy objects brought performance consumption.

3. Optimization

Good algorithm can help us greatly improve system performance. For example, in different scenarios, using a suitable algorithm to find the time complexity can be reduced.

4. The time for space

Sometimes the system speed when the query is not very high demand, but demanding of storage space, this time we can use the time to consider for space.
For example, I will speak in the 03 intern Detailed method of the String object, you can be relatively high repetition rate of data sets stored in the constant pool, a repeated use of the same object, which can greatly save memory storage space. However, due to the constant pool using HashMap type of data structure, if we store too much data, query performance will drop. So in this more stringent requirements for storage capacity, and query speed is not required to make a scene, we can be considered for space with time.

The space for time

This method is the use of storage space to improve access speed. Now many MySQL database systems are used, the more common sub-library sub-table is a typical case of using space for time.
Because MySQL single table while storing data more than ten million, read and write performance will be significantly decreased, this time we need a field to table data by Hash value or otherwise split, the system query data, based on the conditions of Hash value judgment find the corresponding table, because the table reduces the amount of data, query performance also improved.

6. Tuning parameters

These are optimized business layer code, in addition, JVM, Web containers, and operating system optimization is also very critical.
According to their own business scenarios, a reasonable set of JVM memory and garbage collection algorithm can improve system performance. For example, if you create a large number of large objects in our business, we can set, these large objects directly into the old era. This reduces the small garbage collection (Minor GC) the young generation occurs frequently, reducing CPU usage time, improve system performance.
Setting up the Web container thread pool and the Linux operating system kernel parameters may also lead to unreasonable system performance bottlenecks and optimize these two parts according to their own business scenarios, you can enhance system performance.

Fallback strategy to ensure system stability

All top performance tuning strategies mentioned are the means to improve system performance, but in the era of rapid development of the Internet, users are rapidly changing the amount of the product, regardless of our system optimization how well, or there will be tolerance limits Therefore, in order to ensure the stability of the system, we also need to use some fallback strategy.

What is the catch-all strategy?

First, the current limit, set a maximum limit access to the portal system. Herein refer to the performance test TPS bottom interface. Fuse while taking measures to return to a friendly request did not succeed.
Second, intelligent lateral expansion. Intelligent lateral expansion ensures that when the traffic exceeds a certain threshold, the system can automatically add laterally on demand service.
Third, ahead of expansion. This method is usually applied to a high concurrent systems, e.g., instantaneous buying business systems. This is because the lateral expansion can not meet the large number of requests happen in an instant, even if successful, buying is over.
At present, many companies use Docker containers to deploy applications. This is because the Docker containers using Kubernetes as a container management system, and Kubernetes can achieve intelligent lateral expansion and advance expansion Docker service.

to sum up

Completion of this talk, you should be aware of the performance testing and tuning up. We again by a diagram to recap today's content.
We will test the performance benchmarks into micro and macro benchmarks, the former can be precisely adjusted preferably small business functional units, which may be combined with internal and external factors, online integrated simulation environment to test the system performance. Combination of two methods may be more three-dimensional test system performance.
The test results can help us develop strategies tuning, tuning methods are many, here it is not a repeat. But there is one thing in common, tuning strategies ever-changing, but the core idea is the same, are from the tuning business tune into the program, and then to system tuning.
Finally, to give you a heads, no need to combine both tuning scene clearly known issues and performance goals, not for tuning and tuning, so as not to introduce new Bug, risks and drawbacks.

Questions

Suppose you are a responsible electricity supplier system, immediately, there on the new line, but also buying activities, then what features you will do micro-benchmarks, which features do macro benchmarks it?
We look forward to seeing your answers in the comments area. You are welcome to click on the "ask a friend to read", today the share content to their friends, inviting him to discuss.
Published 24 original articles · won praise 0 · Views 419

Guess you like

Origin blog.csdn.net/WillliveWillWork/article/details/105242287