jvm参数

2017-12-07  本文已影响0人  吃花生的小猴子
image.png

function start() {
        JAVA_OPTS="$JAVA_OPTS -server
               -Xmx512m
               -Xms256m
               -Xmn256m
               -XX:MetaspaceSize=64m
               -XX:MaxMetaspaceSize=256m
               -Xss256k
               -XX:+ExplicitGCInvokesConcurrent
               -XX:+UseConcMarkSweepGC
               -XX:+UseCMSInitiatingOccupancyOnly
               -XX:CMSInitiatingOccupancyFraction=70
               -XX:-UseBiasedLocking
               -XX:AutoBoxCacheMax=20000
               -XX:MaxTenuringThreshold=6
               -Xloggc:/dev/shm/gc_maila-manager-web.log
               -XX:+PrintGCApplicationStoppedTime
               -XX:+PrintGCDateStamps
               -XX:+PrintGCDetails
               -XX:+PrintCodeCache
               -XX:+UseGCLogFileRotation
               -XX:NumberOfGCLogFiles=2
               -XX:GCLogFileSize=10m
               -XX:+HeapDumpOnOutOfMemoryError
               -XX:HeapDumpPath=/home/admin/logs/ "

        nohup java $JAVA_OPTS -jar   /home/admin/duiba-deploy/maila-manager-web/maila-manager-deploy/build/libs/maila-manager-web.jar --spring.profiles.active=pre --spring.cloud.config.uri=http://configserver.duiba.com.cn > /dev/null &
}


function stop() {
        process=`ps -ef | grep 'maila-manager-web.jar' | grep -v "grep"|grep -v "restart"|grep -v "stop"| wc -l`
        if [[ 0 != $process ]];then
                ps -ef | grep 'maila-manager-web.jar' | grep -v "grep"|grep -v "stop"|grep -v "restart"| awk '{print $2}' | xargs kill -15
        fi
        sleep 10
        if [[ 0 != $process ]];then
                ps -ef | grep 'maila-manager-web.jar' | grep -v "grep"|grep -v "stop"|grep -v "restart"| awk '{print $2}' | xargs kill -9
        fi
}

function restart() {
        stop;
        sleep 1;
        start;
}

function status() {
        ps -ef | grep 'maila-manager-web.jar' | grep -v grep| awk '{print $2}'

}
function help() {
    echo "$0 |start|stop|restart|status|"
}

Xss 栈空间大小。每个线程执行都有其对应的线程栈,用于存放线程执行相关的本地变量,比如方法调用信息等。如果方法调用层次很深(递归),那么应该适当加大此参数配置。此空间的分配来自于操作系统内存,不分配于jvm内存,但却与堆的大小相关。在java中每new一个线程,jvm都是向操作系统请求new一个本地线程,此时操作系统会使用剩余的内存空间来为线程分配内存,而不是使用jvm的内存。这样,当操作系统的可用内存越少,则jvm可用创建的新线程也就越少。比如随着-Xmx的加大,空闲的内存数就更少,那么可以创建的线程也就更少。


-XX:+PrintGC :简要gc信息

0.234: [GC (Allocation Failure)  512K->400K(1536K), 0.0023670 secs]
0.309: [GC (Allocation Failure)  908K->480K(1536K), 0.0115048 secs]
0.415: [GC (Allocation Failure)  992K->548K(1536K), 0.0116569 secs]
0.489: [GC (Allocation Failure)  1060K->548K(1536K), 0.0118201 secs]
0.573: [GC (Allocation Failure)  1044K->788K(1536K), 0.0010058 secs]
0.600: [GC (Allocation Failure) -- 1300K->1512K(1536K), 0.0013921 secs]
0.602: [Full GC (Ergonomics)  1512K->617K(1536K), 0.0264870 secs]
0.629: [Full GC (Ergonomics)  997K->997K(1536K), 0.0278348 secs]
0.657: [Full GC (Allocation Failure)  997K->982K(1536K), 0.0274462 secs]

-XX:+PrintGCDateStamps 记录gc时间

2017-12-11T19:18:12.754-0800: 0.155: [GC (Allocation Failure) [PSYoungGen: 512K->432K(1024K)] 512K->432K(1536K), 0.0010447 secs] [Times: user=0.00 sys=0.00, real=0.00 scs] 

-XX:+PrintGCDetails 输出GC的详细日志

2017-12-11T19:22:03.684-0800: 0.381: [GC (Allocation Failure) [PSYoungGen: 1005K->496K(1024K)] 1127K->834K(1536K), 0.0030809 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
2017-12-11T19:22:03.687-0800: 0.384: [Full GC (Ergonomics) [PSYoungGen: 496K->495K(1024K)] [ParOldGen: 338K->208K(512K)] 834K->703K(1536K), [Metaspace: 3314K->3314K(1056768K)], 0.0067339 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
2017-12-11T19:22:03.695-0800: 0.392: [GC (Allocation Failure) --[PSYoungGen: 1007K->1007K(1024K)] 1215K->1511K(1536K), 0.0013120 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2017-12-11T19:22:03.696-0800: 0.393: [Full GC (Ergonomics) [PSYoungGen: 1007K->114K(1024K)] [ParOldGen: 504K->501K(512K)] 1511K->616K(1536K), [Metaspace: 3315K->3315K(1056768K)], 0.0086868 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
2017-12-11T19:22:03.705-0800: 0.403: [Full GC (Ergonomics) [PSYoungGen: 494K->494K(1024K)] [ParOldGen: 501K->501K(512K)] 996K->996K(1536K), [Metaspace: 3315K->3315K(1056768K)], 0.0104646 secs] [Times: user=0.03 sys=0.00, real=0.01 secs] 
2017-12-11T19:22:03.716-0800: 0.413: [Full GC (Allocation Failure) [PSYoungGen: 494K->494K(1024K)] [ParOldGen: 501K->488K(512K)] 996K->982K(1536K), [Metaspace: 3315K->3315K(1056768K)], 0.0116172 secs] [Times: user=0.02 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 1024K, used 512K [0x00000007bfe80000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 512K, 100% used [0x00000007bfe80000,0x00000007bff00000,0x00000007bff00000)
  from space 512K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007bff80000)
  to   space 512K, 76% used [0x00000007bff80000,0x00000007bffe2330,0x00000007c0000000)
 ParOldGen       total 512K, used 502K [0x00000007bfe00000, 0x00000007bfe80000, 0x00000007bfe80000)
  object space 512K, 98% used [0x00000007bfe00000,0x00000007bfe7d8a0,0x00000007bfe80000)
 Metaspace       used 3348K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 372K, capacity 388K, committed 512K, reserved 1048576K

-XX:+PrintHeapAtGC 每次gc前后都会打印堆信息

{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 1024K, used 512K [0x00000007bfe80000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 512K, 100% used [0x00000007bfe80000,0x00000007bff00000,0x00000007bff00000)
  from space 512K, 0% used [0x00000007bff80000,0x00000007bff80000,0x00000007c0000000)
  to   space 512K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007bff80000)
 ParOldGen       total 512K, used 0K [0x00000007bfe00000, 0x00000007bfe80000, 0x00000007bfe80000)
  object space 512K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bfe80000)
 Metaspace       used 2097K, capacity 4480K, committed 4480K, reserved 1056768K
  class space    used 230K, capacity 384K, committed 384K, reserved 1048576K
2017-12-11T19:24:50.318-0800: 0.258: [GC (Allocation Failure) [PSYoungGen: 512K->400K(1024K)] 512K->400K(1536K), 0.0135751 secs] [Times: user=0.00 sys=0.00, real=0.02 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 1024K, used 400K [0x00000007bfe80000, 0x00000007c0000000, 0x00000007c0000000)
  eden space 512K, 0% used [0x00000007bfe80000,0x00000007bfe80000,0x00000007bff00000)
  from space 512K, 78% used [0x00000007bff00000,0x00000007bff64010,0x00000007bff80000)
  to   space 512K, 0% used [0x00000007bff80000,0x00000007bff80000,0x00000007c0000000)
 ParOldGen       total 512K, used 0K [0x00000007bfe00000, 0x00000007bfe80000, 0x00000007bfe80000)
  object space 512K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bfe80000)
 Metaspace       used 2097K, capacity 4480K, committed 4480K, reserved 1056768K
  class space    used 230K, capacity 384K, committed 384K, reserved 1048576K
}

-XX:+PrintGCTimeStamps 打印系统启动后到gc发生经过了多少时间。如下:0.106秒,0.157秒,0.212秒 发生了3次gc

0.106: [GC (Allocation Failure) [PSYoungGen: 512K->416K(1024K)] 512K->416K(1536K), 0.0094628 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
0.157: [GC (Allocation Failure) [PSYoungGen: 924K->480K(1024K)] 924K->480K(1536K), 0.0006946 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
0.212: [GC (Allocation Failure) [PSYoungGen: 992K->512K(1024K)] 992K->586K(1536K), 0.0027471 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 

-XX:+PrintGCApplicationConcurrentTime 打印应用的执行时间

0.096: [GC (Allocation Failure) [PSYoungGen: 512K->416K(1024K)] 512K->416K(1536K), 0.0018458 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
0.156: Application time: 0.0581703 seconds
0.156: [GC (Allocation Failure) [PSYoungGen: 924K->448K(1024K)] 924K->448K(1536K), 0.0013974 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
0.201: Application time: 0.0428315 seconds

-XX:+PrintGCApplicationStoppedTime 打印gc停顿时间

0.103: [GC (Allocation Failure) [PSYoungGen: 512K->384K(1024K)] 512K->384K(1536K), 0.0007675 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
0.104: Total time for which application threads were stopped: 0.0008867 seconds, Stopping threads took: 0.0000085 seconds

-XX:+PrintReferenceGC 跟踪软,弱,虚和Finallize队列

0.113: [GC (Allocation Failure) 0.115: [SoftReference, 0 refs, 0.0000443 secs]0.115: [WeakReference, 7 refs, 0.0000054 secs]0.115: [FinalReference, 5 refs, 0.0000169 secs]0.115: [PhantomReference, 0 refs, 0 refs, 0.0000041 secs]0.115: [JNI Weak Reference, 0.0000064 secs][PSYoungGen: 512K->416K(1024K)] 512K->416K(1536K), 0.0022235 secs] [Times: user=0.01 sys=0.00, real=0.00 secs] 
0.173: [GC (Allocation Failure) 0.175: [SoftReference, 0 refs, 0.0000713 secs]0.175: [WeakReference, 9 refs, 0.0000195 secs]0.175: [FinalReference, 69 refs, 0.0000802 secs]0.175: [PhantomReference, 0 refs, 0 refs, 0.0000139 secs]0.175: [JNI Weak Reference, 0.0000102 secs][PSYoungGen: 924K->480K(1024K)] 924K->480K(1536K), 0.0024862 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

上一篇下一篇

猜你喜欢

热点阅读