当前位置:网站首页>Distributed. Performance optimization
Distributed. Performance optimization
2022-08-11 00:21:00 【idle cat】
性能优化
代码层面
字符串
拼接:for内不使用+,而是StringBuilder(线程不安全)/StringBuffer(线程安全)
分割
split ,StringTokenizer ,indexOf 和 substring ,StringUtils
由高到低的排序为:StringTokenizer > split ,StringUtils.split > indexOf
数组
复制效率
System.arraycopy > clone > Arrays.copyOf > for
集合
设置初始化容量,比如:StringBuilder,ArrayList,HashMap 等
for
使用Collections.EMPTY_LIST/Collections.EMPTY_SET/Collections.EMPTY_MAP,不要return null; 或者 return new ArrayList();
traverse recommendation:for (int i = 0, int length = list.size(); i < length; i++)
forWriting query database statements is prohibited in
Hibernate/Mybatis
锁
减少锁持有时间(尽量缩小锁的范围)
减小锁粒度
使用同步方法块替代同步方法
锁属性 替代 锁对象
锁分离
读写锁ReadWriteLock
根据功能进行分离成读锁和写锁,这样读读不互斥,读写互斥,写写互斥
锁粗化
锁粗化就是告诉我们任何事情都有个度,有些情况下我们反而希望把很多次锁的请求合并成一个请求,以降低短时间内大量锁请求、同步、释放带来的性能损耗.
锁消除
A compiler-level lock optimization
针对JDKSynchronization code in source code,A way to remove locks at compile time
数据库层面
Sql
编写Sql
字段类型
Numeric fields are preferred over character fields
变长字段 优于 定长字段
单表查询
应尽量避免在 where 子句中使用 or 来连接条件,可以考虑使用 union 代替
尽量避免在 where 子句中对字段进行表达式操作和函数操作
Databases only do simple thingsCRUD
in 和 not in 也要慎用.对于连续的数值,能用 between 就不要用 in,exists 代替 in
Replace with specific fields*
连接查询
join
It can quickly reduce the amount of Cartesian product datajoin,The conditions are also to the left first
joinThe condition types are preferably the same,Best built on an index
子查询
杜绝,The query efficiency is very poor,使用join替代
执行计划
Explain
慢SQL处理
索引
防止索引失效
避免在Where中使用!=
避免建立太多的索引
一个表最多7个,Otherwise consider whether it is necessary
Fields with better dispersion are indexed,Indexing on gender makes little sense
索引降低Insert和update效率
建立索引避免全表扫描
比如:createtime,where&orderby Preferably on the index
Database configuration tuning
缓存
CDN
Cache static files near users
静态化技术
客户端缓存
浏览器
内存级别
ehcache
查询级别缓存
mysql&hibernate一级缓存
Inter-Service Caching
redis&memcache&mongodb
前端
Reduce excessive front-end calls
业务层面
Prevent excessive code reuse
性能和容量评估
指标
对象
应用服务器
数据库
缓存
消息队列
服务器层面
Linux
性能监控
top
See where the system load is coming from
Linux w命令
Find out who is currently logged in to the system,以及他们正在执行的程序
mpstat
查看CPU的占用情况
free m
内存分析
iostat
Disk operation activity of the system
tail -f -n 100 最后100行
WebServer
tomcat线程池的配置
JVM
垃圾回收算法选择
JVM参数配置调优
检测
分析
调优
工具
Analysis and evaluation tools
常用命令
jps
jvm进程lvmid,主类类名,main函数参数, jvm参数,jarname etc
jmap
堆占用情况
jhat
堆分析工具,结合jmap使用
jstat
查看堆内存各部分的使用量,以及加载类的数量
hprof
Heap/CPU Profiling Tool
jstack
堆栈跟踪工具
边栏推荐
- YOLOv5的Tricks | 【Trick10】从PyTorch Hub加载YOLOv5
- 【pypdf2】安装、读取和保存、访问页面、获取文本、读写元数据、加密解密
- 8. WEB 开发-静态资源访问
- 【js】获取当前时间的前后n天或前后n个月(时分秒年月日都可)
- Is there a way out in the testing industry if it is purely business testing?
- 时间戳转换为日期格式、获取当前时间戳
- 3d打印出现stl文件物体不是流形,意味着不是水密体...解决办法
- 【C语言】探索数据的存储(整形篇)
- Kunpeng compilation and debugging and basic knowledge of native development tools
- How to do patent mining, the key is to find patent points, in fact, it is not too difficult
猜你喜欢
I caught a 10-year-old Ali test developer, and after talking about it, I made a lot of money...
11. 自定义转换器
nodejs项目连接mysql数据库
YOLOv5的Tricks | 【Trick11】在线模型训练可视化工具wandb(Weights & Biases)
[数据可视化] 图表设计原则
Introduction to Qt (6) - Implementation of the lottery system
Promise in detail
详谈二叉搜索树
Starting a new journey - Mr. Maple Leaf's first blog
10. 接收参数相关注解
随机推荐
LENS CRA和SENSOR CRA匹配问题解析
【考虫 六级英语】语法课笔记
Difference Between Image Recognition and Semantic Segmentation
力扣------使用最小花费爬楼梯
Go项目配置管理神器之viper使用详解
"NIO Cup" 2022 Nioke Summer Multi-School Training Camp 4 ADHK Problem Solving
Which foreign language journals and conferences can be submitted for software engineering/system software/programming language?
Where can I download IEEE papers?
鲲鹏编译调试及原生开发工具基础知识
Analysis of LENS CRA and SENSOR CRA Matching Problems
微信小程序强制更新版本
sqlmap combined with dnslog fast injection
李彦宏拆墙交朋友,大厂“塑料友情”能否帮百度啃下硬骨头?
只会懒汉式和饿汉式 你还不懂单例模式!
微信小程序通过URL Scheme动态的渲染数据
复制带随机指针的链表——LeetCode
10. 接收参数相关注解
报错:Client does not support authentication protocol requested by server; consider upgrading MySQL cli
【C语言】探索数据的存储(整形篇)
How engineers treat open source