SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Garbage Collection verstehen 
3 JVMs – ähnlich aber doch verschieden
• Langsam? Wann und Warum 
• Auswirkungen 
• Jede JVM ist anders 
• GC Strategien & Richtiges Tuning 
• Probleme und Lösungen
Die Basics
GC auf einen Blick 
Nicht Erreichbare 
Objekte  Garbage 
Vergessene Referenz 
 Memory Leak 
Erreichbare Objekte 
GC Roots
Viele (über)lebende Objekte 
= 
Lange Garbage Collection
Generational Heap 
• Wenige Allokationen 
• Viele Überlebende 
• Viele Allokationen 
• Wenige Überlebende 
Marking Phase 
Marking Phase 
Speicher nach Sweep Nach Copy Phase
Performance Auswirkungen 
Runtime Suspensions
Suspensions 
• Alle Anwendungs Threads pausieren 
• Auch Young/Minor Collections! 
• Antwortzeiten  1:1 
• Durchsatz  Exponentiell
Suspensions 
Serial Collector Parallel Collector 
Pause 
Pause 
Remark 
Concurrent 
Mark 
Concurrent Collector 
Concurrent 
Sweep
Performance Auswirkungen 
Fragmentierung
Fragmentierung 
Marking Phase 
Speicher nach Sweep
Compacting GC 
• Young Generation  Copy Collection 
• Old Generation (außer CMS) 
Fragmentierter Speicher 
Speicher nach Kompaktifizierung
Performance Auswirkungen 
CPU Verbrauch
CPU Verbrauch 
• Zeit ≈ CPU Zeit 
• Seriell <≈ Parallel 
• Je mehr CPUs desto kürzer Suspension 
• Negative Auswirkung auf andere 
Prozesse 
• CMS  single Threaded
Die Unterschiede 
Jede JVM ist anders
Young Tenured 
Eden 
Survior 
Survior 
SUN/ORACLE JVM
ORACLE JROCKIT
Heap 
• Generational 
Nursery Tenured 
Keep 
Area 
oder 
• Kontinuierlicher Heap
Mostly Concurrent 
Mark and Sweep 
Pause 
Final Remark 
Concurrent Mark 
& remark 
Sweep 1. Hälfte 
Sweep 2. Hälfte 
Pause
Compacting Windows 
• Inkrementelles Compacting 
• Auch bei CMS 
Fragmentierter Speicher
Thread-Lokale Allokation 
• Separatere Heap Bereiche 
• Dynamische Zuteilung 
• Keine Synchronisation 
Schnellere Allokation
„GROßE“ UND „KLEINE“ 
OBJEKTE
Permanent Generation? 
• Klassen werden wie Objekte behandelt 
• Sofortige Garbage Collection möglich!
IBM JVM
Die Unterschiede 
• Kontinuierlicher Heap ist Standard 
• Allocate und Survivor 
• „Große“ und „Kleine“ Objekte 
• Keine Permanent Generation 
Nursery Tenured 
Allocate 
Survior
Garbage Collection 
TUNING
Das Ziel vor Augen halten
GC Strategien 
Antwortzeit Durchsatz 
Kontinuierlicher Heap Kleine Anwendungen, 
Clients, evtl mit CMS 
Ja, Parallel GC 
Generational Heap Ja Ja, parallel GC 
Concurrent Mark and 
Sweep 
Server Nein, außer wenn 
Suspension sensitiv 
Parallel GC Young, Nicht old Ja
Richtig Messen 
• Suspensions messen 
 Auswirkung auf Antwortzeit 
• Garbage Collection Zeit/CPU messen 
• Garbage Collection Häufigkeit messen
JMX Metriken
Echte Auswirkung
Auf die Größe kommt es an 
• Objekt stirb Young 
• Old Generation abspecken 
• Richtiges Verhältnis
Objekt Churning 
• Allokiere so viel du willst, aber 
– nicht zu viel 
– nicht zu lange 
• Cachen ist gut, aber 
– Nicht zu viel 
– Nicht zu kurz
PROBLEME, MYTHEN, 
LEGENDEN
Minor vs. Major 
• Minor Collections pausieren auch! 
• Old Generation ≠ Major Collection
Zu großer Heap 
• Lange und teure Garbage Collections 
• Caches 
– HTTP-Session as Cache 
– Soft/Weak Referenzen 
• Memory Leaks
Memory Leaks 
• Statische veränderliche Variablen 
• Thread Lokale Variablen 
• JNI 
• Equals/Hashcode 
• Bi-direktionale Referenzen
Bi-direktionale Referenzen 
Document doc = readXmlDocument(); 
Node child = 
doc.getDocumentElement().getFirstChild(); 
doc.removeNode(child); 
doc = null; 
// child hat eine Referenz auf doc, 
// daher doc wird nicht freigegeben
Classloader Probleme 
• Class Loader Leaks 
• Mehrfach geladene Klassen 
• Zu viele, große Klassen 
• Wiederholtes Laden
Out Of Memory 
• GC Thrashing 
• Transaktionaler Speicherverbrauch 
• Große temporare Objekte 
• Permanent Generation
Große Temp. Objekte 
byte tmpData[] = new byte [1024]; 
int offs = 0; 
do{ 
int readLen = bis.read (tmpData, offs, tmpData.length - 
offs); 
if (readLen == -1) 
break; 
offs+= readLen; 
if (oofs == tmpData.length){ 
byte newres[] = new byte[tmpData.length + 1024]; 
System.arraycopy(tmpData, 0, newres, 0, tmpData.length); 
tmpData = newres; 
} 
} while (true);
FRAGEN 
Michael Kopp 
michael.kopp@dynatrace.com 
@mikopp 
http://blog.dynatrace.com

Weitere ähnliche Inhalte

Andere mochten auch

What does performance mean in the cloud
What does performance mean in the cloudWhat does performance mean in the cloud
What does performance mean in the cloudMichael Kopp
 
Releasing fast code - The DevOps approach
Releasing fast code - The DevOps approachReleasing fast code - The DevOps approach
Releasing fast code - The DevOps approachMichael Kopp
 
The China Analyst September 2011
The China Analyst   September 2011The China Analyst   September 2011
The China Analyst September 2011dirkkotze
 
The China Analyst March 2011
The China Analyst   March 2011The China Analyst   March 2011
The China Analyst March 2011dirkkotze
 
Ruxit - How we launched a global monitoring platform on AWS in 80 days.
Ruxit - How we launched a global monitoring platform on AWS in 80 days. Ruxit - How we launched a global monitoring platform on AWS in 80 days.
Ruxit - How we launched a global monitoring platform on AWS in 80 days. Alois Reitbauer
 
Digital Customer Experiences in the age of faceless applications
Digital Customer Experiences in the age of faceless applicationsDigital Customer Experiences in the age of faceless applications
Digital Customer Experiences in the age of faceless applicationsDynatrace
 
What it means to be fast in your industry
What it means to be fast in your industryWhat it means to be fast in your industry
What it means to be fast in your industryAlois Reitbauer
 
Utilize a Disruptive Analytics Approach to Deliver Great Digital Experiences
Utilize a Disruptive Analytics Approach to Deliver Great Digital ExperiencesUtilize a Disruptive Analytics Approach to Deliver Great Digital Experiences
Utilize a Disruptive Analytics Approach to Deliver Great Digital ExperiencesRyan Bateman
 
ADI: Super Bowl 50 Will Be Tipping Point For Ad Industry
ADI: Super Bowl 50 Will Be Tipping Point For Ad IndustryADI: Super Bowl 50 Will Be Tipping Point For Ad Industry
ADI: Super Bowl 50 Will Be Tipping Point For Ad IndustryAdobe
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecMartin Etmajer
 
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
10+ Deploys Per Day: Dev and Ops Cooperation at FlickrJohn Allspaw
 

Andere mochten auch (12)

What does performance mean in the cloud
What does performance mean in the cloudWhat does performance mean in the cloud
What does performance mean in the cloud
 
Releasing fast code - The DevOps approach
Releasing fast code - The DevOps approachReleasing fast code - The DevOps approach
Releasing fast code - The DevOps approach
 
The China Analyst September 2011
The China Analyst   September 2011The China Analyst   September 2011
The China Analyst September 2011
 
The China Analyst March 2011
The China Analyst   March 2011The China Analyst   March 2011
The China Analyst March 2011
 
Ruxit - How we launched a global monitoring platform on AWS in 80 days.
Ruxit - How we launched a global monitoring platform on AWS in 80 days. Ruxit - How we launched a global monitoring platform on AWS in 80 days.
Ruxit - How we launched a global monitoring platform on AWS in 80 days.
 
Digital Customer Experiences in the age of faceless applications
Digital Customer Experiences in the age of faceless applicationsDigital Customer Experiences in the age of faceless applications
Digital Customer Experiences in the age of faceless applications
 
What it means to be fast in your industry
What it means to be fast in your industryWhat it means to be fast in your industry
What it means to be fast in your industry
 
Utilize a Disruptive Analytics Approach to Deliver Great Digital Experiences
Utilize a Disruptive Analytics Approach to Deliver Great Digital ExperiencesUtilize a Disruptive Analytics Approach to Deliver Great Digital Experiences
Utilize a Disruptive Analytics Approach to Deliver Great Digital Experiences
 
World wide web
World wide webWorld wide web
World wide web
 
ADI: Super Bowl 50 Will Be Tipping Point For Ad Industry
ADI: Super Bowl 50 Will Be Tipping Point For Ad IndustryADI: Super Bowl 50 Will Be Tipping Point For Ad Industry
ADI: Super Bowl 50 Will Be Tipping Point For Ad Industry
 
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpecTest-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
Test-Driven Infrastructure with Ansible, Test Kitchen, Serverspec and RSpec
 
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
 

Ähnlich wie JAX 2011 - Garbage collection verstehen

Robustes Testen mit Selenium
Robustes Testen mit SeleniumRobustes Testen mit Selenium
Robustes Testen mit Seleniumx-celerate
 
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas Gelf
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas GelfOSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas Gelf
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas GelfNETWAYS
 
Intro to scaling Databases
Intro to scaling DatabasesIntro to scaling Databases
Intro to scaling DatabasesHeiko Seebach
 
Nosql Hintergründe und Anwendungen
Nosql Hintergründe und AnwendungenNosql Hintergründe und Anwendungen
Nosql Hintergründe und AnwendungenAndy Whole
 
GWAVACon 2015: SEP - Backuplösungen auf dem Prüfstand
GWAVACon 2015: SEP - Backuplösungen auf dem PrüfstandGWAVACon 2015: SEP - Backuplösungen auf dem Prüfstand
GWAVACon 2015: SEP - Backuplösungen auf dem PrüfstandGWAVA
 
Microservices and Container Management with Mesosphere DC/OS
Microservices and Container Management with Mesosphere DC/OSMicroservices and Container Management with Mesosphere DC/OS
Microservices and Container Management with Mesosphere DC/OSRalf Ernst
 

Ähnlich wie JAX 2011 - Garbage collection verstehen (12)

Query Result Caching
Query Result CachingQuery Result Caching
Query Result Caching
 
Big Data & NoSQL
Big Data & NoSQLBig Data & NoSQL
Big Data & NoSQL
 
JavaScript Performance
JavaScript PerformanceJavaScript Performance
JavaScript Performance
 
Mercurial
MercurialMercurial
Mercurial
 
Robustes Testen mit Selenium
Robustes Testen mit SeleniumRobustes Testen mit Selenium
Robustes Testen mit Selenium
 
Boston webcast nv_me_2016-09
Boston webcast nv_me_2016-09Boston webcast nv_me_2016-09
Boston webcast nv_me_2016-09
 
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas Gelf
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas GelfOSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas Gelf
OSMC 2011 | Monitoring at large - die Welt ist nicht genug by Thomas Gelf
 
Intro to scaling Databases
Intro to scaling DatabasesIntro to scaling Databases
Intro to scaling Databases
 
Nosql Hintergründe und Anwendungen
Nosql Hintergründe und AnwendungenNosql Hintergründe und Anwendungen
Nosql Hintergründe und Anwendungen
 
GWAVACon 2015: SEP - Backuplösungen auf dem Prüfstand
GWAVACon 2015: SEP - Backuplösungen auf dem PrüfstandGWAVACon 2015: SEP - Backuplösungen auf dem Prüfstand
GWAVACon 2015: SEP - Backuplösungen auf dem Prüfstand
 
in memory datenbanken
in memory datenbankenin memory datenbanken
in memory datenbanken
 
Microservices and Container Management with Mesosphere DC/OS
Microservices and Container Management with Mesosphere DC/OSMicroservices and Container Management with Mesosphere DC/OS
Microservices and Container Management with Mesosphere DC/OS
 

JAX 2011 - Garbage collection verstehen

Hinweis der Redaktion

  1. Wie funktioniert GC eigentlich, GC Roots, traverse objects. Nicht erreichbare objekte?
  2. Das ist eine Krux und wir werden sehen das sich das durchzieht. Einerseits haben werden sehr viele kurzlebige Objekte erzeugt die der Garbage Collector effizient entfernt, andererseits haben heutige Applikationen eine immer groessere anzahl von lang lebigen Objekten.
  3. Der concurrent wird allerdings fast nur bei einem normallen mark and sweep. Also nicht in der young generation. Wir sehen hier schon das das ganze ein trade off ist. Es werden zwar die unterbrechungen kuerzer, allerdings steigt dadurch der CPU verbrauch. Das ist etwas das man immer bedenken muss, mann kann nur fuer eine seite tunen.
  4. Allokationen werden langsamer Sweep Phase wird langsamer OutOfMemory bei grossen objekten Vorteil des copy collectors
  5. Kompletter Heap Parallel CMS  gar nicht? Das gilt fuer die Sun JVM wohlgemerkt!
  6. Objekte im eden angelegt, dann in einen aktiven survivor promoted. Dann so oft hin und her kopiert bis die kriterien erfuellt sind. Das geht nicht immer. Young Gen Garantie! Missing perm generation. haellt
  7. Kontinuierlicher und Generationaler Heap
  8. Internal/external
  9. Response time vs. CPU Verbrauch aka Throughput.
  10. Das problem mit allokationen ist oftmals nicht einmal der GC selbst, sondern das allokieren an und fuer sich. Und natuerlich wenn ich mehr objekte erzeuge als im young platz haben.
  11. Caches  Soft Referenzen
  12. Sun jvm oom, wenn zuviel gc
  13. Ineffizienter Code Major Collections ohne ersichtlichen Grund Out Of Memory mit genügend freiem Speicher