Web Application Server ãåããæã® Java8 èµ·åãªãã·ã§ã³ã®ã¡ã¢
ä¸è¬ç㪠Web Application Server *1 ã Java8 ã§åããã«ããã£ã¦ï¼æè¿æå¹ã«ãã¦ããèµ·åãªãã·ã§ã³ã«ã¤ãã¦ã¡ã¢ï¼
ä½ãééã£ã¦ãããï¼ãããã¯ããã£ã¡ã®æ¹ãè¯ããã¿ãããªã®ãããã°æãã¦ä¸ããï¼
-server
server mode ã§èµ·åããã (æå®ããªã㨠client mode ã«ãªãå¯è½æ§ãããï¼ãã·ã³ã¹ããã¯ã«ãã£ã¦ã¹ã¤ããããï¼)ï¼
-Djava.net.preferIPv4Stack=true
If IPv6 is available on the operating system the underlying native socket will be an IPv6 socket. This allows Java(tm) applications to connect too, and accept connections from, both IPv4 and IPv6 hosts.
If an application has a preference to only use IPv4 sockets then this property can be set to true. The implication is that the application will not be able to communicate with IPv6 hosts.
https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
IPv6 ã使ãã OS ã§ã¯ IPv6 㨠IPv4 両æ¹ã®ãã¹ãã¨æ¥ç¶ã§ãããï¼true ã«ãããã¨ã§ IPv4 ã½ã±ããã ãã使ãããã«ããï¼
-Dnetworkaddress.cache.ttl=0
networkaddress.cache.ttl=0
Specified in java.security to indicate the caching policy for successful name lookups from the name service.. The value is specified as integer to indicate the number of seconds to cache the successful lookup.
A value of -1 indicates "cache forever". The default behavior is to cache forever when a security manager is installed, and to cache for an implementation specific period of time, when a security manager is not installed.
https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
ããã©ã«ãã§ã¯ DNS ã®æåçµæãæªæ¥æ°¸å«ãã£ãã·ã¥ããããã«ãªã£ã¦ãã¦ã¢ã¬ãªã®ã§ï¼0ãè¨å®ãããã¨ã§ãã£ãã·ã¥ããªãããã«ããï¼
[追è¨]
id:astjããã«æãã¦ããã£ããã§ããï¼ãã®ãªãã·ã§ã³ã¯ã»ãã¥ãªãã£ããªã·ã¼ã®ãã -D
ã§ã¯æå¹ã«ãªãã¾ããï¼
ã»ãã¥ãªãã£ã¼ããªã·ã¼ã®ä¸é¨ã§ããããã-D ãªãã·ã§ã³ã System.setProperty() API ã§ã¯è¨å®ããã¾ããããã®ä»£ããããããã®ããããã£ã¼ã¯ JRE ã®ã»ãã¥ãªãã£ã¼ããªã·ã¼ãã¡ã¤ã« lib/security/java.security ã§è¨å®ããã¾ãã
https://docs.oracle.com/javase/jp/7/api/java/net/doc-files/net-properties.html
ãã¿ã¾ãããã¿ã¾ããï¼
-Dnetworkaddress.cache.negative.ttl=0
networkaddress.cache.negative.ttl=0
Specified in java.security to indicate the caching policy for un-successful name lookups from the name service.. The value is specified as integer to indicate the number of seconds to cache the failure for un-successful lookups.
A value of 0 indicates "never cache". A value of -1 indicates "cache forever".
https://docs.oracle.com/javase/8/docs/technotes/guides/net/properties.html
ããã©ã«ãã§ã¯ DNS ã®å¤±æçµæã 10 ç§ãã£ãã·ã¥ããããã«ãªã£ã¦ããï¼0ãã»ãããããã¨ã§ãã£ãã·ã¥ããªãããã«ããï¼
[追è¨]
ä¸ã¨åãçç±ã§-D
ã§ã¯æå¹ã«ãªããªãã®ã§ã»ãã¥ãªãã£ããªã·ã¼ã§è¨å®ãã¦ãã ããï¼ãã¿ã¾ãããã¿ã¾ããï¼
-XX:OnOutOfMemoryError="kill -9 %p"
OutOfMemory ãçºçããæã«å®è¡ããã³ãã³ããè¨å®ã§ããï¼OOM ãèµ·ããã確å®ã«èªæ®ºãã¦ãããå¿
è¦ãããã®ã§ kill ãçºè¡ï¼äºã¨æ¬¡ç¬¬ã«ãã£ã¦ã¯èªåã§ã¢ããªã±ã¼ã·ã§ã³ãåèµ·åããããã«ãã¦ãè¯ããããããªãï¼
Ref: OutOfMemoryErrorが発生したときにきちんとJavaプロセスを殺す - nekop's blog
[追è¨]
@sugarlifeããã«æãã¦ããã ãã¾ãããï¼Java8u92ãã追å ããã-XX:+ExitOnOutOfMemoryError
ãå©ç¨ããã»ããè¯ãããã§ã (XX:OnOutOfMemoryError
ã«æå®ããã³ãã³ããééã£ã¦ãã¦ãã£ããæ»ãªãªãï¼ã¿ãããªãã¹ãåé¿ã§ãã)ï¼
-XX:+OptimizeStringConcat
Optimize String concatenation operations where possible
http://www.oracle.com/technetwork/articles/java/vmoptions-jsp-140102.html
æååé£çµãæé©åãããã¨ã®ã㨠(Java 8 ã§ã¯ããã©ã«ã true ã£ã½ã)ï¼
-verbose:gc
-Xloggc:/var/log/gc/gc.log.`date +%Y%m%d%H%M%S`
gc log ãåãããã«ããï¼ã¾ããããã©ãã«åããã®è¨å®ï¼
log ãã¡ã¤ã«åã®ãããã«æ¥ä»æ
å ±ãä»ä¸ãããã¨ã§logãä¸æ¸ããããã®ãé²ãã§ããï¼
-XX:+UseGCLogFileRotation
gc log ã1ã¤ã®ãã¡ã¤ã«ã«å»¶ã
åãç¶ããã®ã§ã¯ãªãï¼ãã°ãã¼ãã¼ã·ã§ã³ãæå¹ã«ããï¼
å¾è¿°ã® XX:NumberOfGCLogFiles 㨠XX:GCLogFileSize ã«é¢ä¿ããã
-XX:NumberOfGCLogFiles=5
ãã°ãã¼ãã¼ã·ã§ã³ãããã¨ãã«ï¼æ大ä½åã®ãã°ãã¡ã¤ã«ã§ãã¼ãã¼ã·ã§ã³ããããã®è¨å®ï¼æ°å (ãã¡ã¤ã«åæ°) ã¯ä»»æï¼
-XX:GCLogFileSize=1024MB
gc log 1åãããã®æ大容é ï¼å®¹éã¯ä»»æï¼
-Xms 2G
ãã¼ãé åã®åæå¤ï¼å¤ã«ã¤ãã¦ã¯åã¢ããªã±ã¼ã·ã§ã³ãã¨ã«ãã¥ã¼ãã³ã°ã®ä½å°ãããï¼
-Xmx 2G
ãã¼ãé åã®æ大å¤ï¼å¤ã«ã¤ãã¦ã¯åã¢ããªã±ã¼ã·ã§ã³ãã¨ã«ãã¥ã¼ãã³ã°ã®ä½å°ãããï¼
-Xmn 512m
New ä¸ä»£é åãµã¤ãºï¼å¤ã«ã¤ãã¦ã¯åã¢ããªã±ã¼ã·ã§ã³ãã¨ã«ãã¥ã¼ãã³ã°ã®ä½å°ãããï¼
-Xss 256K
ã¹ã¬ããã¹ã¿ãã¯ãµã¤ãºï¼å¤ã«ã¤ãã¦ã¯åã¢ããªã±ã¼ã·ã§ã³ãã¨ã«ãã¥ã¼ãã³ã°ã®ä½å°ãããï¼
-XX:MaxMetaspaceSize=128M
!!! ãããã£ã¡ãéè¦ !!!
Java 8以éã ã¨ï¼ãã¤ã¦ã®ã-XX:MaxPermSizeãã®ä»£ããã«è¨å®ãã¦ããå¿
è¦ãããï¼
Permanent é åã¯æ大容éãæéã ã£ãã®ã«å¯¾ãï¼Java 8 以éã® Metaspace é åã¯ã¡ã¢ãªã®è¨±ãéãã¢ãªã¢ãªæ¶è²»ã§ãã¦ãã¾ãã®ã§ï¼æ大容éãæå®ãã¦ãã£ãããããã¨ã§å®å
¨å´ã«åãã¦ããå¿
è¦ãããï¼
Ref: http://equj65.net/tech/java8hotspot/
-XX:+UseConcMarkSweepGC
Use concurrent mark-sweep collection for the old generation
CMS GC ã使ãï¼
Java ã®ãã¼ã¸ã§ã³ã«ãã£ã¦ããã©ã«ãã®GCãå¤ãããããªã®ã§ï¼è¨å®ããã»ããå®å
¨ãªæããããï¼
-XX:+CMSParallelRemarkEnabled
ã¡ã¸ã£ã¼GCã®Remarkãã§ã¤ãºããã«ãã¹ã¬ããã§å®è¡
(ãåä½ããããã·ã³ã®CPUã2å以ä¸ãã¤ç©çã¡ã¢ãªã2Gbytes以ä¸ã®å ´åã«ã¯ãèªåè¨å®ããããã¨ããã念ã®ãã: http://www.atmarkit.co.jp/ait/articles/0704/24/news136_2.html)
-XX:+UseParNewGC
ãã¤ãã¼GCããã«ãã¹ã¬ããã§å®è¡
(ãåä½ããããã·ã³ã®CPUã2å以ä¸ãã¤ç©çã¡ã¢ãªã2Gbytes以ä¸ã®å ´åã«ã¯ãèªåè¨å®ããããã¨ããã念ã®ãã: http://www.atmarkit.co.jp/ait/articles/0704/24/news136_2.html)
-XX:+UseCMSInitiatingOccupancyOnly
CMSãéå§ãããããªã¬ã¼ã¯äºã¤ãããã²ã¨ã¤ã¯Oldé åã®å©ç¨çãCMSInitiatingOccupancyFraction ã«å°éããå ´åãããã²ã¨ã¤ã¯ä»CMSèµ°ãããªãã¨å ã«ãã¼ãåã¾ã£ã¡ãããããã¨ããçµ±è¨å¤æãå ã«ããããªã¬ã¼ãUseCMSInitiatingOccupancyOnlyãä»ä¸ããã¨å¾è ã®ããªã¬ã¼ãç¡å¹ã«ãªãã
http://nekop.hatenablog.com/entry/20140327/1395886237
ã¨ããããã§ï¼çµ±è¨å¤æãç¡å¹ã«ï¼
-XX:CMSInitiatingOccupancyFraction=75
XX:+UseCMSInitiatingOccupancyOnly ã¨é¢é£ï¼
ãããã®ããã©ã«ãã¯MinHeapFreeRatio=40ãCMSTriggerRatio=80ãªã®ã§ãCMSInitiatingOccupancyFractionã®ããã©ã«ãå¤ã¯92ã«ãªããã¤ã¾ããOldé åã92%ã«ãªã£ãã¨ãã«æåã®CMS GCãè¡ãããããªãã¸ã§ã¯ãã¢ãã±ã¼ã·ã§ã³ãæ¿ãããããªã¢ããªã±ã¼ã·ã§ã³ã§ã¯92%ã ã¨æé ãã«ãªããã¨ãããã®ã§CMSInitiatingOccupancyFractionã¯ä¸ããã»ããè¯ãã70ã¨ãã
http://nekop.hatenablog.com/entry/20140327/1395886237
[追è¨]
XX:CMSInitiatingPermOccupancyFraction=percent
Sets the percentage of the permanent generation occupancy (0 to 100) at which to start a GC. This option was deprecated in JDK 8 with no replacement.
http://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
JDK8 以éã¯éæ¨å¥¨ã¨ã®ãã¨â¦â¦JDK 9ã¨åºä¼ã£ããã¾ãèãã¾ããã
[追è¨]
@sugarlifeããã«æãã¦ããã ãã¾ãããï¼ããã¯ãªãã·ã§ã³èªä½ãéæ¨å¥¨ãªããã§ã¯ãªãï¼JDK 9ã§ã¯CMS GCèªä½ãéæ¨å¥¨ã®ãããã®ãããªè¨è¿°ã«ãªã£ã¦ããã¨ã®ãã¨ï¼
-XX:+ScavengeBeforeFullGC
FullGC èµ°ãããåã« young ã® GC ãèµ°ããã
-XX:+CMSScavengeBeforeRemark
If turned on, it will cause a minor collection to occur just before the remark. That's good because it will reduce the remark pause. That's bad because there is a minor collection pause followed immediately by the remark pause which looks like 1 big fat pause.
https://blogs.oracle.com/jonthecollector/entry/did_you_know
CMS ã® Remark å¦çã®åã«ãã¤ãã¼ã® scavenge ãããã¨ãããã¨ãããï¼
-XX:+TieredCompilation
é層åã³ã³ãã¤ã«ãæå¹ã«ããï¼æå¹ã«ããã¨ï¼ã³ã³ãã¤ã«æ¸ã³ã¼ãã®å®è¡ä¸ã« JVM ãæé©åã®ããã®çµ±è¨æ å ±ãåéå¯è½ã«ããï¼
ãã®æ¹è¯ã®æå¹æ§ã¯ããã»ã©é«ãã¯ãªãã¨æãããããµã¼ãã®ã¹ã¿ã¼ãã¢ããæã®å¦çæéã¯ï¼ãã¹ã¯ããããã¢ãã¬ãããã¼ã¹ã®ã¢ããªã±ã¼ã·ã§ã³ã»ã©éè¦ã§ã¯ãªãããã ããã ãé常ã«ãã¤ãããã¯ãªã·ã¹ãã ã«ããã¦åãã¼ãããã°ããç«ã¡ä¸ããå¿ è¦ã®ããå ´åãªã©ã«ã¯ï¼ãã®å¤æ´ã§ã¦ã©ã¼ã ã¢ããæéãç縮ã§ããããç¥ããªãã
http://www.infoq.com/jp/news/2011/11/java7-u1
ã¨ã®ãã¨ã ãâ¦â¦
-XX:+UseCompressedOops
Enables the use of compressed pointers (object references represented as 32 bit offsets instead of 64-bit pointers) for optimized 64-bit performance with Java heap sizes less than 32gb.
XX:+UseCompressedOops ãªãã·ã§ã³ã使ç¨ããã¨ãJava ãªãã¸ã§ã¯ããã¼ãã®ãµã¤ãºã 32 ã®ã¬ãã¤ãæªæºã®å ´åã«ã64 ããã JRE ã®ããã©ã¼ãã³ã¹ãåä¸ããããã¨ãã§ãã¾ãããã®å ´åãHotSpot ã¯ãªãã¸ã§ã¯ãåç §ã 32 ãããã«å§ç¸®ãã¦ãå¦çããå¿ è¦ã®ãããã¼ã¿ã®éãæ¸ããã¾ãã
Ref: http://itdoc.hitachi.co.jp/manuals/link/has_v101000/0342020D/0766.HTM
Ref: http://www.oracle.com/technetwork/jp/articles/java/compressedoops-427542-ja.html
Ref: http://d.hatena.ne.jp/quitada/20120130/p1
-XX:+PrintGCDetails
gc log ã«è©³ç´°ãªæ å ±ãåãåºãããã«ããï¼GC algorithm ã JVM ã®ãã¼ã¸ã§ã³ã«ãã£ã¦è¿½å ãããæ å ±ã¯å¤ãã£ã¦ããããã ãï¼ã¨ãããã GC ã®ã¹ã«ã¼ãããã®æ å ±ãåºããããï¼
-XX:+PrintGCApplicationStoppedTime
Stop The World ãèµ·ããæï¼stop ããæéã gc log ã«æ¸ãåºãããã«ããï¼
-XX:+PrintGCDateStamps
gc log ã®åè¡ã®å é ã«æ¥æã®ã¹ã¿ã³ããä»ä¸ãã (PrintGCTimeStamps ã«ããã¨ï¼JVM ãèµ·åãã¦ããã®ç§æ°ãå é ã«ä»ä¸ãããããã«ãªãï¼ãããèªã¿ã«ããæ°ãããã®ã§ Date ã«)
-XX:+PrintTenuringDistribution
youngé åããoldé åã¸ã®ææ ¼ï¼ææ ¼ï¼ï¼ã«é¢ãããã°ãåºåããããã®ãªãã·ã§ã³ï¼
-XX:+HeapDumpOnOutOfMemoryError
OOM Error ãèµ·ããæã« Heap Dump ãåãåºãããã«ããï¼
éæ
Xmsï¼Xmxï¼Xmn åã³ Xss ã¯å²ã¨åã¨çµé¨ã§è¨å®ãã¦ããæããããã®ã§ï¼æ¹åã®ä½å°ãæ®ããã¦ããæ°ãããï¼
以ä¸ã®è¨äºãªãããåèã«ããã®ãè¯ãã®ã;
JVMのチューニング - ITエンジニアとして生きる
[調査]JVMのスタックサイズについて - Akira's Tech Notes
ガベージコレクタの仕組みを理解する:チューニングのためのJava VM講座(後編) - @IT
åèè³æ
Java VM Options You Should Always Use in Production – Software Engineer Sandbox
OutOfMemoryErrorが発生したときにきちんとJavaプロセスを殺す - nekop's blog
Java 7 CMS GCの基本的な情報の整理 - nekop's blog
Java8のHotSpotVMからPermanent領域が消えた理由とその影響 | ギークを目指して
http://www.whitemark.co.jp/tec/java/javagc.html
Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine
Useful JVM Flags - Part 8 (GC Logging) - codecentric AG Blog
UseCompressedOops オプションのデフォルト値 - めざせ!細マッチョ
“Stop the World”を防ぐコンカレントGCとは?:現場から学ぶWebアプリ開発のトラブルハック(2) - @IT
*1:ä¸è¬çã®å®ç¾©ãææ§