性能监控/优化系列——Java应用Profiling

 1. 常见的内存泄露有adding entries to a Java Collection and never removing them are a common source of memory leaks。

2. 对于IO应用的调优, 为了减低CPU utilization, 一个常用的方法是buffer 输入和输出数据,减少交互次数。
3. 任何一次网络IO的调用最终会导致一个OS的系统调用,会消耗system CPU utilization,因此可以尽量选择NIO的方式
4. Java NIO nonblocking data structures allow for the ability to read or write as much data as possible in a single call to a network I/O (read or write) operation。
5. 在涉及到同步代码时注意: 1. 尽量减少同步代码path的长度; 2. 减少同步数据集合的大小, 像ConcurrentHashMap就是通过分段(segment)来缩小同步集合的范围实现高效同步操作;3. 也要尽量避免在同步块中设置不可控的依赖。
6.Atomic and concurrent data structures并不是万能的,它依赖于CAS操作,在高并发情况下会产生大的性能问题,因此首先要考虑不是选择何种原子数据结构,而是要尽量遵循上面提到的规则。
7. volatile field’s value must be kept in sync across all application threads and CPU caches。为了保持多个CPU中的volatile数据一致,必然涉及到同步操作。如果在多CPU环境下,频繁更新volatile值会出现性能问题。
8. StringBuffer/StringBuiler当空间不足时会resize它的容量大小,这会产生一些性能问题。Eliminating these char[] allocations from resizing improves the performance of this program by saving the CPU instructions needed to perform the new char[] allocation, copying the characters from the old char[] into the new char[]and the CPU instructions required to garbage collect the old discarded char[]。请在构造它们的实例时显示指定大小。
9. ArrayList, Vector, HashMap, and ConcurrentHashMap同样也是基于数组作为底层结构,因此都有上面提到的resize问题。基于链表的数据结构不会有此性能问题。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值