SlideShare a Scribd company logo
• JVM Garbage Collection
•
September 03, 2012
Gökhan Özman
1
2
İçerik
1. GC Giriş
2. Java Bellek Modeli
3. GC Nesilleri
4. GC Çeşitleri
5. Nesne Referans Tipleri
6. Hotspot Vm Seçenekleri
3
Ne oluyor?
4
Garbage Collection(Çöp toplama)
5
Çöp ?
Ogrenci a=new Ogrenci();
Ogrenci b=new Ogrenci();
a=b;
ya da
a=null;
Garbage Collection Giriş
a
b
Ogrenci
Ogrenci
6
• finalize()
• System.gc()
• Runtime.gc()
Garbage Collection Giriş
Neden gc, ne işe yarar?
7
• Bellek geri dönüşümü
• JVM bütünlüğü
• Geliştirici verimliliği
Garbage Collection Giriş
8
• Stack
• Metotlar
• Lokal değişkenler
• Referans değişkenleri
• Heap
• Nesneler
• Sınıf değişkenleri
Java Bellek Modeli
Stack&Heap
9
Java Bellek Modeli
main() x
method2 car
method1 b c
p=0
q=0
Car object
stack
heap
Java Heap
10
Java Bellek Modeli
Heap
Young gen.
Old gen.
%33
Young gen.
11
Java Bellek Modeli
Eden Space
Survivor Space 1
Survivor Space 2
EDEN
12
Java Bellek Modeli
SURVIVOR
13
Java Bellek Modeli
Old gen.
14
Java Bellek Modeli
Old gen.
15
Java Bellek Modeli
Young gen. Old gen.
Java işlem alanı
16
Java Bellek Modeli
Bellek(İşletim Sistemi)
Java işlem alanı(java.exe)
Java nesne alanı(heap) Diğer...
Diğerleri
17
• Kalıcı alan
• Kod çevrim alanı
• Soket alanı
• Thread yığını
• Direk bellek alanı
• GC
Java Bellek Modeli
Kalıcı Alan(Perm gen.)
18
• Sınıfların metadata elemanları tutulur
• Web uygulamalarında OOM(Out of Memory) hatası
• -XX:PermSize=<deger>(initial)
• -XX:MaxPermSize=<deger>(max)
Java Bellek Modeli
Kod çevrim alanı
19
Java Bellek Modeli
Kod çevrim alanı
20
• Çok nadir bellek sorunu yaşanır
• Bu alanda yeterli bellek bulunamazsa
JVM büyük ihtimal çöker
Java Bellek Modeli
Soket alanı
21
• Her TCP bağlantısı 2 buffer içerir:
1. Alım için: ~37k
2. Gönderim için: ~25k
• Java kodu içerisinde ayarlanır.
• Bellek hatasından önce genelde diğer limitlerde hata
oluşur. Örn: IOException: Too many open files
Java Bellek Modeli
Thread stack
22
• Özel alan
• Belleğe dikkat
• -Xss
Java Bellek Modeli
Direk bellek alanı
23
• Heap dışında belleği kullanma imkanı !
• Java.nio.ByteBuffer.allocateDirect
• -XX:MaxDirectMemorySize=
Java Bellek Modeli
24
Nesne Yaşamdöngüsü
Yaratılma
Kullanım
Görünmezlik
ErişilemezlikToplanma
Sonlandırılma
Temizlenme
25
• Yaratılma Durumu
• Nesne için gerekli bellek ayrılmıştır
• Nesne yaratımı başlamıştır.
• Super sınıf constructor u çağrılmıştır
Nesne Yaşamdöngüsü
26
• Kullanım Durumu
• En az bir strong referans tarafından erişim vardır.
Nesne Yaşamdöngüsü
27
• Görünmezlik Durumu
• Herhangi bir strong referans kalmadıysa
Nesne Yaşamdöngüsü
28
• Erişilemezlik Durumu
• Collection için aday
• Circular referanslar sayılmaz
Nesne Yaşamdöngüsü
Erişilmezlik Durumu
29
Java Bellek Modeli
main()
buildCar()
Car
Engine
Stack
Heap
30
• Toplanma Durumu
• GC nesnenin artık erişilemez durumda oldugunu tespit eder
• Finalize()
• Finalized
• Deallocated
Nesne Yaşamdöngüsü
31
• Strong
• Soft
• Weak
• Phantom
Nesne Referans Tipleri
32
• Strong Referans
• En çok kullandığımız referans tipi
Person person = new Person();
person = null;
Nesne Referans Tipleri
33
• Soft Referans
• Cache için oldukça uygundur.
• OutOfMemory e kadar dayanır.
Person person = new Person();
SoftReference<Person> softPerson = new
SoftReference<Person>(person);
Nesne Referans Tipleri
34
• Weak Referans
• Sadece weak referans kalmışsa gc toplar.
Person person = new Person();
WeakReference<Person> weakPerson = new
WeakReference<Person>(person);
Nesne Referans Tipleri
35
• Phantom Referans
• finalize() !!!
• Nesneye erişim için kullanılmaz
ReferenceQueue q = new ReferenceQueue();
PhantomReference phantomImage= new
PhantomReference(bigImage, q);
q.remove();
Nesne Referans Tipleri
Algoritmalar
36
• Referans sayma
• Referans takip etme
GC Çeşitleri
Yöntemler
37
• Sıkıştırma(compacting collector)
• Kopyalama(copying collector)
• Nesillere ayırma(generational collector)
GC Çeşitleri
Yaklaşımlar(çalışma zamanı bakımından)
38
• Stop the World
• Incremental
• Concurrent
GC Çeşitleri
GC Zamanları
39
• Heap büyüklüğüne göre değişir.
• Minor collection
• Major collection
GC Çeşitleri
-verbose:gc
40
GC Çeşitleri
Toplam young gen. alanı Toplam old gen. alanı Toplam perm gen. alanı
Full gc süresi Old gen. de kalan nesneler Perm gen. boyutu
Serial Collector
41
Collector Çeşitleri
GC GC
Uygulama Uygulama Uygulama
Paralel(Throughput) Collector
42
Collector Çeşitleri
GC GC
Uygulama Uygulama Uygulama
Concurrent Mark&Sweep(CMS) Collector
43
Collector Çeşitleri
GC GCUygulama Uygulama Uygulama
initial
mark
concurrent
mark
remark concurrent
sweep
Gargabe First Collector
44
• Garbage First (G1) Collector
Total Java Heap
Collector Çeşitleri
Region 1 Region 2 Region 3 Region 4 Region 5 Region n...
Gargabe First Collector
45
• Garbage First (G1) Collector
• -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC
• -XX:MaxGCPauseMillis=n
• -XX:G1HeapRegionSize=n
• -XX:ParallelGCThreads=n
Collector Çeşitleri
Heap/Generation Sizing
46
• Heap Size: -Xms, -Xmx
Örn: Xms 128m -Xmx 1g
• -XX:MinHeapFreeRatio=40
GC sonrası kalan min. heap miktarı. tavsiye edilen miktar %40
• -XX:MaxHeapFreeRatio=70
GC sonrası kalan max. heap miktarı. tavsiye edilen miktar %70
• -XX:NewRatio=2
new/old generation oranı
• -XX:NewSize=128m new generation büyüklük degeri.
• -XX:SurvivorRatio=3
eden/survivor space oranı
HotSpot VM Options
Heap/Generation Sizing
47
• Permanent Size:
• -XX:PermSize -XX:MaxPermSize
• Stack Size :
• -Xss 128k veya -XX:ThreadStackSize=128k
• Solaris x86 nın default verdiği değer 512k
HotSpot VM Options
GC Davranışı ile ilgili parametreler
48
• -XX:MaxTenuringThreshold
• Tenuring Threshold: Young Gen’deki canlı bir objenin kaç minor collection süresi
boyunca hala canlıysa, «promote» olması gerektiğini ifade eden bir değer
• XX:+DisableExplicitGC
• Explicit gc yi kapat. System.gc()’yi çağırdığınız zaman GC tetiklenmez
• XX:ParallelGCThreads=n ve -XX:ConcGCThreads=m (default: CPU sayısı
kadar)
• Parallel ve CMS collector thread sayıları
• -XX:CMSInitiatingOccupancyFraction=90
• CMS’i geç başlatmak: Old’un %90’ı dolmadan CMS’i başlatma
• -XX:+CMSClassUnloadingEnabled
• CMS’in Perm Gen’i temizlemesi için
HotSpot VM Options
Debugging
49
• VM hatalarını belli bir file’a yazdır:
• -XX:ErrorFile=./hs_err_pid<pid>.log
• Out of memory olduğuda «heap dump» al:
• XX:+HeapDumpOnOutOfMemoryError
• -XX:HeapDumpPath=./java_pid<pid>.hprof
• Hata ve out of memory durumlarında aksiyon almak
• -XX:OnError="<cmd args>;<cmd args>"
• -XX:OnOutOfMemoryError="<cmd args>; <cmd args>"
HotSpot VM Options

More Related Content

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

Java for telco_gc

Editor's Notes

  1. Stop the WorldGc sırasında uygulamanın çalışmasını durdururSerial collector minor ve major collection için bunu kullanırThrougput colector major collection için bunu kullanırIncrementalGc ara ara uygulamanın çalışmasına izin verirJava collector leri bunu uygulamazConcurrentUygulama ile birlikte çalışırThroughput major collection da kullanırCMS major ve minor collection için kullanır
  2. Heap büyüklüğüne göre değişir.Heap alanı küçük ise, gc kısa sürer ancak heap küçük olduğu için çabuk dolar ve sık gc ye neden olur.Heap alanı büyük ise, gc uzun sürer fakat heap büyük olduğu için daha geç dolar ve daha seyrek gc yapılır.Minor collectionYoung space doldugunda olurMajor collectionTenured/Old space dolduğunda olur.
  3. Full GC major collection yapıldığını gösterir. GC yazsaydı minor collection yapıldığı anlamına gelirdi
  4. Tek thread ile çalışırStop-the-world tipi collector Küçük uygulamalar için uygundur.-XX:+UseSerialGC
  5. Parallel (Throughput)CollectorBirden fazla thread ile toplama yapar.Serial collector ün çok threadlisi denebilir ancak tek cpu da serial collector un performansını göstermezYoung gen i çok cpu ile paralel toplarOld gen i aynı serial collector gibi toplar.Büyük batch uygulamalar, faturalama, hesaplama uygulamaları için uygundur-XX+UseParallelGCParallel Old gen. CollectorYoung gen i parallel collector gibi toplarOld gen i serial collector gibi toplar ancak birden fazla thread ile.-XX+UseParallelOldGC-XX:ParallelGCThreads=&lt;value&gt; ile thread sayısı belirlenir.
  6. App. threadleri ile birlikte eşzamanlı toplama yaparToplama aşamalarıinitial markconcurrent markremarkconcurrent sweepCompaction yapmazÇok kısa sürelerle pause yaparCevap zamanının önemli olduğu telekom, finans uygulamaları için uygundur.-XX+UseConcMarkSweepGC
  7. Garbage First (G1) CollectorHeap eşit büyüklükte region lara bölünmüştür.young/old gen. kavramı yok Yaşayan nesneler survivor regionlarına taşınır.Boşalan region lar hemen toplanır.Kısmen boş olanlar zamanla temizlenir.Gelecekte CMS in yerini alması planlanıyor.Compacting var.Java 7 ile stable hale geldiBüyük heap(&gt;6gb) ve düşük gc zamanı (&lt;0.5 sec)gerektiren uygulamalar için uygundur.