JVM 性能优化命令

jps

 jps 用来列出host 上的java 进程, 找出有哪些java 进程, 进程id , 启动参数

jps -l 简洁列表
jps -v 详细参数列表

jstack

用来查看当前运行的java 进程 线程栈信息
jstack -l > stackdump.log  

jmap

 jmap dump 堆内存, 查看堆里的详细信息, 堆里实时对象统计信息等
 
 D:\test>jmap -heap 15440
Attaching to process ID 15440, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.171-b11

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 0
   MaxHeapFreeRatio         = 100
   MaxHeapSize              = 268435456 (256.0MB)
   NewSize                  = 8388608 (8.0MB)
   MaxNewSize               = 89128960 (85.0MB)
   OldSize                  = 16777216 (16.0MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 72351744 (69.0MB)
   used     = 66692672 (63.60308837890625MB)
   free     = 5659072 (5.39691162109375MB)
   92.1783889549366% used
From Space:
   capacity = 524288 (0.5MB)
   used     = 425984 (0.40625MB)
   free     = 98304 (0.09375MB)
   81.25% used
To Space:
   capacity = 6815744 (6.5MB)
   used     = 0 (0.0MB)
   free     = 6815744 (6.5MB)
   0.0% used
PS Old Generation
   capacity = 30932992 (29.5MB)
   used     = 19421808 (18.522079467773438MB)
   free     = 11511184 (10.977920532226562MB)
   62.78671006024894% used

19653 interned Strings occupying 1722984 bytes.

jmap -histo:live 15440
 num     #instances         #bytes  class name
	----------------------------------------------
	   1:         41422        3586176  [C
	   2:          4556        2460104  [I
	   3:         40541         972984  java.lang.String
	   4:          7236         818096  java.lang.Class
	   5:         10047         595864  [Ljava.lang.Object;
	   6:         17366         555712  java.util.HashMap$Node
	   7:          3592         327008  [Ljava.util.HashMap$Node;
	   8:          9633         308256  java.util.Hashtable$Entry
	   9:           611         297928  [B
	  10:         10020         240480  java.lang.Double
	  11:           187         234624  [J
	  12:          4350         208800  java.util.HashMap
	  13:          3350         107200  java.util.concurrent.ConcurrentHashMap$Node
	  14:           828         105352  [Ljava.util.Hashtable$Entry;

jmap -dump:live,format=b,file=heapdump.hprof 15440
	Dumping heap to D:\test\heapdump.hprof ...
	Heap dump file created

jstat

D:\test>jstat -options
		-class
		-compiler
		-gc
		-gccapacity
		-gccause
		-gcmetacapacity
		-gcnew
		-gcnewcapacity
		-gcold
		-gcoldcapacity
		-gcutil
		-printcompilation

D:\test>jstat -help
	Usage: jstat -help|-options
	       jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
   #显示当前进程 gc 情况, 每秒打印一次,打印5次
D:\test>jstat -gcutil 15440 1000 10
  S0     S1     E      O      M     CCS    YGC     YGCT    FGC    FGCT     GCT
  0.00  75.96  18.28  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  20.39  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  20.61  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  21.94  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  22.12  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  22.56  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  23.24  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  24.67  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  24.86  37.00  93.84  87.91     29    0.324    10    0.860    1.184
  0.00  75.96  25.68  37.00  93.84  87.91     29    0.324    10    0.860    1.184
	
	#显示当前进程class load 情况, 每秒打印一次,打印5次
D:\test>jstat -class 15440 1000 5
Loaded  Bytes  Unloaded  Bytes     Time
  6784 14637.1       44    63.3       5.31
  6784 14637.1       44    63.3       5.31
  6784 14637.1       44    63.3       5.31
  6784 14637.1       44    63.3       5.31
  6784 14637.1       44    63.3       5.31

jinfo

   查看java 进程的jvm 参数
   D:\test>jinfo -flags 15440
	Attaching to process ID 15440, please wait...
	Debugger attached successfully.
	Server compiler detected.
	JVM version is 25.171-b11
	Non-default VM flags: -XX:CICompilerCount=3 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=null -XX:+IgnoreUnrecognized
	VMOptions -XX:InitialHeapSize=25165824 -XX:MaxHeapSize=268435456 -XX:MaxNewSize=89128960 -XX:MinHeapDeltaBytes=524288 -XX
	:NewSize=8388608 -XX:OldSize=16777216 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeSta
	mps -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
	Command line:  -Xms24m -Xmx256m -Dsun.jvmstat.perdata.syncWaitMs=10000 -Dsun.java2d.noddraw=true -Dsun.java2d.d3d=false -
	Dnetbeans.keyring.no.master=true -Dplugin.manager.install.global=false --add-exports=java.desktop/sun.awt=ALL-UNNAMED --a
	dd-exports=jdk.jvmstat/sun.jvmstat.monitor.event=ALL-UNNAMED --add-exports=jdk.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --
	add-exports=java.desktop/sun.swing=ALL-UNNAMED --add-exports=jdk.attach/sun.tools.attach=ALL-UNNAMED --add-modules=java.a
	ctivation -XX:+IgnoreUnrecognizedVMOptions -Djdk.home=D:\tools\Java\jdk1.8.0_171 -Dnetbeans.home=D:\tools\Java\jdk1.8.0_1
	71\lib\visualvm\platform -Dnetbeans.user=C:\Users\nick.li\AppData\Roaming\VisualVM\8u131 -Dnetbeans.default_userdir_root=
	ng\VisualVM\8u131\var\log\heapdump.hprof -Dsun.awt.keepWorkingSetOnMinimize=true -Dnetbeans.dirs=D:\tools\Java\jdk1.8.0_1
	71\lib\visualvm\visualvm;D:\tools\Java\jdk1.8.0_171\lib\visualvm\profiler

linux 性能调优命令

top

  显示进程列表, 线程列表, 资源利用情况

vmstate

	cpu/内存/io 在操作系统级别的统计信息

iostate

操作系统io 的统计信息

k8s 命令

kubectl

kubectl -n namespace get pods

显示pod 列表		

kubectl -n namespace get services

显示service 列表

kubectl -n namespace get deployments

显示deployment 列表

kubectl -n namespace edit deployment deployment id

显示deployment 列表

kubectl -n namespace exec -it podid sh

进入pod

kubectl -n namespace logs -h podid | grep xxxx

 	查看并查找pod 的标准输出

jvisualvm

 连接方式: jmx,  jstatd
  如果能上网,可以下载Visual GC 插件,看GC 详细信息

JVM 参数

例子: -Xmx5m -Xms2m -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -Xss1m 
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐