当前位置:网站首页>(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
2022-07-04 14:30:00 【Cute Xiaoxin @ Yuanjie】
List of articles
- @[toc]
- 1. When do I start to get involved in tuning
- 2. Basic steps and Strategies of performance tuning
- 3. The common performance pit of strings
- 3.4 String.intern Case study : Memory effect after optimization
- 5. java serialize : Native serialization
- 6 NIO principle
- 7.HashMap Blood cases and ConcurrentHashMap The correct use of
List of articles
- @[toc]
- 1. When do I start to get involved in tuning
- 2. Basic steps and Strategies of performance tuning
- 3. The common performance pit of strings
- 3.4 String.intern Case study : Memory effect after optimization
- 5. java serialize : Native serialization
- 6 NIO principle
- 7.HashMap Blood cases and ConcurrentHashMap The correct use of
Performance issues , On HeapDump Performance community !
1. When do I start to get involved in tuning
· The initial stage of project development , Too concerned about performance optimization , Instead, it will make us tired of wasting energy , Not only can it not bring great improvement to the system performance , It will also affect the development progress , Even get the opposite effect , Bring new problems to the system
We only need to consider the basic scenario programming performance problems at the code level ︰ Reduce disk I/О operation 、 Reduce the use of contention locks and handle external service calls carefully
· After development , Generally, the system will be tested . Product managers usually provide online expected data , We conduct pressure test on the reference platform provided , Through performance analysis 、 Statistical tools to count performance indicators , See if it's within expectations .
· After the project goes online , We need to consider the actual situation online , According to the monitoring indicators and statistical logs , To observe system performance problems , Find the problem , Fix the problem . Performance concerns core dimensions
CPU、 Memory 、 disk I/O、 The Internet 、 response time 、 throughput TPS、QPS
2. Basic steps and Strategies of performance tuning
Give priority to ensuring that the program is available , Then repair, troubleshooting and tuning
3. The common performance pit of strings
String、StringBuffer、StringBuilder、intern
Java9 In the program , Most strings only contain characters such as alphanumeric characters , Use Latin-1 code , One character takes up one Byte. Use Char, One Char It takes two hours Byte, It takes up twice as much memory
6 -> 7/8 Improper operation by developers may lead to error in offset statistics , Cause stack overflow . So cancel offset,count Variable
7/8 -> 9 Characters are generally alphabetic , Performance considerations use byte[]
3.1 Source code analysis StringBuffer、StringBuilder performance
StringBuffer Thread safety , But a lot of Synchronized lock .
StringBuilder It is suitable for the scenario of non competitive character resources in the concurrent environment : For example, common tool class methods .
3.2 String、StringBuffer、StringBuilder Performance pressure test
3.3 String.intern The magic of
Twitter Every time the status of a message is released , Will generate an address message . at that time Twitter Size of users , Server needs 32G To store address information . Later call String.intern, Memory becomes hundreds of megabytes
intern Method : Query whether the current string exists from the string constant pool , If it does not exist, put the current string into the constant pool
intern Method : Query whether the current string exists from the string constant pool , If it does not exist, put the current string into the constant pool
intern Method : Query whether the current string exists from the string constant pool , If it does not exist, put the current string into the constant pool
jdk6: The constant pool of strings is on the heap Perm District
JDK7、JDK8: String constant pool already from Perm Move the area to normal Java Heap Regional .Perm The area is too small is a major reason . Often encountered OOM situation .JDK8 It has been cancelled directly Perm Area , Create a new meta region MetaSpace
3.4 String.intern Case study : Memory effect after optimization
4 Regular expression pit
use NFA Automata implement more complex regular expressions , In the process of matching, it often causes backtracking problem . A lot of backtracking takes up for a long time CPU, This leads to system performance overhead
Greedy mode (Greedy)
seeing the name of a thing one thinks of its function , It's in quantity matching , If used alone +、?、* or [min.max] Equivalent words , Regular expressions match as much as possible . For example, the previous example : text= “abbc”regex= “ab[ 1 ,3]c” In greedy mode ,NFA The automaton reads the maximum matching range , Match 3 individual b character . The match failed once , It caused a retrospective . If the match turns out to be “abbbc”, It will match
Exclusive mode (Possessive)
Exclusive mode will match more content as much as possible ; The difference is , In exclusive mode , Failure to match will end the match , There will be no backtracking problem . Previous examples , Add a... After the character “+”, Open exclusive mode .
text=“abbc”regex= “"ab[1,3]+bc The result is a mismatch . End match , There will be no backtracking problem
Previous cases are suitable for exclusive mode . Summarize regular expression skills
Use less greedy mode , Multi use exclusive mode and greedy mode will cause backtracking problems , We can use exclusive mode to avoid backtracking 2. Reduce branch selection types “(X|Y|Z)” Regular expressions that are used in this way can degrade performance , When we develop, we should try to reduce the use. If we must use , There are several ways to optimize :
First , Put the more common options in the front , So that they can be matched quickly ;
secondly , We can try to extract common patterns , for example , take “(abcd|abef)” Replace with “ab(cd|ef)"
5. java serialize : Native serialization
Java Provides a serialization mechanism , This mechanism can serialize an object into binary form ( Byte array )
Used to write to disk or output to the network , It can also read byte arrays from the network or disk , Anti serialization into objects , Use... In the program
6 NIO principle
An asynchronous non blocking I/O Model , It's also I/O The foundation of multiplexing , It has been applied to large application servers more and more , To solve the problem of high concurrency and a large number of connections 、I/O The effective way to deal with problems comes from Linux epoll Communication model
6.1 NIO Concurrent IO scene
6.2 NIO Under what circumstances can not use ?
Data communication is very frequent Don't suggest
, There will be more context switches .
Suitable for use NIO Of :
Long connection time , High concurrency , Communication is not very frequent
7.HashMap Blood cases and ConcurrentHashMap The correct use of
HashMap The cause of the dead cycle is one : Map It's expanding 、 Multithreading Put operation
Thread safety scheme :ConcurrentHashMap
· avoid HashMap The problem of concurrent reading and writing dirty data
·JDK 1.7 ConcurrentHashmap Sectional lock , performance Synchronized Too much
·JDK1.8 Use Synchronized and CAS、Volatile、 The combination of red and black trees , Replace distributed locks
边栏推荐
- The game goes to sea and operates globally
- DDD application and practice of domestic hotel transactions -- Code
- 聊聊保证线程安全的 10 个小技巧
- vscode 常用插件汇总
- Use of tiledlayout function in MATLAB
- AI and Life Sciences
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
- 架构方面的进步
- LifeCycle
- Respect others' behavior
猜你喜欢
Chapter 17 process memory
Ruiji takeout notes
去除重复字母[贪心+单调栈(用数组+len来维持单调序列)]
leetcode:6110. The number of incremental paths in the grid graph [DFS + cache]
Practical puzzle solving | how to extract irregular ROI regions in opencv
flink sql-client. SH tutorial
NowCoder 反转链表
Supprimer les lettres dupliquées [avidité + pile monotone (maintenir la séquence monotone avec un tableau + Len)]
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
Count the running time of PHP program and set the maximum running time of PHP
随机推荐
Detailed index of MySQL
Data Lake (13): spark and iceberg integrate DDL operations
Vscode common plug-ins summary
Use of tiledlayout function in MATLAB
2022 game going to sea practical release strategy
电商系统中红包活动设计
聊聊保证线程安全的 10 个小技巧
一种架构来完成所有任务—Transformer架构正在以一己之力统一AI江湖
ML之shap:基于boston波士顿房价回归预测数据集利用shap值对XGBoost模型实现可解释性案例
Rich text editing: wangeditor tutorial
R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
Talk about 10 tips to ensure thread safety
Count the running time of PHP program and set the maximum running time of PHP
AI与生命科学
富文本编辑:wangEditor使用教程
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)
Data center concept
Transplant tinyplay for imx6q development board QT system
Redis daily notes
docker-compose公网部署redis哨兵模式