25 Şubat 2019 Pazartesi

G1 Garbage Collector - Loglama Seçenekleri

Giriş
Java 9 ile Unified JVM Logging seçeneği olarak sadece -XLog:gc kullanılıyor. Geri kalanlar kaldırıldı. Açıklaması şöyle
Unified JVM Logging got introduced in Java SE 9 with the motivation of simplifying root-cause analysis by allowing fine-grained and easy-to-configure logging options. 
GC çıktısını etkinleştirmek performans kaybına sebep olmuyor. Bu logları incelemek için bir araç kullanmak gerekir. Açıklaması şöyle
Thus, to analyze GC logs, it’s highly recommended to use GC log analysis tools such as GCeasy, HPJmeter. These tools parse GC logs and generate great graphical visualizations of data, reports Key Performance Indicators and several other useful metrics.
Kullanım
Şöyle yaparız
Until Java 8:

Below is the system property that is supported by all versions of Java until JDK 8.

-XX:+PrintGCDetails -Xloggc:<gc-log-file-path>

Example:
-XX:+PrintGCDetails -Xloggc:/opt/tmp/myapp-gc.log

From Java 9:

Below is the system property that is supported by all versions of Java starting with 
JDK 9.

-Xlog:gc*:file=<gc-log-file-path>

Example:
-Xlog:gc*:file=/opt/tmp/myapp-gc.log

1. -Xlog:gc seçeneği
Örnek
Şöyle yaparız.
-Xlog:gc=debug:file=/tmp/gc.log
Loglardaki humongous allocation isteklerini bulmak için şöyle yaparız
# humongous allocation için
grep "source: concurrent humongous allocation" /tmp/gc.log | 
  sed 's/.*allocation request: \([0-9]*\) bytes.*/\1/' > humongous_size.txt

# Daha sonra toplamı bulmak için
awk -F',' '{sum+=$1} END{print sum;}' humoungous_size.txt

2. -Xloggc seçeneği - Kullanmayın
Bu seçenek sanırım HotSpot'a mahsustu ve Java 9 ile deprecate edildi. Dosya ismine pattern verilebilir.
Örnek
Şöyle yaparız.
"-Xloggc:/home/GCEASY/gc-%t.log"
Örnek - filecount + filesize
Şöyle yaparız
-Xlog:gc*:gc.log:time,level,tags:filecount=5,filesize=1024K
Dosyada çıktı olarak şöyle bir şey görürüz
Pause Young (Normal) (G1 Evacuation Pause) 10247M->2108M(16384M) 9.477ms
Açıklaması şöyle. Burada Java uygulaması 16GB heap ile başlatılıyor ancak 2.1GB'ye gelince GC başlıyor.
In this case, the -Xmx parameter was 16G, this is where the 16484M comes from. Garbage collection started running when 10247 MB were used, and ended up with 2108 MB after the garbage collection. Which means that you absolutely can't go below ~ 2 GB because that's what Java really needs, and shouldn't go below around double this value.
Örnek
Şöyle yaparız.
java ... -Xlog:gc*=info,heap*=debug,safepoint=info:file=/home/logs/gc.log::filecount=3,
filesize=1m FooApp
3. Java 8 ve Öncesinde Loglama Seçenekleri
Loglamayla ilgili çoğu seçenek PrintXXX şeklinde.

Bir sürü seçenek var ancak hepsini kullanmak anlamlı değil sanırım.

-XX:+PrintGCDetails  seçeneği
Prints G1 Phases
Java 8 ve öncesinde şöyle yaparız.
-XX:+PrintGCDetails -Xloggc:
Java 9 ve sonrasında şöyle yaparız
class="prettyprint"-Xlog:gc*:file=<gc-log-file-path>
Örnek 
Şöyle yaparız
-verbose:gc -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps
-XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5
-XX:GCLogFileSize=1M
Şuna benzer bir çıktı alırız. Java 16GB heap ile başlatılıyor. GC'den önce 10.7GB kullanılıyor, GC'den sonra 2790 M'e düşüyor.
[Eden: 8176.0M(8176.0M)->0.0B(8176.0M) Survivors: 16.0M->16.0M 
Heap: 10.7G(16.0G)->2790.4M(16.0G)]
Örnek - PrintGCDateStamps
Dosyaya 2MM'lik 5 dosyaya yazdırmak için şöyle yaparız
-XX:+DisableExplicitGC 
-XX:+PrintGCDetails 
-XX:+PrintGCApplicationStoppedTime 
-XX:+PrintGCApplicationConcurrentTime 
-XX:+PrintGCDateStamps 
-Xloggc:gclog.log 
-XX:+UseGCLogFileRotation 
-XX:NumberOfGCLogFiles=5 
-XX:GCLogFileSize=2000k 
-XX:+PrintGCTimeStamps seçeneği
Prints date and uptime
Şöyle yaparız.
-XX:+PrintGCTimeStamps -XX:+PrintGCDetails
-XX:+PrintAdaptiveSizePolicy -XX:+PrintTenuringDistribution
Prints date and uptime
-XX:+PrintAdaptiveSizePolicy seçeneği
Prints ergonomic decisions
-XX:+PrintTenuringDistribution seçeneği
Print aging information of survivor regions
-XX:+UseGCLogFileRotation
Bu seçenek şöyle kullanılıyor ancak log rotasyonu pek önerilmiyor.
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/home/GCEASY/gc.log 
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20M"

Hiç yorum yok:

Yorum Gönder