Slide 1

Slide 1 text

JVM Tuning in a rush Tomasz Borek, Symentis

Slide 2

Slide 2 text

• Infected in childhood • From me parents • Amstrad, ElWro Junior • Games! Doh! • Mem pages in DOS anyone? • In IT • ETL, crawlers, web-app, archi • IAAS, SAAS, own servers • Java 4 – 7, GNU/Linux, SQLs • Ardent “activist” Tomasz Borek

Slide 3

Slide 3 text

Can be found in the net! :P https://lafkblogs.wordpress.com/ https://twitter.com/lafk_pl https://pl.linkedin.com/in/tjborek GeeCON, ChamberConf, Confitura, Lambda Days, LambdaCon, Java Developer Days, JavaDay Lviv, JavaDay Kiev

Slide 4

Slide 4 text

Tomek in IT groups .com http://java.pl Kraków Poznań Praga Sopot http://geecon.org

Slide 5

Slide 5 text

Prod hits rock bottom ● Everybody is kung-fu fighting ● Must be quick like lightning

Slide 6

Slide 6 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra

Slide 7

Slide 7 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes

Slide 8

Slide 8 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1)

Slide 9

Slide 9 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1) 4.To have access to monitoring

Slide 10

Slide 10 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1) 4.To have access to monitoring 5.To adjust pooling (both thread and connection)

Slide 11

Slide 11 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1) 4.To have access to monitoring 5.To adjust pooling (both thread and connection) 6.To peruse logs and pull out anomalies

Slide 12

Slide 12 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1) 4.To have access to monitoring 5.To adjust pooling (both thread and connection) 6.To peruse logs and pull out anomalies 7.TO TUNE JVM

Slide 13

Slide 13 text

So! Being a dev, you need: 1.To know your traffic and your app and your infra 2.To know recent changes 3.To know your limits (sometimes comes from point 1) 4.To have access to monitoring 5.To adjust pooling (both thread and connection) 6.To peruse logs and pull out anomalies 7.TO TUNE JVM

Slide 14

Slide 14 text

JVM? Meaning? • Sun Hotspot • IBM • JRockit • IceTea • OpenJDK • TCK decides

Slide 15

Slide 15 text

JVM? Meaning? • Sun Hotspot • IBM • JRockit • IceTea • OpenJDK • TCK decides

Slide 16

Slide 16 text

JVM? Meaning? • Sun Hotspot – but which version? • IBM • JRockit • IceTea • OpenJDK • TCK decides

Slide 17

Slide 17 text

JVM? Meaning? • Sun Hotspot – but which version? And architecture? • IBM • JRockit • IceTea • OpenJDK • TCK decides

Slide 18

Slide 18 text

So! JVM tuning? 1.To adjust GC, based on it's logs

Slide 19

Slide 19 text

So! JVM tuning? 1.To adjust GC, based on it's logs 2.To adjust (native) heap

Slide 20

Slide 20 text

So! JVM tuning? 1.To adjust GC, based on it's logs 2.To adjust (native) heap 3.Tweaking JVM starting flags

Slide 21

Slide 21 text

So! JVM tuning? 1.To adjust GC, based on it's logs 2.To adjust (native) heap 3.Tweaking JVM starting flags 4.To use TOOLS

Slide 22

Slide 22 text

Today! ● JVM tuning ● Diagnosing performance problems ● Tools ● All in a rush

Slide 23

Slide 23 text

JVM tuning

Slide 24

Slide 24 text

Takeaway #1 JVM is a process

Slide 25

Slide 25 text

Being a process means ● OS architecture enforces JVM architecture ● Your memory is limited by OS and other processes – Heap is one – C-heap is another! ● IO-wise and thread-wise: – Your threads and files opened are limited by ulimit ● File descriptors!

Slide 26

Slide 26 text

OOM flavours?

Slide 27

Slide 27 text

OOM flavours ● Out of HeapSpace

Slide 28

Slide 28 text

OOM flavours ● Out of HeapSpace ● PermGen error

Slide 29

Slide 29 text

OOM flavours ● Out of HeapSpace ● PermGen error ● Unable to create native thread

Slide 30

Slide 30 text

OOM flavours ● Out of HeapSpace ● PermGen error ● Unable to create native thread ● There are others, these are most popular

Slide 31

Slide 31 text

API says OutOfMemoryError is ● Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. OutOfMemoryError objects may be constructed by the virtual machine as if suppression were disabled and/or the stack trace was not writable.

Slide 32

Slide 32 text

API says OutOfMemoryError is ● Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. OutOfMemoryError objects may be constructed by the virtual machine as if suppression were disabled and/or the stack trace was not writable.

Slide 33

Slide 33 text

API says OutOfMemoryError is ● Due to failure in allocating an object after garbage collection. ● Nothing about threads. ● Nothing about PermGen.

Slide 34

Slide 34 text

How much memory JVM uses? ● Say you start it with Xmx == Xms == 1GB

Slide 35

Slide 35 text

How much memory JVM uses? ● Say you start it with Xmx == Xms == 1GB ● 1GB?

Slide 36

Slide 36 text

How much memory JVM uses? ● Say you start it with Xmx == Xms == 1GB ● 1GB? ● Around 1GB?

Slide 37

Slide 37 text

How much memory JVM uses? ● Say you start it with Xmx == Xms == 1GB ● 1GB? ● Around 1GB? ● If we talk about Java HEAP

Slide 38

Slide 38 text

Memory management Entire RAM ● 32 bits: can address less than 4GB. ● 64 bits: can address… theoretically 16 EB. – Still – much more! ● There's much more to 32vs64 but that's for another time

Slide 39

Slide 39 text

Memory management Entire RAM What's left of RAM – C-HEAP JVM heap -Xmx ● -Xms – minimal heap size ● -Xmx – maximal heap size ● When both should be set to same value?

Slide 40

Slide 40 text

Memory management Entire RAM What's left of RAM – C-HEAP JVM heap What's left – C-HEAP JVM ops JVM heap -Xmx PermGen

Slide 41

Slide 41 text

PermGen ● Permanent Generation – Early Java – for JDK classes – and Strings ● Back then – good idea ● Now removed – JDK 7 – Strings no longer in PermGen – JDK 8 – no PermGen at all

Slide 42

Slide 42 text

PermGen ● Permanent Generation – Early Java – for JDK classes – and Strings ● Back then – good idea ● Now removed – JDK 7 – Strings no longer in PermGen – JDK 8 – no PermGen at all Quick fix? Increase PermGen size.

Slide 43

Slide 43 text

Memory management What's left – C-HEAP JVM ops JVM heap -Xmx PermGen

Slide 44

Slide 44 text

GC ● When it runs?

Slide 45

Slide 45 text

GC ● When it runs? ● Minor collection?

Slide 46

Slide 46 text

GC ● When it runs? ● Minor collection? ● Major collection?

Slide 47

Slide 47 text

GC ● When it runs? ● Minor collection? ● Major collection? ● How can a dev tune GC?

Slide 48

Slide 48 text

Generational GC Tenured – where long-lived are promoted Eden – infants that die quickly ● Studies showed: – most objects die young – Some live really long ● Ergo: short- and long-lived division ● Minor collection: Eden ● Major collection: whole heap

Slide 49

Slide 49 text

Generational GC - mechanics ● In fact Eden has also 2 Survivor spaces – To handle locality – Helps compress after freeing space – First promotion to survivor, then to tenured ● Flags tell: – How many GCs object must survive to be promoted – How large Eden / Tenured / Survivors spaces are – What is logged (how details GC logs are) – Many, MANY more

Slide 50

Slide 50 text

Memory management trade-offs ● Large heap – large full GC – small native and C-heap? ● Smaller heap – minor GC may be enough ● Make sure your objects die young and only really long lived reach tenured

Slide 51

Slide 51 text

JVM tuning 1.To adjust GC, based on it's logs 2.To adjust (native) heap 3.Tweaking JVM starting flags 4.To use TOOLS – later

Slide 52

Slide 52 text

Takeaway #2 Log GC

Slide 53

Slide 53 text

Takeaway #3 GC tuning is a trade-off

Slide 54

Slide 54 text

Diagnosing performance problems

Slide 55

Slide 55 text

„The Box” • Heinz Kabutz, Kirk Pepperdine • Top - bottom

Slide 56

Slide 56 text

„The Box” • TRAFFIC: ? TRAFFIC

Slide 57

Slide 57 text

„The Box” • TRAFFIC: how is app used? TRAFFIC: people, automatic

Slide 58

Slide 58 text

„The Box” • TRAFFIC: how is app used? • CODE: ? TRAFFIC: people, automatic Application CODE

Slide 59

Slide 59 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... TRAFFIC: people, automatic CODE: threads, data structs, algo

Slide 60

Slide 60 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: ? TRAFFIC: people, automatic CODE: threads, data structs, algo JVM

Slide 61

Slide 61 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: ? TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC

Slide 62

Slide 62 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ? TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS

Slide 63

Slide 63 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ulimit, FS, config, archi, other procs… TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS: FS, config, limits

Slide 64

Slide 64 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ulimit, FS, config, archi, other procs… • VIRT: ? TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS: FS, config, limits VIRT

Slide 65

Slide 65 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ulimit, FS, config, archi, other procs… • VIRT: hell depends! TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS: FS, config, limits VIRT

Slide 66

Slide 66 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ulimit, FS, config, archi, other procs… • VIRT: hell depends! • HARDWARE: ? TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS: FS, config, limits VIRT HARDWARE

Slide 67

Slide 67 text

„The Box” • TRAFFIC: how is app used? • CODE: threads, algos, data structures... • JVM: starting flags, GC • OS: ulimit, FS, config, archi, other procs… • VIRT: hell depends! • HARDWARE: 32 vs 64, RAM, BIOS, drivers… TRAFFIC: people, automatic CODE: threads, data structs, algo JVM: flags, GC OS: FS, config, limits VIRT HARDWARE

Slide 68

Slide 68 text

Brendan Gregg – USE • Utilization, Saturation, Errors • Use – how much in use is your resource • Saturation – how many requests await (waiting queue) • Errors – what errors are thrown by resource • http://www.brendangregg.com/usemethod.html • Create a checklist for each important resource, for finding out Utilization, Saturation and Errors and you'll know how to soon find out what is going on with resource

Slide 69

Slide 69 text

Takeaway #1 The Box

Slide 70

Slide 70 text

Takeaway #2 GNU/Linux perf? Brendan Gregg

Slide 71

Slide 71 text

TOOLS

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Takeaway #1 GNU/Linux surely has a tool for that

Slide 75

Slide 75 text

How to find your java process? ● ps … | grep java ●

Slide 76

Slide 76 text

How to find your java process? ● ps … | grep java ● pgrep java

Slide 77

Slide 77 text

How to find your java process? ● ps … | grep java ● pgrep java ● jps

Slide 78

Slide 78 text

How to change flags on-the-fly? ● jinfo

Slide 79

Slide 79 text

How to dump threads or heap? ● kill -3

Slide 80

Slide 80 text

How to dump threads or heap? ● kill -3 ● jstack

Slide 81

Slide 81 text

How to dump threads or heap? ● kill -3 ● jstack ● jhat (heap)

Slide 82

Slide 82 text

jvisualvm ● Deserves it's own slide ● Profiler, sampler ● Monitor (heap, threads, etc.) ● Calls GC, does dumps

Slide 83

Slide 83 text

SUMMARIZING ● For being rushed – prepare in advance – Monitoring, logs, ceilings, etc. ● Log GC ● JVM is a process – all process limits in your OS apply ● The Box ● Brendan Gregg ● GNU/Linux – tools unparalleled

Slide 84

Slide 84 text

?