JVMã¢ããªã±ã¼ã·ã§ã³ãéç¨ããéã®ã¡ã¸ã£ã¼ã©ãããã¥ã¼ãã³ã°ãã¤ã³ãã¡ã¢
JVMã«ãã¥ã¼ãã³ã°é ç®ã¯å¤ã ããã©ããããã¯ã·ã§ã³ã§éç¨ããéã«äºããããã¦ããããé ç®ãã¾ã¨ãã¦ã¿ãã¨ã³ããªã§ãã*1 å¿è«ãOSãJVMãããã©ã«ãã§ããç¨åº¦ã®ããã©ã¼ãã³ã¹ã¯çºæ®ã§ããè¨æ¸¬ãä¼´ããªããã¥ã¼ãã³ã°ã¯æªæã§ãããã¨ã¯ããç¥ããã¦ãã¾ãã ããããè¨å®ãã¦ãããªãã¨ããã©ã¼ãã³ã¹ã«ãã®ã¾ã¾å½±é¿ããã¨åãããã®ã調ã¹ãªãã®ã¯è£¸ã§æ¦å ´ã«èµ´ããããªãã®ã§ãã*2 ã©ããªé ç®ãã©ãå¤æ´ããã°è¯ãã®ãç¥ã£ã¦ãããã¨ã¯éè¦ãªæ¦å¨ãªã®ã§ãã
ãªã調ã¹ãã®ã
ä»åããã¥ã¼ãã³ã°ãã¤ã³ãã調ã¹ãã«ããã£ã¦ãç§ã®ã¢ããã¼ã·ã§ã³ã¯ã©ãã«ããã®ããèããã¨ã以ä¸ã®è¦ä»¶ãæºããããã¨ãããã¨ãããããã¾ãã
- ã¢ããªã±ã¼ã·ã§ã³ã¨ãã¦æ±ããããå質水æºã¨ãã¦åä½ãã â æ§è½ç®æ¨
- ç°å¸¸æã«äºè±¡ã追ããã¨ãã§ãã
ããã§ããå質水æºã»ç°å¸¸ã¨ã¯ãããã©ã¼ãã³ã¹ãæããã«ä½ããã¢ããªã±ã¼ã·ã§ã³ãã¯ã©ãã·ã¥ããããªã©ã®ï¼JVMã»ã¢ããªã±ã¼ã·ã§ã³åæ¹ã®ï¼æå¾ ããªãæ¯ãèããæãã¾ãã
æ§è½ç®æ¨
ãã¿ããã«ãã¥ã¼ãã³ã°ãã¦ãçµããããªããä½ããã¥ã¼ãã³ã°ããã°è¯ãããå¤æãã¥ãããã®ã§ãã æ§è½ç®æ¨ãå®ãããã¨ã§ããã®ã©ã¤ã³ãã¯ãªã¢ãç¶ãããã¨ãç®æãæ¹ãå¥å ¨ã§ãã ä¾ãã°ä»¥ä¸ã®ãããªé ç®ãããããããã¨æãã¾ãã
- ã¬ã¤ãã³ã·
- ã¬ã¹ãã³ã¹ã¿ã¤ã
- ã¹ã«ã¼ããã
- GCã«ä¼´ãåæ¢æé
TL;DR
ã ãããã®ãã¨ã¯Javaããã©ã¼ãã³ã¹ã«æ¸ãã¦ããã®ã§ããããèªããã
ãªããä»åã®ä¸»ãªé¢å¿ç¯å²ã¯ã¦ã§ãã¢ããªã±ã¼ã·ã§ã³ï¼JVMããã³ãã®ããã§åãã¢ããªã±ã¼ã·ã§ã³ï¼ãæ³å®ãã¦ãã¾ãã*3 代表çãªãã®ãããã¤ã¤ãããã¯æä½éãã§ãã¯ãããã¨ãããã®ã« â ãä»ãã¦ãã¾ãã
Kernel
JVMã®åã«åå°ã«ã¤ãã¦ãå°ãèãã¾ãã ãã¹ãã®ãªã½ã¼ã¹ãåå解æ¾ããªãã¨ãå½ç¶JVMãããã©ã¼ãã³ã¹ãçºæ®ã§ãã¾ããã æ¨ä»ã§ã¯Dockerãªã©ã®ã³ã³ããæè¡ãå½ããåã«ãªãã¤ã¤ããããã¹ãã ãã§ãªãã³ã³ããã®ãã¥ã¼ãã³ã°ãå¿ è¦ã«ãªã£ã¦ããããã«æãã¾ãã
- ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿
ulimit
fs.file-max
- fluentdã使ç¨ããã±ã¼ã¹ã§ã¯å¼·ãæ¨å¥¨ããã¦ãã
- TCP
- large page(huge page)
- OSã§ã®ã¡ã¢ãªã®ç®¡çåä½
- Linux 2.6.32以éã§ã¯transparent huge pageãå°å ¥ããã¦ããã
- ã¢ããªã±ã¼ã·ã§ã³ãç®ã«è¦ãã¦é«éåããï¼ãããï¼ã
transparent huge page
ã¡ã¢ãªã®ãã¼ã¸ãµã¤ãºã大ãããªãã°ãããã ãå°ãªãåæ°ã§I/Oãã§ããããé«éåã«ã¤ãªããã¾ãã
JVM以å¤ã«ãã·ã¹ãã ä¸ã®ãã¹ã¦ã®ããã°ã©ã ã使ç¨ããããã«ãªãç¹ã«æ³¨æãå¿
è¦ã§ãã
JVMå´ã¸ã®ãªãã·ã§ã³ã®æå®ã¯ä¸è¦ï¼-XX:+UseLargePages
ã¯å¥ã®ãã®ãªã®ã§ç¡å¹ã®ã¾ã¾ã«ãã¦ããï¼ã§ãã
# cat /sys/kernel/mm/transparent_hugepage/enabled always [madvise] never # echo always > /sys/kernel/mm/transparent_hugepage/enabled # cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never
Kubernetesä¸ã§åãéã®ãªã½ã¼ã¹å¶é
ã³ã³ãããªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ã®ããã«Kubernetesã使ãã±ã¼ã¹ãå¤ããªã£ã¦ãã¾ããã ã¢ããªã±ã¼ã·ã§ã³ã¯Podã®ä¸ã®ã³ã³ããåä½ã§åä½ãã¾ããããã®ã³ã³ããã«ãªã½ã¼ã¹ã®request/limitãæå®ã§ãã¾ããæ示ããªãã¦ãåä½ããããã¾ãããæå®ããæ¹ãã¢ããªå´ã®è¦ç©ãããããããããªã¨æã£ã¦ãã¾ãã ãã®limitãå ã«ã¢ããªã±ã¼ã·ã§ã³ï¼JVMï¼ã®è¨å®ã決ãã¦ããã°è¯ãã§ãããã*4
- CPUã¯çµ¶å¯¾å¤æå®
- ããã¤CPUã使ãããæå®
- milliåä½ã§æå®å¯è½
- Nodeã«ããã¤vCPUããã£ã¦ã絶対å¤æå®
1 cpu = 1 vCPU
- Memoryã絶対å¤æå®
- åºæ¬ã¯ã¡ããã¤ãï¼MiBï¼ã§æå®ããã®ã楽ãã
ããããããªã½ã¼ã¹ãæå®ããªãå ´åãããã ã使ããã¨ãããããè¤æ°ã®Podãä¸ã¤ã®Nodeã«è¼ããã¨ãã®åä½ãä¸å®å®ã¨ãªãæããããã¾ãã*5 大ããæ°ãæå®ãã¦ãNodeã®ãªã½ã¼ã¹ã足ããªãã¨èµ·åããã§ãã¾ããã
see also:
- Managing Compute Resources for Containers
- Assign Memory Resources to Containers and Pods
- Assign CPU Resources to Containers and Pods
- Understanding Kubernetes Resources
- Kubernetes ã¢ã³ããã¿ã¼ã³
JDK 10ã®ã³ã³ãããµãã¼ã
JDK 10ããã³ã³ãããµãã¼ããå¼·åããã¾ãã
-XX:-UseContainerSupport
ãããã©ã«ãã§æå¹ã¨ãªããJDK 10ããã¯Dockerã®è¨å®*6ããå¤ãåå¾ããããã«ãªãããã§ãã
Dockerã§ã¯ããã¤ãã®CPUè¨å®ãå¯è½ã§ãããJVM㯠min(cpuset-cpus, cpu-shares/1024, cpus)
ã¨ããè¨ç®ã«ãã active_processor_count
ã決å®ããããã§ãã端æ°ã®å ´åã¯åãä¸ãããã¦æ´æ°ã«ãªãã¾ãã
cpus㯠cpu_quota / cpu_period
ã«ãã£ã¦æ±ããããå¤ã§ãã
ãã®å¤ã¯ -XX:ActiveProcessorCount=N
ã«ãã£ã¦ä¸æ¸ããããã¨ãã§ãã¾ãã
ã¡ã¢ãªã¯JDK 10ããFractionï¼1/Nï¼ã«ããæå®ã§ã¯ãªãPercentageï¼%ï¼ã«ããæå®ãã§ããããã«ãªãã¾ãã 使ç¨å¯è½ãªãã¹ãã¡ã¢ãªã®å²åãæå®ãã¾ãã
Kubernetesä¸ã§åä½ããå ´åãKubernetesã®ããã¥ã¡ã³ãã«ããã¨ã次ã®ããã«ã³ã³ããã«ãã©ã¡ã¼ã¿ã渡ãããã¨ããã¾ãã
spec.containers[].resources.requests.cpu
ã¯ã³ã¢å¤ã«å¤æã1024ãæããå¤ã--cpu-shares
ã¨ãã¦æ¸¡ãããspec.containers[].resources.limits.cpu
ã¯ããªã³ã¢å¤ã«å¤æã100ãæããå¤ã--cpu-quota
ã¨ãã¦æ¸¡ããã*7- ã³ã³ããã100ms*8ã«ä½¿ç¨ã§ããCPUæéã®åè¨é
spec.containers[].resources.limits.memory
ã¯ãã®ã¾ã¾--memory
ã¨ãã¦æ¸¡ããã
ãã¨ãã°ãrequest.cpuã¨limits.cpuã®ä¸¡æ¹ã1ã¨ããå ´åã¯ãcpu-shares: 1 * 1024 / 1024 = 1cpu
㨠cpu-quota: 1000m * 100 / 100ms = 1cpu/ms
ã¨ãªãã®ã§JVMã«ã¯CPU 1ã¨ãã¦ã»ããããã¾ãã
ã¤ã¾ããKubernetesã®å®ç¾©ãã1cpuã¯ããã®ã¾ã¾JVMããè¦ãCPUæ°ã¨ãªãã¾ãã
ã§ãã®ã§ã両è
ã®å¤ã«å·®ãããã¨ããJDK 10ã§ã¯åè¿°ã®è¨ç®å¼ã§æå°å¤ãCPUã¨ãªãã¨æããã¾ããâ»æªæ¤è¨¼
see also:
- [JDK-8189497] Improve docker container detection and resource configuration usage - Java Bug System
- [JDK-8146115] Improve docker container detection and resource configuration usage - Java Bug System
- [JDK-8186315] Allow more flexibility in selecting Heap % of available RAM - Java Bug System
- New thing in JDK10 even that scala-er should know
- Better containerized JVMs in JDK 10
- Kubernetes on AWS - Container resource limits
- JVMã®ãã¼ããµã¤ãºã¨ã³ã³ããæ代ã®ãã¥ã¼ãã³ã°
JVM
æ¸ç±ãJavaããã©ã¼ãã³ã¹ï¼ãªã©ã¤ãªã¼ï¼ãã¯ãä¸è¬ã«å¿ è¦ã«ãªããã¨ãç¶²ç¾ ãã¦ãããã¨ããããã³ã¬ãèªãã§ããã°ã ãããã®ã±ã¼ã¹ã§ã¯ååã§ãããã¨æããä¸åã§ãã
JIT
-server -XX:+TieredCompilation
â- é層ã³ã³ãã¤ã«ï¼client compilerçã«æåã¯åããªãããæ å ±ãæºã¾ã£ã¦ãããserver compilerã¨ãã¦åä½ããï¼
- clientã¯æ©æããã³ã³ãã¤ã«ããserverã¯æ å ±ãæºã¾ã£ã¦ããããæå¹ãªã³ã³ãã¤ã«ãè¡ãï¼å¾è¿°ã®é¾å¤ã«ããï¼
- 64bit OS Java8ã ã¨ããã©ã«ãæå¹
-XX:ReservedCodeCacheSize=N
- ã³ã³ãã¤ã«ããã³ã¼ãã®ãã£ãã·ã¥ãµã¤ãº
- ãã®ãµã¤ãºã¾ã§ããã³ã³ãã¤ã«ããªãã®ã§å°ãããã¦ãNG
- 64bit server(+Tiered) Java8ã ã¨240MBãããã©ã«ã
- æå®ãããµã¤ãºããããªãå²ãå½ã¦ãããããã§ã¯ãªãã¡ã¢ãªã®äºç´ãè¡ã
- ãã£ãã·ã¥ããã£ã±ãã«ãªãã¨
VM warning: CodeCache is full.
ã®ãããªè¦åã表示ããããï¼è¦è½ã¨ããããï¼
-XX:-UseCodeCacheFlushing
- CodeCacheãéçã«è¿ã¥ãã¨ã³ã³ãã¤ã«ããã³ã¼ããæ¨ã¦ã
- ããã©ã«ãæå¹
- JMXãªã©ãéãã¦ãã£ãã·ã¥ãµã¤ãºãè¦ãªãããå¿
è¦ãªã³ã¼ããã£ãã·ã¥ãµã¤ãºãåããã°
ReservedCodeCacheSize
ã¨ä½µãã¦æå®ããã - Javaã®è¬ã®ããã©ã¼ãã³ã¹å£åç¾è±¡ã¨ã®æ¦ã
-XX:CompileThreshold=N
- ã³ã³ãã¤ã©ã¯ãã³ã¼ã«ã®åæ°ãã«ã¼ãã®åæ°ãªã©ãã¿ã¦ããããé¾å¤ãè¶ ããã¨ã³ã³ãã¤ã«å¯¾è±¡ã¨ãã
- ãã®ã«ã¦ã³ãã¯æéã®çµéï¼ã»ã¼ããã¤ã³ãã«éãã度ï¼ã§æ¸ç®ããããããé¾å¤ã«æºããªããéè¦ãªã³ã¼ããç¾ããå¯è½æ§ããããã³ã³ãã¤ã«ãããå ´åã¯ããã®ãªãã·ã§ã³ã§é¾å¤ãä¸ããã*9
- ããã©ã«ãã¯ãclient compilerã¯1500ãserver compilerã¯1ä¸
-XX:+DoEscapeAnalysis
Memory/GC
-Xms<N> -Xmx<N>
- ãã¼ããµã¤ãº
- ç©çã¡ã¢ãªãè¶ ãã¦ã¯ãããªããï¼ã¹ã¯ããã³ã°ãçºçããã¨ããã©ã¼ãã³ã¹ãæªåããï¼
-Xms
ã¨-Xmx
ã¯åãå¤ã«ããã»ãããæ¡å¼µ/ã·ã¥ãªã³ã¯æã®ã³ã¹ããçºçããªãã- ã¢ããªã±ã¼ã·ã§ã³ãããã©ã«ã以ä¸ã®å¤§ããªãã¼ããå¿ è¦ã¨ãã¦ããã®ã§ãªããªããGCã¢ã«ã´ãªãºã ãã¨ã®ããã©ã¼ãã³ã¹ç®æ¨å¤ããã¥ã¼ãã³ã°ããæ¹ãè¯ãã
- Linux 64bit serverã®ããã©ã«ãã¯ãXmsã512MBã¨ç©çã¡ã¢ãªã®1/64ã®ãã¡å°ããæ¹ãXmxã32GBã¨ç©çã¡ã¢ãªã®1/4ã®ãã¡å°ããæ¹
- JDK 8u131ã9ã§ã¯experimentalãªãªãã·ã§ã³ã¨ãã¦
-XX:+UseCGroupMemoryLimitForHeap
ã¨ãããã®ããã- ããã¯JDK 10ã§deprecated
- JDK 10ããã³ã³ããã®ãµãã¼ããå¼·åããã
-XX:InitialRAMFraction
ãªã©ã¯deprecatedã¨ãªã-XX:InitialRAMPercentage
ãè¨å®ã§ããããã«ãªãã- see also: [JDK-8196595] Release Note: Java Improvements for Docker Containers - Java Bug System
-XX:MaxRAMPercentage
ã使ããã¨ã§ã³ã³ããã®ã¡ã¢ãªé1/2以ä¸ã®ãã¼ããå²ãå½ã¦ããã¨ãå¯è½
-XX:NewRatio=N
- youngé åã«å¯¾ããoldé åã®æ¯ç
- ããã©ã«ãã¯2ï¼youngé åã¯33%ï¼
-XX:+UseSerialGC
or-XX:+UseParallelGC
or-XX:+UseConcMarkSweepGC -XX:+UseParNewGC
or-XX:+UseG1GC
â- ã¢ããªã±ã¼ã·ã§ã³ã®æ§è³ªã«ããé©åãªGCãé¸æããå¿ è¦ãããã
- Java8ããã©ã«ãã¯ã¹ã«ã¼ãããåGCï¼ParallelGCï¼
- SerialGCã¨ParallelGCã§ã¯STWï¼Stop the worldï¼ãã»ã¼é¿ããããªãã
- CMS GCã§ã¯ã¢ããªã±ã¼ã·ã§ã³ã¹ã¬ããã¨ä¸¦è¡ãã¦ãã¼ããæ¢ç´¢ããããCPUã«ãããªãã®ä½è£ãå¿
è¦ã§ãã³ã³ãã¯ãåãè¡ããªããããã¼ããæçåããã¾ã¾ã¨ãªããããã¯ã°ã©ã¦ã³ãã¹ã¬ããã®CPUãªã½ã¼ã¹ã確ä¿ã§ããªãå ´åãæçåã«ãããªãã¸ã§ã¯ãã®å²å½ãã§ããªããªãã¨ãã·ãªã¢ã«åã¨åãããã¹ã¦ã®ã¢ããªã±ã¼ã·ã§ã³ã¹ã¬ãããåæ¢ãã¦ãåä¸ã®ã¹ã¬ããã§GCãè¡ãããã
åèï¼Concurrent Mark-Sweep Garbage Collection - G1 GCã§ã¯ãã¼ãããªã¼ã¸ã§ã³ã«åå²ãã¦ç®¡çããCMSã¨åããã³ã³ã«ã¬ã³ãåã§ãããã»ã¨ãã©ã®å ´åã§ã¢ããªã±ã¼ã·ã§ã³ã¹ã¬ããã¯åæ¢ããªãããªãã¸ã§ã¯ãããªã¼ã¸ã§ã³ç§»åããããã¨ã§ãã¼ãã®æçåãèµ·ãã«ããããCPUæéã¯å¤ãæ¶è²»ãããããã«ãªãã4GB以ä¸ã®ãã¼ããµã¤ãºã®å ´åã¯CMSã®æ¹ãåºæ¬çã«é«éã
åèï¼Garbage First Garbage Collection- Java9ã§æ¨æºGCå
-XX:InitiatingHeapOccupancyPercent
大ããªãã¼ããåæã«ä½ããã¦ããã®ã§ãã¼ããµã¤ãºãå°ããå ´åã¯ãã®ãªãã·ã§ã³ã§èª¿æ´ããã
-XX:+HeapDumpOnOutOfMemoryError
â- OutOfMemoryErrorãçºçããéã«ãã¼ããã³ããå®è¡
- OOMEã«ã¤ãã¦ã®åèï¼java.lang.OutOfMemoryError
-XX:+CrashOnOutOfMemoryError
or-XX:+ExitOnOutOfMemoryError
â- OutOfMemoryErrorãçºçããéã«ããã»ã¹ãçµäºããã
- åè ã¯ã¨ã©ã¼ãã¡ã¤ã«ãåºåãã
- OutOfMemoryErrorãçºçããã¨ããã®å¾ã®æåã¯ä¸å®ç¶æ ã¨ãªããããããã«Killãããã¨ã好ã¾ããã
- Java 8u92ãã使ç¨ã§ãã
- see also: Spring Boot 1.4.x ã® Web ã¢ããªã 1.5.x ã¸ãã¼ã¸ã§ã³ã¢ãããã ( ãã®ï¼ï¼ )( -XX:+ExitOnOutOfMemoryError 㨠-XX:+CrashOnOutOfMemoryError ãªãã·ã§ã³ã®ã©ã¡ããæå®ãã¹ããï¼ )
-XX:OnOutOfMemoryError='bin/kill -ABRT %p'
- OutOfMemoryErrorãçºçããéã«ã³ãã³ããå®è¡ã§ãã
- Java 8u91以åãªã©ã§åè¿°ã®ãªãã·ã§ã³ã使ç¨ã§ããªãã¨ãããä»ã«è¡ããããã¨ãããå ´åã«ä½¿ç¨ãã
-XX:HeapDumpPath=<path>
- ãã¼ããã³ãã®åºåå
- ããã©ã«ãã¯ã¢ããªã±ã¼ã·ã§ã³ã®ã«ã¬ã³ããã£ã¬ã¯ããªã®
java_pid<PID>.hprof
- ãã£ã¬ã¯ããªåã ãã®æå®ãå¯è½
-XX:+HeapDumpBeforeFullGC
- ãã«GCã®åã«ãã¼ããã³ããçæããã
- ãã¼ããµã¤ãºã大ããç¨ãã¼ããã³ãã«ã¯æéãããããã使ç¨ã«æ³¨æã
CMS GCã¯Java9ã§éæ¨å¥¨ã¨ãªã£ã¦ãããããç¾å®çã«ã¯ã¹ã«ã¼ãããåGCã¾ãã¯G1 GCã®ããããé¸æãããã«ãªãããã«æãã¾ãã ã©ã¡ããé¸æããæ¹ãè¯ããã¯ãCPUã®ä½åã¨ãã¼ãã¡ã¢ãªã®ãµã¤ãºã«ãã£ã¦å¤ããã¾ãã両æ¹ãååã«å¤§ããï¼å¤ãå¿ è¦ã¨ããï¼ã®ã§ããã°G1 GCã®æ¹ãåºæ¬çã«é©ãã¦ãã¾ãããã«GCã«ä¼´ãåæ¢ã極åãªããããå ´åã¯CPUã¨ã¡ã¢ãªãç©ãã§G1 GCãé¸æãã¾ãããã
see also: HotSpot Virtual Machineã¬ãã¼ã¸ã»ã³ã¬ã¯ã·ã§ã³ã»ãã¥ã¼ãã³ã°ã»ã¬ã¤ã
ã¹ã«ã¼ãããåGCï¼ParallelGCï¼ã®è¨å®
-XX:MaxGCPauseMillis=N
- æ大ä¸æåæ¢æéç®æ¨ï¼è¨±å®¹å¯è½ãªåæ¢æéã®æ大å¤ï¼
- ãã¤ãã¼GCã¨ãã«GCã®ä¸¡æ¹ã«é©ç¨ãããã
- ãã¾ãã«ä½ãå¤ãæå®ããã¨ãå°ãããGCãè¡ãããªããããã¼ãã空ãããããã£ã¦GCãé »çºããããã¨ã¨ãªããç¾å®çãªæéãæå®ããå¿ è¦ãããã
- ããã©ã«ãæå®ãªãï¼ç¡è¦ãããï¼
-XX:GCTimeRatio=N
â- ã¹ã«ã¼ãããç®æ¨
- ã¢ããªã±ã¼ã·ã§ã³ã¹ã¬ããã¨æ¯ã¹ã¦GCã«ã©ã®ç¨åº¦ã®æéãããã£ã¦ããããæå®ããã
- ããã©ã«ãã¯99ï¼
1 / (1 + GCTimeRatio)
ã§è¨ç®ãããã®ã§ããã®å ´å1%ãGCã®å®è¡æéç®æ¨ï¼ - 19ãããã§å§ãããã¨ããªã¹ã¹ã¡ï¼GCæé5%ç®æ¨ï¼
æ大ä¸æåæ¢æéç®æ¨âã¹ã«ã¼ãããç®æ¨âæå°ãããããªã³ãç®æ¨ï¼-Xmx
ï¼ã®é ã«éæããããåä½ãã¾ãã
JVMã¯adaptive sizingãããã©ã«ãã§æå¹ã§ãæå®ãããç®æ¨å¤ã«ãªãããã«èªåçã«ã¡ã¢ãªã®æ¡å¼µãªã©èª¿æ´ãè¡ãã¾ãã
ãã®ãããå¿
è¦ãªãã¼ããµã¤ãºãäºãåããå ´åã«ã¯-Xms -Xmx
ãåå¤ã«æå®ããã¨GCãæå°éã«çããããããããã©ã¼ãã³ã¹ã«ãã©ã¹ã¨ãªãããã§ããããããGCæé以ä¸ã«ã¹ã«ã¼ãããï¼Opsï¼ã®ç®æ¨ãååã«æºãããã¨ãéè¦ã§ãããé©åãªãµã¤ãºã®ãã¼ãï¼-Xmx
ï¼ã¨GCTimeRatioãæå®ãã¦JVMã«å§ãã¦ãæä½æ¥ã§ãã¥ã¼ãã³ã°ããå ´åã¨åçã®ã¹ã«ã¼ããããéæã§ãããã¨ãããç¹ã«ã¯çæãå¿
è¦ã§ããï¼ä¸è¨Oracleã®ã¬ã¤ãã§ãããã©ã«ãããå¿
è¦ãªãã¼ããµã¤ãºã大ããå ´åãé¤ãXmxãæå®ããªããã¨ãå§ãã¦ãããï¼
G1 GCã®è¨å®
-XX:MaxGCPauseMillis=N
â- åè¿°ã®éã
- G1 GCã®å ´åããã©ã«ãã¯200
- ã»ã¨ãã©ãã®ãã©ã°ã®ãã¥ã¼ãã³ã°ã主ã¨ãªãï¼G1ã¯äºæ¸¬ã¢ãã«ãç¨ãã¦ããã®å¤ããã¨ã«åä½ãèªå調æ´ããï¼ã
-XX:ParallelGCThreads=N
- GCã¹ã¬ããã®æ°
- ããã©ã«ãã¯CPU1ã¤ã«ã¤ã1ã¹ã¬ããï¼9CPU以éã¯
(8 + (CPUæ° - 8) * (5 / 8))
ï¼ã ããã¹ã¬ãããå¤ããã¦ãå¹æãèããªãããå°ããããã
-XX:ConcGCThreads=N
- ãã¼ã¯ä»ããè¡ãããã¯ã°ã©ã¦ã³ãã¹ã¬ããã®æ°
- ããã©ã«ãã¯
(ParallelGCThreads + 2) / 4
- ååãªCPUãæè¼ããã¦ãããªãããã¼ã¯ä»ããè¡ãã¹ã¬ãããå¢ãããã¨ã§ããã©ã¼ãã³ã¹ã«ãã©ã¹ã¨ãªãã
-XX:InitiatingHeapOccupancyPercent=N
- GCãéå§ãããã¼ãã®ä½¿ç¨ç
- ããã©ã«ã45
- ãã®ãã©ã°ã¯å¸¸ã«ä¸å®ã§èªå調æ´ãããªãã
- 大ããããã¨ãã«GCãçºçãããããªããå°ããããã¨ããã¯ã°ã©ã¦ã³ãã§ã®GCãå¿ è¦ä»¥ä¸ã«çºçãããã³ã³ã«ã¬ã³ããµã¤ã¯ã«ã®çµäºå¾ã®ãã¼ããè¨å®å¤ããä¸åã£ã¦ãããã¨ã確èªãã¹ãã
ã¾ãã¯MaxGCPauseMillisã®ãã¥ã¼ãã³ã°ããå§ããããã§ããã«GCãçºçããå ´åã«ä»ã®ãã¥ã¼ãã³ã°ãè¡ã£ãæ¹ãè¯ãã§ãããã
ãã®ä»
-Duser.timezone
- ã¢ããªã±ã¼ã·ã§ã³/DBéã§ã¿ã¤ã ã¾ã¼ã³ã¯æãã¦ãããæ¹ãäºæ ãæ¸ãããã
- å人çã«ã¯UTCã§çµ±ä¸ãããã*11
Application
Thread Pool
- ãã¼ã«ãµã¤ãº
- æ大å¤ã¨æå°å¤ã¯ååã«è¦ç©ããããªãåãã«ãã¦ãããâ»åºå®ãã¼ã«ã®å ´å
- åºæ¬ã¯CPUã³ã¢æ°ã¨åããæ大ã®ã¹ã«ã¼ããããéæãããã®ã¯åæ°ã®ã¹ã¬ããããã¼ã«ã«ããã¨ãã
- CPUãããã«ããã¯ã®å ´åã¯ãã¹ã¬ããæ°ãCPU以ä¸ã«å¢ããã¦ã大ããªããã©ã¼ãã³ã¹æªåã¯èµ·ãã«ããã*12
- CPU以å¤ï¼DBãªã©å¤é¨ãªã½ã¼ã¹ï¼ãããã«ããã¯ã®å ´åã¯ãã¯ã©ã¤ã¢ã³ãå´ã¯ä½å°CPUããã£ã¦ãå¤é¨ãªã½ã¼ã¹å´ããã¸ã¼ç¶æ ã¨ãªããããã¹ã¬ããæ°ãå¢ããã°å¢ããã»ã©ããã©ã¼ãã³ã¹ãæªåãã¦ããã
- DBã¢ã¯ã»ã¹ã®ããã®ã¹ã¬ãããã¼ã«ã®ããã«ãããããã³ã°ãçºçããé¨åã®ãã¼ã«ãåé¢ããæ¹ãè¯ãã
- DBã«ã¢ã¯ã»ã¹ããã¯ã©ã¤ã¢ã³ãå¦çãããã¹ã¬ãããã¼ã«ã§ãããã¯ç¶æ ã¨ãªãã¹ã¬ãããå¢ããå ´åã¯ãã¼ã«æ°ãå¢ãããã¨ã§ãããã§ãªããã¼ã«ï¼å©ç¨å´ï¼ã®å¦çãççªãã§ãããã¯ç¶æ ã¨ãªããã¨ãç·©åãããã¨ãã§ããï¼å¢ãããããã¨åè¿°ã®ã¨ããå¤é¨ãªã½ã¼ã¹ã®è² è·ãæ¡å¤§ããï¼ã
see also: Understanding Play thread pools
DB Connection Pool
maximumPoolSize
â- ã³ãã¯ã·ã§ã³ããã¼ã«ããæ大æ°
pool size = æ大ã¹ã¬ããæ° * (æ大åææ¥ç¶æ° - 1) + 1
- ã¹ã¬ããä¸ã¤ããããåæã«ããã¤ã®ã³ãã¯ã·ã§ã³ãæã¤ãï¼ã¨ãããã¨
connectionInitSql
â- kamipo TRADITIONAL
- ããã©ã¼ãã³ã¹ã¨ããããäºæ ãæªç¶ã«é²ãããã
transactionIsolation = TRANSACTION_READ_COMMITTED
- ãã©ã³ã¶ã¯ã·ã§ã³åé¢ã¬ãã«
- MySQLãMVCCã¢ãã«ã¨ã¯ãã
REPEATABLE READ
ãªã®ã§æå®ãã¦ãã¾ãæ¹ãå®çãï¼ï¼ï¼ - ä»ã®DBã ã¨
TRANSACTION_READ_COMMITTED
ãããã©ã«ã
see also: HikariCPè¨å®
JDBC driver
ã¹ãã¼ãã¡ã³ããã£ãã·ã¥ãªã©ã¯ãã©ã¤ãã®è¨å®ã§èª¿æ´ãã¾ãã Aurora(MySQL)ã¸ã®æ¥ç¶ã«MariaDB Connector/Jã使ç¨ãã¦ãããããã§ã¯ãã®ãã©ã¤ãã®è¨å®é ç®ãæ¤è¨ãã¦ãã¾ãã*13
- SSL
- å¿ è¦ã«å¿ãã¦
useServerPrepStmts
- ãµã¼ããµã¤ãã§ã¯ã¨ãªå®è¡åã«ããªãã¢ã¼ãã¹ãã¼ãã¡ã³ãã®å¦çãè¡ãããã«ããã
- ããã©ã«ãç¡å¹
- HikariCPã®ããã¥ã¡ã³ãã§ã¯MySQLãã©ã¤ãã«ããã¦æå¹åãæ¨å¥¨ãã¦ããããMariaDBãã©ã¤ãã§ãåæ§ãä¸æã§ããéå»ã«æå¹ã§ãã£ããã®ãç¡å¹åãããæ´å²ããããããªã®ã§ãæ§åãã¿ãªããè¨å®ãæ¤è¨ããæ¹ãããã
serverTimezone
- ã¢ããªã±ã¼ã·ã§ã³ã¨ç°ãªãã¿ã¤ã ã¾ã¼ã³ã§ããå ´åã¯æå®ãå¿ è¦
Aurora(MySQL) failover support
jdbc:mysql:aurora://<hostDescription>[,<hostDescription>...]/
- ãã©ã¤ãã¬ãã«ã§ãã§ã¤ã«ãªã¼ãã¼ããµãã¼ãããã¦ããã
- Auroraããã§ã¤ã«ãªã¼ãã¼ãåãã¦ãããããã©ã¤ãå´ã§æ»æ´»ããã§ãã¯ããããããæ©ãåãæ¿ããã
useBatchMultiSend
- Aurora failoverãå©ç¨ããå ´åã¯falseã«ããã
Coding
#setFetchSize
#setQueryTimeout
- ã¯ã¨ãªã®ã¿ã¤ã ã¢ã¦ãï¼ç§ï¼
- Aurora(MySQL)ã§ã®åä½ã¯è¦æ¤è¨¼
è¨æ¸¬ã«ã¤ãã¦
ãã¥ã¼ãã³ã°ã«ã¯è¨æ¸¬ãã»ããã§ãªããã°ãããªããã¨ã¯å¨ç¥ã®éãã§ãã ä¾ãã°ã以ä¸ã®ãããªæ¹æ³ãèãããã¾ãã
- ãµã¼ãã¡ããªã¯ã¹
- CPU
- Memory
- Network
- etc
- JMXã«ããã¢ããªã±ã¼ã·ã§ã³ã§ã®ã¡ã¢ãªãã¹ã¬ãããDBã³ãã¯ã·ã§ã³ãªã½ã¼ã¹
-XX:+PrintCompilation
- JITã«ãã£ã¦ãã¡ã½ãããã«ã¼ããã³ã³ãã¤ã«ããããã³ã«ã¡ãã»ã¼ã¸ãåºåãããããã«ãªãã
- ãã«ãã°ã§ã¯ãªãã
jstat -compiler <PID>
ãjstat -printcompilation <PID> <refresh rate>
ã§ãä½ãã³ã³ãã¤ã«ãããããç¥ããã¨ã¯ã§ããã
- GCãã° â
-verbose:gc
(=-XX:+PrintGC
)-Xloggc:<path>
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
or-XX:+PrintGCDateStamps
-XX:+PrintReferenceGC
- GCã®éã«ã½ããåç §ã¨å¼±ãåç §ã«å¯¾ãã¦è¡ãããå¦çãè¨é²
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=N -XX:GCLogFileSize=N
-XX:+PrintTLAB
- jcmd
netstat -an
TIME_WAIT
ã大éçºçãã¦ããã¨ã¨ãã§ã¡ã©ã«ãã¼ããä¸è¶³ãã¦ããã
ãããã«
ããã¾ã§è¦ã¦ããããã«ãæåã«æ¤è¨ãã¹ãé ç®ã¯å°ãªããåºæ¬çã«JVMã¯åªç§ã§ãã ããã©ã¼ãã³ã¹ã«å½±é¿ããå¤ãã®ã±ã¼ã¹ã§ã¯ã¢ããªã±ã¼ã·ã§ã³ã³ã¼ããåå ã§ãããã¨ãã»ã¨ãã©ã§ããããã«æãã¾ãã ãã¥ã¼ãã³ã°ãã¤ã³ããç¥ãã ãã§ãªããå é¨åä½ï¼ã¹ã¬ããã¢ãã«ãã¡ã¢ãªã¢ãã«ãGCã®ä»çµã¿ãªã©ï¼ãç¥ããã¨ãä¸å¯æ¬ ã§ãã
ã¾ããå¶ç´çè«ã«ããã°å±ææé©åã®ç½ ãªã©ãããã¾ãã ã·ã¹ãã å ¨ä½ã®ããã«ããã¯ãæ¢ããã¨ãæéè¦ã§ãããããã©ã¼ãã³ã¹å£åã«ç´é¢ããéã¯ãããã¯ã«ããªããã®ã§ãã äºãã©ã®ãããªãã¤ã³ããããã®ãç¥ããã¨ãã§ããã®ãªããåããã«ããããã¨ã¯ããã¾ããã ã¢ããªã±ã¼ã·ã§ã³ã®æ§æ ¼ã«ãã£ã¦æé©è§£ã¯ç°ãªãã¾ãããæåã«èããç¯å²ã¯ä¼¼éãã®ããªã¨æãã¾ãã
æ´æ°å±¥æ´
- 2017/11/7 ã¯ã¦ãã³ã¡ã³ãã«ãã£ãçºè¡¨è³æãKubernetesã¢ã³ããã¿ã¼ã³ãã¸ã®ãªã³ã¯ã追è¨
- 2017/11/7 ã¯ã¦ãã³ã¡ã³ãã«ãã£ã
-XX:+CrashOnOutOfMemoryError
or-XX:+ExitOnOutOfMemoryError
ãè¿½è¨ - 2018/3/20 JDK 10ã§ã®ã³ã³ãããµãã¼ãã«ã¤ãã¦è¿½è¨
- 2019/10/6 è¯è¨äº JVMã®ãã¼ããµã¤ãºã¨ã³ã³ããæ代ã®ãã¥ã¼ãã³ã° ã¸ã®ãªã³ã¯ã追è¨
*1:ä½çªç ãã®ã¨ã³ããªã ã¨ããæãã§ãããèªåã§ã¾ã¨ããæ¹ãå¦ç¿ã«ãªãã®ã§â¦
*2:æ©ã¾ã£ãæé©åã¯æªã ããæé©åãä½ãããã«æ¬çªã«ãã¦ãã¨ãããã¨ã§ã¯ãªãã¨æã
*3:ããå ·ä½çã«ã¯Scala + Play frameworkãOpenJDK 8ã10
*4:Storageã¯ã»ã¼ä½¿ããªãã®ã§ãããã§ã¯èæ ®å¤ã¨ãã¦ãã¾ã
*5:ç¹ã«CPUã®ãã¼ã¹ããã¡ã¢ãªã溢ããæã¯å·»ãæ·»ããããããã¨ãã³ã¯ã¤
*6:cgroup filesystem?
*7:ããã¥ã¡ã³ãã«quotaå¼æ°ã¨ã¯æ¸ãã¦ããªãã®ã§ãã ãã®è³ªåã¨Dockerå ¬å¼ããã¥ã¡ã³ãããã³Zalandoã®å ¬éæ å ± ããquotaã¨æ¨æ¸¬ãã¾ãã
*8:default period
*9:æ» å¤ã«ãªããã
*10:ã¨ã¹ã±ã¼ãåæï¼é¸åºåæï¼ã¨ã¯ãã¼ã«ã«ãªãã¸ã§ã¯ãã®åç §ããã¼ãã«å ¬éããã¦ããªãï¼ï¼å®è³ªãããã¯ãä¸è¦ï¼ç®æãæ¤åºãã¦ãã©ã³ã¿ã¤ã ã³ã³ãã¤ã©ããããã¤ã³ã©ã¤ã³åãããã¨ã§æé©åãããã¨ãããã¯çç¥ã¨ãããã
*11:è²ã ãªé½åã®çµæJSTãæå®ããããå¾ãªãã±ã¼ã¹ã¯ããâ¦
*12:4CPUãªã32ã¹ã¬ããç¨åº¦ã¾ã§ã¯90%ç¨åº¦ã«ã¹ã«ã¼ããããè½ã¡ããããããã
*13:AWSæ¨å¥¨ã½ãç¹ã¨ãMySQL Connector/Jã«æ¯ã¹ã¦ç½ ãå°ãªãããã«æãã