Java Flight Recorder
- Provide a low-overhead data collection framework for troubleshooting Java applications and the HotSpot JVM.
- ์๋ฐ ์ดํ๋ฆฌ์ผ์ด์ ๊ณผ HotSpot JVM์ ๋ฐ์ดํฐ๋ฅผ ๋ฎ์ ์ค๋ฒํค๋๋ก ์์งํ์ฌ ํธ๋ฌ๋ธ ์ํ ์ ํ์ํ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ ๋๊ตฌ
Licence
- ์๋ JFR์ Oracle JDK์ ์๋ ๊ธฐ๋ฅ์ด์์ง๋ง, ์คํ์์ค1๋ก ๋ณ๊ฒฝ๋์๋ค.
Flight Recorder has existed for many years and was previously a commercial feature of the Oracle JDK.
This JEP moves the source code to the open repository to make the feature generally available.
์์ง ๋์
- OS
- Memory, CPU Load and CPU information, native libraries, process information
- JVM
- Flags, GC configuration, compiler configuration
- Method profiling event
- Memory leak event
- JDK libraries
- Socket IO, File IO, Exceptions and Errors, modules
Events
- JFR์ JVM๊ณผ ๊ด๋ จ๋ ์ด๋ฒคํธ๋ฅผ ์์งํ๋ค.
- duration event : ํน์ ์๊ฐ ๋์ ๋ฐ์ํ๋ ์ด๋ฒคํธ ex) ๋ฉ์๋ ์คํ ์๊ฐ
- instant event : ์ฆ์ ๋ฐ์ํ๊ณ ๊ธฐ๋ก๋๋ ์ด๋ฒคํธ ex) ์ค๋ ๋ ์ฐจ๋จ
- sample event : ์ฃผ๊ธฐ์ ์ผ๋ก ์์คํ ์ํ๋ฅผ ์ ๊ฒํ๋ ์ด๋ฒคํธ ex) heap
How to use
JFR ๊ธฐ๋ฅ ํ์ฑํ
- ์๋ฐ ์ดํ๋ฆฌ์ผ์ด์ ์ ์คํํ ๋ ์๋์ ์ต์ ์ ์ถ๊ฐํ๋ค.
-XX:+UnlockCommercialFeatures
-XX:+FlightRecorder
Command jcmd๋ฅผ ํตํด JFR ํ์ผ ์์ฑํ๊ธฐ
settings=profile
์ ์ถ๊ฐํด์ผ ๋ ๋ง์ ์ ๋ณด๋ฅผ ์์งํ๋ค.- ๊ทธ๋งํผ ๋ถํ๊ฐ ์๊ธฐ ๋๋ฌธ์ ์งง์ ์๊ฐ ์์งํ ๋ ํ์ฉํ๋๊ฒ ์ข๋ค.
$JAVA_HOME/jre/lib/jfr/default.jfc, profile.jfc
์ ๋ฏธ๋ฆฌ ์ค์ ๋ ํ๋กํ์ผ์ด ์กด์ฌํ๋ค.
# jfr ์์ฑ ์์
jcmd {ํ๋ก์ธ์ค ID} JFR.start duration=30s settings=profile filename=test.jfr
# JFR.check - checks running JFR recording
jcmd {ํ๋ก์ธ์ค ID} JFR.check
# JFR.stop
jcmd {ํ๋ก์ธ์ค ID} JFR.stop recording=2
Kubernetes๋ฅผ ํตํด JFR ํ์ผ ๊ฐ์ ธ์ค๊ธฐ
- ์๋์ ๋ช ๋ น์ด๋ฅผ ์คํํ๋ฉด ๋ก์ปฌ๋ก ๋ณต์ฌํ ์ ์๋ค.
kubectl cp {namespace}/{pod-name}:{file-path} {local-path}
How to read
- ๋ก์ปฌ๋ก ๊ฐ์ ธ์จ ํ์ผ์ JDK Mission Control, IntelliJ, Visualvm์ผ๋ก ์ฝ์ ์ ์๋ค.
- CPU
- ์ด๋ Thread๊ฐ ๊ฐ์ฅ CPU๋ฅผ ๋ง์ด ์ฌ์ฉํ๊ณ ์๋์ง ์ ์ ์๋ค.
- CPU ์ฌ์ฉ๋์ ์ต์ ํ ํ ๋ ์ ์ฌํ ๋ณด๋ฉด ์ ์ผ ์ข๋ค.
- Memory
- ์์๊ฐ ๋ฐ์ฑ, ๊ฐ์ฒด ์์ฑ๊ณผ์ ์์ ๋ฐ์ํ๋ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์ฐพ์์ ์ต์ ํ ํ ๋ ์ข๋ค.
- Flame Graph
- ๋ฆฌ์์ค๋ฅผ ๊ฐ์ฅ ๋ง์ด ์๋นํ๋ Thread ํจ์ ๋ถํฐ ๋ ธ์ถ๋๋ค.
- IntelliJ ๊ธฐ์ค ์ฌ์ฉ๋ฅ ์ด ๋์์๋ก ์ผ์ชฝ์ ์์นํ๋ฉฐ ๋๋น๊ฐ ๋์
JDK 21์์ ์ ๊ณตํ๋ JFR view
- ๊ณผ๊ฑฐ์๋ ๋ณ๋์ ํ๋ก๊ทธ๋จ์ ํตํด JFR์ ํด์ํด์ผ ํ์ง๋ง, JDK์ JFR view cli 2๊ธฐ๋ฅ์ด ํฌํจ๋์๋ค.
jfr view hot-methods test.jfr
Reference
- https://openjdk.org/jeps/328
- https://docs.oracle.com/en/java/java-components/jdk-mission-control/8/user-guide/using-jdk-flight-recorder.html
- https://www.baeldung.com/java-flight-recorder-monitoring
- https://blog.naver.com/kbh3983/220995466033
Footnotes
-
Opensourceํ์๋ง์ ํ ์ ์ฒด๋ฅผ layoff ํ๋ค๋ ์์์ด ์๋ค. https://www.infoq.com/news/2018/06/open-source-jmc/ โฉ