SlideShare une entreprise Scribd logo
1  sur  63
Télécharger pour lire hors ligne
JVM Tuning
Lo que debes saber antes de subir a producción
@edusanchezcon
JVM Tuning
Lo que debes saber antes de subir a producción
@edusanchezcon
Sobre mí
Eduardo Sánchez
@edusanchezcon
github.com/EduSanchezCon
Consultor tecnológico en
Qué vamos a ver
* Tests de carga
* Tuning de memoria
* Tuning de rendimiento
Suda en desarrollo
para no sangrar en producción
@edusanchezcon
Tests de carga
Hay que probar un uso similar a la que tendrá en producción
Carga proporcional
Funcionalidad coherente
Entorno parecido
@edusanchezcon
Tests de carga: Medir y Monitorizar
Medir para saber cuánto
Tiempo de respuesta
Operaciones / Tiempo
Tiempo total por lote
Monitorizar para saber por qué
Sistema: CPU, Memoria, Disco
JVM: Memoria (Heap), GCs
Logs, Sampling, Profilers
@edusanchezcon
Load Test
Uso similar al de producción
Tests de carga: Tipos
@edusanchezcon
Capacity Test
Degradación en función de la carga
Tests de carga: Tipos
@edusanchezcon
Stress Test
Comportamiento ante una carga por encima de sus capacidades
Tests de carga: Tipos
@edusanchezcon
Recovery Test
Recuperación tras un desastre (fallo de BD, llenado de disco…)
Tests de carga: Tipos
@edusanchezcon
Soak Test
Degradación en función del tiempo
Tests de carga: Tipos
@edusanchezcon
JMeter, LoadUI, WebLoad, Gatling
JVisualVM, JConsole, Java Mission Control, Java Flight Recorder
Tests de carga: Herramientas
Y mucho más: Grafana, JMX events, integración en CI…
Qué vamos a ver
* Tests de carga
* Performance Tuning
* Memory Tuning
JVM
Unboxing
@edusanchezcon
Process Memory
La memoria en la JVM
@edusanchezcon
Heap
Metaspace
Code
Cache
Thread
N
Thread
2
Thread
1
La memoria en la JVM
@edusanchezcon
Young Generation
Metaspace
Code
Cache
Old Generation
Eden survivor
1 2
compressed
class space
PC Register
JVM Stack
Native Stack
Thread
N
La memoria en la JVM
@edusanchezcon
La memoria en la JVM (JDK ≤ 7)
Young Generation
Thread
N
Old Generation
Eden survivor
1 2
PC Register
JVM Stack
Native Stack
PermGen
Code
Cache
@edusanchezcon
¿Cómo se gestiona la Memoria?
No se libera memoria explícitamente
El Garbage Collector libera lo que ya no se usa
@edusanchezcon
C
B
D
E
N
A J
H
I
F
G
M
K
L
Q
P
¿Cómo se detecta lo que ya no se usa?
@edusanchezcon
C
B
D
E
N
A J
H
I
F
G
M
K
L
Q
P
¿Cómo se detecta lo que ya no se usa?
@edusanchezcon
C
B
D
E
N
A J
H
I
F
G
M
K
L
Q
P
static
Thread
¿Cómo se detecta lo que ya no se usa?
@edusanchezcon
C
B
D
E
N
A
J
H
I
F
G
M
K
L
Q
P
GC Roots
Reachable Objects
Non Reachable Objects
¿Cómo se detecta lo que ya no se usa?
@edusanchezcon
C
B
D
E
A
J
H
I
F
G
KP
GC Roots
Reachable Objects
¿Cómo se detecta lo que ya no se usa?
Hipótesis generacional
Objetos, peces,
la mayoría mueren jovenes
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Old GenerationEden
Survivors
1 2
Generational Collection
@edusanchezcon
Serial GC
Parallel GC
G1 GC
Concurrent Mark & Sweep
Z GC
Epsilon GC
Garbage Collectors
@edusanchezcon
Heap: Problemas comunes
OutOfMemoryError: Java heap space|GC overhead limit exceeded
Dimensionamiento incorrecto de la memoria
Memory leak
No Referenced Referenced
Not Used Used
{
leak
@edusanchezcon
Heap: Diagnóstico
Heap Dumps
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path-to-hd
jcmd <pid> GC.heap_dump <path>
JVisualVM, JConsole, Java Mission Control
Sin Full GC previo: jcmd <pid> GC.heap_dump -all <path>
Análisis: Eclipse Memory Analyzer Tool
Ahí te hemos dejado el dump
@edusanchezcon
Monitorización continua del tamaño del Heap
Configuración de frameworks/librerías de terceros
Heap: Recomendaciones
-Xms = -Xmx
@edusanchezcon
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:<file-path>
Java 9+ -xlog
Garbage Collector: GC Logs
SIEMPRE ACTIVADO EN PRODUCCIÓN
@edusanchezcon
Garbage Collector: GC Logs
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Timestamp absoluto del gc
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Timestamp relativo al inicio de la JVM
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Causa del GC
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Región de memoria
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Espacio antes y después del GC (capacidad de la región de memoria)
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Espacio antes y después dell GC (capacidad total del Heap)
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Tiempo real
Garbage Collector: GC Logs
@edusanchezcon
2018-11-19T10:49:38.496-0100: 17.830:
[Full GC (Ergonomics)
[PSYoungGen: 256K->0K(43008K)]
[ParOldGen: 46473K->1524K(46592K)] 46729K->1524K(89600K),
[Metaspace: 5450K->5442K(1056768K)],
0.0075023 secs] [Times: user=0.03 sys=0.00, real=0.01 secs]
Tiempo de CPU
Garbage Collector: GC Logs
Qué vamos a ver
* Tests de carga
* Memory Tuning
* Performance Tuning
“Premature optimization
is the root of all evil”
Donald Knuth
@edusanchezcon
Nuestro código vs lo que se ejecuta
Interprete
Bytecode
Compilador
Código máquina
optimizado
@edusanchezcon
Nuestro código vs lo que se ejecuta
Interprete
Bytecode
C1
Código máquina
C2
Código máquina
optimizado
@edusanchezcon
Optimizaciones del JIT Compiler
‣ Trivial inlining
‣ Call graph inlining
‣ Tail recursion elimination
‣ Virtual call guard optimizations
‣ Local data flow analyses and optimizations
‣ Register usage optimization
‣ Simplifications of Java idioms
‣ Code reordering, splitting, and removal
‣ Loop reduction and inversion
‣ Loop striding and loop-invariant code motion
‣ Loop unrolling and peeling
‣ Loop versioning and specialization
‣ Exception-directed optimization
‣ Switch analysis
‣ Global data flow analyses and optimizations
‣ Partial redundancy elimination
‣ Escape analysis
‣ GC and memory allocation optimizations
‣ Synchronization optimizations
@edusanchezcon
Ciclo de performance tuning
Determinar la carga máxima
Localizar el cuello de botella Solucionar el problema
Load Test
Sampler/Profiler
@edusanchezcon
Ejemplo práctico
-XX:+UnlockCommercialFeatures -XX:FlightRecorder
@edusanchezcon
Operaciones de Entrada / Salida
Cuellos de botella frecuentes
Ejecutar muchas veces lo mismo (de manera innecesaria)
Dimensionamiento ineficiente de pools de hilos
Wanna go faster?
No GCs
Native Memory
Specialized Collections
CharSequence
? @edusanchezcon

Contenu connexe

Tendances

Introduction to data flow management using apache nifi
Introduction to data flow management using apache nifiIntroduction to data flow management using apache nifi
Introduction to data flow management using apache nifiAnshuman Ghosh
 
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...inwin stack
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3Linaro
 
How to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsHow to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsSandesh Rao
 
LCA14: LCA14-418: Testing a secure framework
LCA14: LCA14-418: Testing a secure frameworkLCA14: LCA14-418: Testing a secure framework
LCA14: LCA14-418: Testing a secure frameworkLinaro
 
MariaDB Galera Cluster
MariaDB Galera ClusterMariaDB Galera Cluster
MariaDB Galera ClusterAbdul Manaf
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...ScyllaDB
 
Synchronization linux
Synchronization linuxSynchronization linux
Synchronization linuxSusant Sahani
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuningGuy Harrison
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuningSimon Huang
 
Oracle 12c and its pluggable databases
Oracle 12c and its pluggable databasesOracle 12c and its pluggable databases
Oracle 12c and its pluggable databasesGustavo Rene Antunez
 
OPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialOPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialDalton Valadares
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slidesMohamed Farouk
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialColin Charles
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageKernel TLV
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaionAngel Boy
 
The Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - PresentationThe Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - PresentationMarkus Michalewicz
 

Tendances (20)

Introduction to data flow management using apache nifi
Introduction to data flow management using apache nifiIntroduction to data flow management using apache nifi
Introduction to data flow management using apache nifi
 
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...
Intel - optimizing ceph performance by leveraging intel® optane™ and 3 d nand...
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
 
How to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata EnvironmentsHow to Use EXAchk Effectively to Manage Exadata Environments
How to Use EXAchk Effectively to Manage Exadata Environments
 
LCA14: LCA14-418: Testing a secure framework
LCA14: LCA14-418: Testing a secure frameworkLCA14: LCA14-418: Testing a secure framework
LCA14: LCA14-418: Testing a secure framework
 
MariaDB Galera Cluster
MariaDB Galera ClusterMariaDB Galera Cluster
MariaDB Galera Cluster
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
 
Synchronization linux
Synchronization linuxSynchronization linux
Synchronization linux
 
Oracle Database Cloud Service
Oracle Database Cloud ServiceOracle Database Cloud Service
Oracle Database Cloud Service
 
Linux device drivers
Linux device drivers Linux device drivers
Linux device drivers
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
Oracle 12c and its pluggable databases
Oracle 12c and its pluggable databasesOracle 12c and its pluggable databases
Oracle 12c and its pluggable databases
 
One PDB to go, please!
One PDB to go, please!One PDB to go, please!
One PDB to go, please!
 
OPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build TutorialOPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build Tutorial
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
The Complete MariaDB Server tutorial
The Complete MariaDB Server tutorialThe Complete MariaDB Server tutorial
The Complete MariaDB Server tutorial
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Advanced heap exploitaion
Advanced heap exploitaionAdvanced heap exploitaion
Advanced heap exploitaion
 
The Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - PresentationThe Oracle RAC Family of Solutions - Presentation
The Oracle RAC Family of Solutions - Presentation
 

Similaire à JVM tuning: lo que debes saber antes de subir a producción

JVM tuning: Lo que debes saber antes de subir a producción
JVM tuning: Lo que debes saber antes de subir a producciónJVM tuning: Lo que debes saber antes de subir a producción
JVM tuning: Lo que debes saber antes de subir a producciónEduardo Sánchez Contreras
 
Nodejs.introduccion
Nodejs.introduccionNodejs.introduccion
Nodejs.introduccionkillfill
 
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...RootedCON
 
(Codemotion 2014) JVM GC: WTF?!
(Codemotion 2014) JVM GC: WTF?!(Codemotion 2014) JVM GC: WTF?!
(Codemotion 2014) JVM GC: WTF?!Alonso Torres
 
Primeros pasos con Logstash y Beats
Primeros pasos con Logstash y BeatsPrimeros pasos con Logstash y Beats
Primeros pasos con Logstash y BeatsUllyCarolinneSampaio
 
Presentacion password cracking_madrid_2019
Presentacion password cracking_madrid_2019Presentacion password cracking_madrid_2019
Presentacion password cracking_madrid_2019Labs CSL
 
Big Data. Complejidad,algoritmos y su procesamiento
Big Data. Complejidad,algoritmos y su procesamientoBig Data. Complejidad,algoritmos y su procesamiento
Big Data. Complejidad,algoritmos y su procesamientoVictoria López
 
Computación evolutiva no tradicional
Computación evolutiva no tradicionalComputación evolutiva no tradicional
Computación evolutiva no tradicionalJuan J. Merelo
 
Nodejs.introduccion
Nodejs.introduccionNodejs.introduccion
Nodejs.introduccionkillfill
 

Similaire à JVM tuning: lo que debes saber antes de subir a producción (13)

JVM tuning: Lo que debes saber antes de subir a producción
JVM tuning: Lo que debes saber antes de subir a producciónJVM tuning: Lo que debes saber antes de subir a producción
JVM tuning: Lo que debes saber antes de subir a producción
 
Nodejs.introduccion
Nodejs.introduccionNodejs.introduccion
Nodejs.introduccion
 
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...
Juan Antonio Calles & Patricia Rada - Biohacking: Almacenando información en ...
 
(Codemotion 2014) JVM GC: WTF?!
(Codemotion 2014) JVM GC: WTF?!(Codemotion 2014) JVM GC: WTF?!
(Codemotion 2014) JVM GC: WTF?!
 
Archlinux
ArchlinuxArchlinux
Archlinux
 
Primeros pasos con Logstash y Beats
Primeros pasos con Logstash y BeatsPrimeros pasos con Logstash y Beats
Primeros pasos con Logstash y Beats
 
Leeme
LeemeLeeme
Leeme
 
Presentacion password cracking_madrid_2019
Presentacion password cracking_madrid_2019Presentacion password cracking_madrid_2019
Presentacion password cracking_madrid_2019
 
Big Data. Complejidad,algoritmos y su procesamiento
Big Data. Complejidad,algoritmos y su procesamientoBig Data. Complejidad,algoritmos y su procesamiento
Big Data. Complejidad,algoritmos y su procesamiento
 
7 curso
7 curso7 curso
7 curso
 
Computación evolutiva no tradicional
Computación evolutiva no tradicionalComputación evolutiva no tradicional
Computación evolutiva no tradicional
 
Nodejs.introduccion
Nodejs.introduccionNodejs.introduccion
Nodejs.introduccion
 
[Run Reloaded] Estrategias de Caching Distribuído con Microsoft Velocity Proj...
[Run Reloaded] Estrategias de Caching Distribuído con Microsoft Velocity Proj...[Run Reloaded] Estrategias de Caching Distribuído con Microsoft Velocity Proj...
[Run Reloaded] Estrategias de Caching Distribuído con Microsoft Velocity Proj...
 

JVM tuning: lo que debes saber antes de subir a producción