Mais conteúdo relacionado
Semelhante a Systemanalyse von OutOfMemory Fehlern in Java-Anwendungen (20)
Mais de Communardo GmbH (20)
Systemanalyse von OutOfMemory Fehlern in Java-Anwendungen
- 1. OutOfMemory
Analyse von Laufzeitproblemen bei
Java / J2EE Appliakationen
Communardo Software GmbH
Marko Seifert
Dresden, 22.05.2008
- 2. Motivation und Gliederung
• analysiere OutOfMemory Probleme seit ca. 2 Jahren in
verschiedenen Projekten
• Einsatz verschiedener Tools
• Strukturiertes Vorgehen beim Analysieren
• Gliederung:
• Grundlagen
• Betriebskennzahlen ermitteln
• Analyse von Speicherdumps (MemoryLeaks?)
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 2
- 4. Speicher für den Java-Prozess
• Die Process Size
• maximale Speicher für
einen Prozess
• ist abhängig vom Betriebssystem
und von der Hardware
(4 GB bei 32 Bit, HugeMem-
Kernel, Linux)
• wird benötigt für:
• Heap
• Native Code
• Permanent Generation
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 4
- 5. Speicher für den Java-Prozess
Der Heap
• Speicher für die Erzeugung
der Objekte
Object a = new Object ();
• Größe ist begrenzt; wird nichts
angegeben gelten Systemdefaults
• 2 Bereiche:
• New Generation
• Anlegen von
neuen Objekten
• Old Generation
• Verwaltung der älteren, noch benötigten Objekte
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 5
- 6. Speicher für den Java-Prozess
• New Generation ist unterteilt in:
• Eden:
• Anlegen der
Objekte
• 2 Survivior Bereiche (From/To)
• Zwischenspeicher für das Ermitteln von noch
lebenden Objekte (Referenzen von lebenden
Threads auf die Objekte)
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 6
- 7. Heap-Parameter
• Heapsize explizit angegeben
JAVA_VM_ARGS=quot;$JAVA_VM_ARGS -Xms1024m -Xmx1024mquot;
• Servereinstellung (Heapverteilung old:new 1:3)
JAVA_VM_ARGS=quot;$JAVA_VM_ARGS -serverquot;
• Heapdump bei OOM
JAVA_VM_ARGS=quot;-XX:+HeapDumpOnOutOfMemoryErrorquot;
• Parallele GC
JAVA_VM_ARGS=quot;$JAVA_VM_ARGS
-XX:+UseParallelGC
-XX:UseParallelOldGCquot;
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 7
- 9. Speicher für Prozess
• Aktuelle Speicher für einen Prozess
top -p <PID> (Linux)
• Betriebssystem bestimmen (Kernelversion)
uname -r (Linux)
• In Betriebssystemspezifikation nachlesen (z.B. bei RedHat)
http://www.redhat.com/docs/manuals/enterprise/RHEL-4-
Manual/release-notes/as-x86/
Red Hat Enterprise Linux 4 includes a kernel known as the hugemem
kernel. This kernel supports a 4GB per-process user space (versus
3GB for the other kernels), and a 4GB direct kernel space.
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 9
- 10. Speicher für Prozess
• OutOfMemory in Native Code
• Process Size zu klein
Process Size – Heap – PermSize = Speicher für Native Code
• MemoryLeak in Native Code
• File.deleteOnExit(); //JDK
• Kernel beendet Java-Prozess
An unexpected exception has been detected in
native code outside the VM.
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 10
- 11. GC-Verlauf überwachen
• GC-Logging aktivieren
JAVA_VM_ARGS=quot;$JAVA_VM_ARGS
-verbose:gc -Xloggc:var/logs/gc.log
-XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC
-XX:+PrintTenuringDistributionquot;
• gc.log mit HPjtune
auswerten
• Kurz vor OutOfMemory
kann durch GC kaum
noch Speicher freigegeben
werden
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 11
- 12. Monitoring mit JMeter
Einrichten eines Users für die Management-Seiten
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
...
<role rolename=quot;adminquot;/>
<role rolename=quot;managerquot;/>
<user username=quot;adminquot;
password=quot;adminquot;
roles=quot;admin, managerquot;/>
...
</tomcat-users>
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 12
- 13. Monitoring mit JMeter
Tomcat Monitoring URL
http://HOST:PORT/manager/status?XML=true
<?xml version=quot;1.0quot; encoding=quot;utf-8quot;?>
<status>
<jvm>
<memory free='206.306.536'
total='424.214.528'
max='492.175.360'/>
</jvm>
...
</status>
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 13
- 14. Monitoring mit JMeter
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 14
- 15. Monitoring mit JMeter
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 15
- 16. JMX und JConsole
• JMX Konfiguration
JAVA_VM_ARGS=quot;$JAVA_VM_ARGS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=8086
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=
falsequot;
• jconsole [processID]
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 16
- 17. JMX und JConsole
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 17
- 18. Profilerseite (CAE) + shell script
• Auswertung von Apache Logfiles per shell script
• Profilerseite der CAE mit shell script ausgelesen und in CSV-Datei
geschrieben
• Auswertung und Visualisierung mit Excel
Internet 1.2
Datum: 10.05.2007 11.05.2007 12.05.2007 13.05.2007 14.05.2007 15.05.2007 16.05.2007
alle Aufrufe: 560966 702092 514152 443465 334097 561757 568876
Google: 56038 39199 4669 69170 3578 5221 6276
statisches PDF: 2840 5991 2682 2341 1203 3057 2272
PDFReactor: 2530 2611 197 4163 142 195 243
neue Session
(exkl. URL Rewriting): 52150 43027 18085 57074 14474 20191 21947
Google Session: 37823 30581 967 55440 1490 814 1385
ask Session: 7041 6178 625 11396 484 642 865
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 18
- 19. © Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 19
- 21. Speicherdump erstellen
• Histogramm
/.../jdk1.5.0/bin/jmap -histo <PID> > hist.txt
• Binary HeapDump (komplett)
/.../jdk1.5.0/bin/jmap -heap:format=b <PID>
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 21
- 22. JHat (JDK 1.6)
java -Xmx2048m -jar hat.jar ../java_pid27280.hprof
Started HTTP server on port 7000
Reading from ../java_pid27280.hprof...
Dump file created Tue Nov 20 14:22:07 CET 2007
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 22
- 23. SAP Memory Analyzer
• kostenloses Tool zum Analysieren von großen Memory Dumps
• sehr schnelle (durch Indizierung)
• sehr gute Analysemöglichkeiten
• Bearbeitung großer Dumps
• als Eclipse Plugin oder eigenständige Applikation (RPC-
Framework)
• Artikel im JavaMagazin (11/2007 S.105)
• Download:
https://www.sdn.sap.com/irj/sdn/java?rid=/library/uuid/a0f47c83-5ef6-
2910-2c89-b75d296edef9
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 23
- 24. © Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 24
- 25. © Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 25
- 26. © Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 26
- 27. © Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 27
- 28. OutOfMemory
• MemoryLeak durch CGLIB (Hibernate, EHCache, CoreMedia
Dataviews, …)
• ThreadLocal Variablen und ThreadPool des Tomcats
http://opensource.atlassian.com/confluence/spring/pages/viewpage.a
ction?pageId=2669
© Communardo Software GmbH · Fon +49 (0) 351 833820 · info@communardo.de · www.communardo.de
Folie 28