当前位置:网站首页>(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
边栏推荐
- Data warehouse interview question preparation
- The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
- 第十七章 进程内存
- vscode 常用插件汇总
- Leetcode t47: full arrangement II
- Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
- nowcoder重排链表
- Leetcode T47: 全排列II
- scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
- Leetcode T49: 字母异位词分组
猜你喜欢
Count the running time of PHP program and set the maximum running time of PHP
递增的三元子序列[贪心训练]
leetcode:6109. Number of people who know the secret [definition of DP]
RK1126平台OSD的实现支持颜色半透明度多通道支持中文
Real time data warehouse
No servers available for service: xxxx
Pandora IOT development board learning (RT thread) - Experiment 3 button experiment (learning notes)
MySQL之详解索引
Why should Base64 encoding be used for image transmission
Learn kernel 3: use GDB to track the kernel call chain
随机推荐
nowcoder重排链表
Why should Base64 encoding be used for image transmission
游戏出海,全球化运营
尊重他人的行为
关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
Leetcode t47: full arrangement II
vscode 常用插件汇总
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
GCC【6】- 编译的4个阶段
Digi重启XBee-Pro S2C生产,有些差别需要注意
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
10.(地图数据篇)离线地形数据处理(供Cesium使用)
Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
Vscode common plug-ins summary
Test evaluation of software testing
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
Ruiji takeout notes
Detailed explanation of visual studio debugging methods
LiveData
sql优化之explain