性能监控/优化系列——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. a 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问题。基于链表的数据结构不会有此性能问题。

猜你喜欢

转载自chinese-darren.iteye.com/blog/1752493