20. Linux性能监测工具-内存使用
vmstat
Field Description
Swapd The amount of virtual memory in KB currently in use. As free memory reaches low thresholds, more data
is paged to the swap device. 当前虚拟内存使用的总额(单位:KB).空闲内存达到最低的阀值时,更多的
数据被转换成页到交换设备中.
Free The amount of physical RAM in kilobytes currently available to running applications. 当前内存中可用空
间字节数.
The amount of physical memory in kilobytes in the buffer cache as a result of read() and write()
Buff
operations. 当前内存中用于read()和write()操作的缓冲区中缓存字节数
The amount of physical memory in kilobytes mapped into process address space. 当前内存中映射到进
Cache
程地址空间字节数
so The amount of data in kilobytes written to the swap disk. 写入交换空间的字节数总额
The amount of data in kilobytes written from the swap disk back into RAM. 从交换空间写回内存的字节
si
数总额
The amount of disk blocks paged out from the RAM to the filesystem or swap device. 磁盘块页面从内存
bo
到文件或交换设备的总额
The amount of disk blocks paged into RAM from the filesystem or swap device. 磁盘块页面从文件或交
bi
换设备到内存的总额
30. Linux性能监测工具-network
sar -n DEV 查看网络流量
rxpck/s Total number of packets received per second.
txpck/s Total number of packets transmitted per second.
rxbyt/s Total number of bytes received per second.
txbyt/s Total number of bytes transmitted per second.
36. JVM 堆结构
•Young Generation :Eden where new objects get Instantiated
2 Survivor Spaces to hold live objects during minor GC
•Old Generation: Objects that are longer-lived are eventually
promoted or tenured, to the old generation
Permanent Generation: VM and Java class metadata as well
as interned Strings and class static variables
37. jvm gc
Minor garbage collection illustration
•One survivor space is always empty, Serves as destination for minor
collections。
•At the end of the minor garbage collection, the two survivor spaces swap
roles
•The eden is entirely empty; only one survivor space is in use; and the
occupancy of the old generation has grown slightly
•Major collections occur when the tenured space fills up ,Major collections
free up Eden and both survivor spaces
40. Selecting a Collector
If the application has a small data set (up to approximately
100MB), then
select the serial collector with -XX:+UseSerialGC.
If the application will be run on a single processor and there
are no pause time requirements, then
let the VM select the collector, or
select the serial collector with -XX:+UseSerialGC.
41. Selecting a Collector
If (a) peak application performance is the first priority and (b)
there are no pause time requirements or pauses of one
second or longer are acceptable, then
let the VM select the collector, or
select the parallel collector with -XX:+UseParallelGC and
(optionally) enable parallel compaction with -
XX:+UseParallelOldGC.
If response time is more important than overall throughput
and garbage collection pauses must be kept shorter than
approximately one second, then
43. jvm主要参数
Behavioral options change the basic behavior of the VM.
Performance tuning options are knobs which can be used to tune VM
performance.
Debugging options generally enable tracing, printing, or output of VM
information.
45. Heap Size Starting Point
• From the GC log you will get
Approximation of the Live Data Size (LDS)
It is the heap occupancy after each full GC
Approximation of max perm gen size
It is the perm gen occupancy after each full GC
GC log example:
170.517: [Full GC
[PSYoungGen: 10128K->0K(163392K)]
[ParOldGen: 348898K->161378K(350208K)]
359026K->161378K(513600K)
46. Initial Heap Configuration
• You can now make an informed decision on choosing a
reasonable heap size
Rule of thumb
Set -Xms and -Xmx to 3x to 4x LDS
Set both -XX:PermSize and -XX:MaxPermSize to around
1.2x to 1.5x the max perm gen size
• Set the generation sizes accordingly
Rule of thumb
Young gen should be around 1x to 1.5x LDS
Old gen should be around 2x to 3x LDS
e.g., young gen should be around 1/3-1/4 of the heap
47. JVM调优建议
• You should try to maximize the number of objects
reclaimed in the young generation
This is probably the most important piece of
advice when sizing a heap and/or tuning the
young generation
• Your application's memory footprint should not
exceed the available physical memory
This is probably the second most important piece
of advice when sizing a heap
48. JVM调优建议
• Applications with emphasis on performance tend
to set -Xms and -Xmx to the same value
When -Xms != -Xmx, heap growth or shrinking
requires a Full GC
• Applications with emphasis on performance
almost always set -XX:PermSize and -
XX:MaxPermSize to the same value
Growing or shrinking the permanent generation
requires a Full GC too
49. JVM调优建议
• Try to retain as many objects as possible in the
survivor spaces so that they can be reclaimed in
the young generation
Less promotion into the old generation
Less frequent old GCs
• But also, try not to unnecessarily copy very long
lived objects between the survivors
Unnecessary overhead on minor GCs
• Not always easy to find the perfect balance
50. JVM调优建议
1. Higher tenuring threshold → promotes fewer
objects
Possibly (but not necessarily) longer young GC times
Increases the number of objects reclaimed in the young gen
Better overall efficiency
2. Lower tenuring threshold → promotes more objects
Possibly (but not necessarily) shorter young GC times
More load / pressure on the old gen
More frequent old GCs
Could make fragmentation more severe
51. Java crash
• A crash, or fatal error, causes a process to terminate
abnormally。
• Crash后会产生 hs_err_pid开头的文件,(有时候可能来不及)
• 可能的原因:
– Java虚拟机自身的Bug;
– 系统的库文件、API或第三方的库文件造成;
– 系统资源的短缺
52. Java crash文件格式
Crash 文件由以下几部分组成:
• A header that provides a brief description of the crash.
• A section with thread information.
– Thread Information
– Signal Information
– Register Context
– Machine Instructions
– Thread Stack
– Further Details
• A section with process information.
– Thread List
– VMState
– Mutexes and Monitors
– Heap Summary
– MemoryMap
63. java性能监测工具
Java VisualVM: a tool that provides a visual interface for viewing detailed
information about Java technology-based applications (Java applications)
while they are running on a Java Virtual Machine (JVM)