First, performance tuning acquaintance

  Preface: "Code not learn to think of tune" feeling often heard such things, thinking to learn about the excellent cut, in order to better tune from the point of view to write high-quality code, then open learning about performance optimization.

Sometimes clearly written procedures properly, the amount of data one up, slow is not an error, which is why? It is in the end how to run? Where time is spent? Think about two-eleven Taobao, smooth year after year, this performance really is to the force!

As a back-end developer, more concerned about the server: the server response time, throughput, etc., are all important performance parameters. Outsize is OOM, SOF up.

One: Performance Overview

Program performance in general there are several aspects of performance:

  • Speed ​​of execution: The program reflects whether to respond promptly and the length of time.
  • Memory allocation: memory allocation is reasonable, whether too much or consume memory leak.
  • Start Time: The program can be run from the normal processing business how long it takes.
  • Load-bearing capacity: When the system pressure is increased, the execution speed of the system, whether the response time ascending curve gentle.

II: Performance Reference Index

index:

  • Execution time: a piece of code to run from the beginning of the end of the time spent.
  • Memory allocation: runtime memory space occupied.
  • CPU Time: CPU-time thread.
  • Disk Throughput: the use of I / O.
  • Network throughput: the use of the network.
  • Response time: response time of the system to a user for certain operations.

1. Barrel Theory

It also known as "short-plate theory", the core is: how much of a bucket filled with water, does not depend on the highest piece of wood, but on the lowest piece.

 

Put on a performance optimization system, if the system has sufficient memory and CPU resources, but if poor I / O performance, the overall performance of the system is determined by the slowest disk I / O speed of the current, rather than the best or CPU RAM.

 

Substantially associated therewith may also involve: disk I / O, network operation, CPU, abnormal, database, lock contention, memory and the like.

2.Amdahl律

Speedup is defined: before optimization after speedup = Processed System / optimization system Processed

Speedup ≤ 1 / (F + (1-F) / N) F: specific gravity must be serialized N: Number of CPU processor

 Three: Tuning level

1. Design Tuning

Overrides all tuning tools often require prior software development. Prior to the development of all, we need to evaluate a variety of possible system problems, and give a reasonable design.

Design Optimization biggest feature is that it can avoid performance issues one of its components, rather than to achieve improvement of the component. Such as: A Component B need to wait for an event to trigger an action. If component A is detected by constantly monitoring cycle event B has occurred, it detects behavior is bound to occupy part of system resources, so developers will inevitably strike a balance between detection frequency and resource consumption. If the test frequency is too low, although reducing resource consumption, but real-time response of the system is reduced.

Code optimizing consideration, it is necessary to optimize the detection method, and to obtain a reasonable detection frequency.

If the optimization level in terms of design, you can use the event notification method will be the behavior of the system upside down. For example, the observer pattern: when an event B occurs, the event notification component A to B, thereby triggering the behavior of component A.

2. Code Tuning

Tuning refers to the code in the software development process, after the completion, maintenance and even improvement and optimization of the program code performs the process.

It involves many encoding techniques, such as the familiar language of open API, flexible use of algorithms, data structures. Such as: HashMap and safety of ConcurrentHashMap, ArrayList and LinkedList of random access performance.

3.JVM Tuning

As we all know, java programs are running on the JVM virtual machine, this aspect is also very important optimization points. Usually carried out in the latter part of software development.

First need to understand the principles of operation of the JVM, mechanism, memory structure, composition, etc. JVM.

Then there JVM parameters: heap size, garbage collection policy, GC parameters, logging configuration information

Four: Database Tuning

1. The application layer is optimized sql statement

Database connection to access aspects; sql optimization tips: as fuzzy query, data structures, indexes involved in the execution engine (mysql)

2. Database optimization

Reasonable table structure, table design, improve efficiency multi-table queries cascade. Sub-library sub-table partitions. And the use of the index.

3. Database software optimization

Shared pool of reasonable size, cache buffers and so on.

Five: Operating System Optimization

Virtual memory, disk block size, the maximum number of file handles and so on.

 

Guess you like

Origin www.cnblogs.com/flyinglion/p/12508014.html