JVM optimization:修订间差异

来自WHY42
(Riguz移动页面JVM memory analysisJVM optimization,不留重定向)
第1行: 第1行:
=Linux system tool =
=Linux system tool =
== top ==


<syntaxhighlight lang="bash">
top - 10:55:37 up 1234 days, 20:33,  1 user,  load average: 26.61, 31.80, 35.25
Tasks: 485 total,  2 running, 483 sleeping,  0 stopped,  0 zombie
%Cpu(s): 82.8 us,  9.4 sy,  0.0 ni,  5.6 id,  0.0 wa,  0.0 hi,  2.2 si,  0.0 st
KiB Mem : 26359952+total, 10300115+free, 79046432 used, 81551928 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 17903020+avail Mem
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM    TIME+ COMMAND                                                               
35253 work      20  0  27.3g  10.6g  11532 S 817.5  4.2 795248:54 java                                                                 
38200 work      20  0  27.2g  10.4g  11480 S 774.6  4.1 782100:51 java                                                                 
33196 work      20  0  27.2g  10.5g  11496 S 663.0  4.2 767660:17 java                                                                 
38110 work      20  0  27.2g  10.4g  11496 S 368.3  4.2 717635:28 java                                                                 
38489 work      20  0  27.2g  10.5g  11516 S 286.1  4.2 797625:38 java                                                                 
198487 work      20  0  134384  18352    888 R  64.0  0.0  0:03.06 netstat                                                               
120786 work      20  0  21.7g  4.8g  7032 S  15.5  1.9 410952:23 java                                                                 
120732 work      20  0  21.7g  4.8g  6996 S  11.2  1.9 346910:48 java                                                                 
120726 work      20  0  21.7g  4.8g  6980 S  10.2  1.9 355160:19 java                                                                 
120838 work      20  0  21.7g  4.9g  7244 S  5.6  1.9 407095:04 java                                                                 
198488 work      20  0  113540    976    820 S  2.3  0.0  0:00.13 awk                                                                   
197696 root      20  0      0      0      0 S  0.7  0.0  0:00.34 kworker/15:2                                                         
    10 root      20  0      0      0      0 S  0.3  0.0  10342:55 rcu_sched                                                             
  161 root      20  0      0      0      0 S  0.3  0.0 947:20.63 ksoftirqd/30                                                         
18515 root      20  0  573816  14272  2968 S  0.3  0.0 250:14.40 tuned                                                                 
</syntaxhighlight>
== View threads==
== View threads==


=查看Java进程=
=查看Java进程=

2024年4月15日 (一) 02:55的版本

Linux system tool

top

top - 10:55:37 up 1234 days, 20:33,  1 user,  load average: 26.61, 31.80, 35.25
Tasks: 485 total,   2 running, 483 sleeping,   0 stopped,   0 zombie
%Cpu(s): 82.8 us,  9.4 sy,  0.0 ni,  5.6 id,  0.0 wa,  0.0 hi,  2.2 si,  0.0 st
KiB Mem : 26359952+total, 10300115+free, 79046432 used, 81551928 buff/cache
KiB Swap:        0 total,        0 free,        0 used. 17903020+avail Mem 

   PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                
 35253 work      20   0   27.3g  10.6g  11532 S 817.5  4.2 795248:54 java                                                                   
 38200 work      20   0   27.2g  10.4g  11480 S 774.6  4.1 782100:51 java                                                                   
 33196 work      20   0   27.2g  10.5g  11496 S 663.0  4.2 767660:17 java                                                                   
 38110 work      20   0   27.2g  10.4g  11496 S 368.3  4.2 717635:28 java                                                                   
 38489 work      20   0   27.2g  10.5g  11516 S 286.1  4.2 797625:38 java                                                                   
198487 work      20   0  134384  18352    888 R  64.0  0.0   0:03.06 netstat                                                                
120786 work      20   0   21.7g   4.8g   7032 S  15.5  1.9 410952:23 java                                                                   
120732 work      20   0   21.7g   4.8g   6996 S  11.2  1.9 346910:48 java                                                                   
120726 work      20   0   21.7g   4.8g   6980 S  10.2  1.9 355160:19 java                                                                   
120838 work      20   0   21.7g   4.9g   7244 S   5.6  1.9 407095:04 java                                                                   
198488 work      20   0  113540    976    820 S   2.3  0.0   0:00.13 awk                                                                    
197696 root      20   0       0      0      0 S   0.7  0.0   0:00.34 kworker/15:2                                                           
    10 root      20   0       0      0      0 S   0.3  0.0  10342:55 rcu_sched                                                              
   161 root      20   0       0      0      0 S   0.3  0.0 947:20.63 ksoftirqd/30                                                           
 18515 root      20   0  573816  14272   2968 S   0.3  0.0 250:14.40 tuned

View threads

查看Java进程

jps
top #shift +m按内存排序


有介绍说可以通过PS命令查看进程的线程占用情况,但这里没能提供更多的信息

ps -mp 31560 -o THREAD,tid,time,rss,size,%mem

jmap命令

jmap [option] <pid>
    <none>               to print same info as Solaris pmap
    -heap                to print java heap summary
    -histo[:live]        to print histogram of java object heap; if the "live"
                         suboption is specified, only count live objects
    -permstat            to print permanent generation statistics
...

其中,jmap -histo:live [pid] 可以查看当前Java进程创建的活跃对象数目和占用内存大小。

jmap -dump:live,format=b,file=xxx.xxx [pid] 则可以将当前Java进程的内存占用情况导出来,方便用专门的内存分析工具(例如:MAT)来分析。

jmap -histo:live 31560 | head -n 10

其中:

  1. [C is a char[]
  2. [S is a short[]
  3. [I is a int[]
  4. [B is a byte[]
  5. [[I is a int[][]
  1. 参考文章 [[1]]