Top Banner
Introduction to Java Performance Tuning Marouane Gazanayi @mgazanayi
55

Introduction to Java performance tuning

Apr 15, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Java performance tuning

Introduction to Java Performance Tuning

Marouane Gazanayi@mgazanayi

Page 2: Introduction to Java performance tuning
Page 3: Introduction to Java performance tuning

API Dictionary

Prescriptions safety checkingPMSIRecos...

hoptimal/eVidalvidal.fr

MobileAnd much more...

Page 4: Introduction to Java performance tuning

WORA!

Write Once, Run Anywhere

Page 5: Introduction to Java performance tuning

Main concepts

javac

JVM

Page 6: Introduction to Java performance tuning

Main concepts

javac

scalac JVM

Page 7: Introduction to Java performance tuning

Main concepts

javac

JVMscalac

clojure compiler

Page 8: Introduction to Java performance tuning

And...

No more manual memory management

Signed: GC

Page 9: Introduction to Java performance tuning

SERIOUSLY

Awesome!

Page 10: Introduction to Java performance tuning

Generational hypothesis

Objects age

nb o

f ob

ject

s

Page 11: Introduction to Java performance tuning

Garbage Collector

Manages the Heap by removing "dead" objects

Page 12: Introduction to Java performance tuning

Garbage Collector

Page 13: Introduction to Java performance tuning

Garbage Collector

It is also responsible for "defragmenting" the Heap

Page 14: Introduction to Java performance tuning

Garbage Collector

Page 15: Introduction to Java performance tuning

Garbage Collector

Most employ a "stop the world" collection, meaning the running application must stop processing while the GC is engaged.

Page 16: Introduction to Java performance tuning

Garbage Collector

Therefore frequent or large amounts of collection affect the performance of your application.

Page 17: Introduction to Java performance tuning

Garbage CollectorLot of JVM options, at least always run with these

Page 18: Introduction to Java performance tuning

Heap

S0 S1eden

Young Generation

Survivor space

Page 19: Introduction to Java performance tuning

Heap

TenuredS0 S1eden

Old GenerationYoung Generation

Survivor space

Page 20: Introduction to Java performance tuning

Heap

Tenured Permanent

Permanent Generation

S0 S1eden

Old GenerationYoung Generation

Survivor space

Page 21: Introduction to Java performance tuning

Heap

Tenured Permanent

Metaspace

S0 S1eden

Old GenerationYoung Generation

Survivor space

Page 22: Introduction to Java performance tuning

Heap: Example

TenuredS0 S1eden

Page 23: Introduction to Java performance tuning

Heap: Example

11

TenuredS0 S1eden

Page 24: Introduction to Java performance tuning

Heap: Example

2

TenuredS0 S1eden

Page 25: Introduction to Java performance tuning

Heap: Example

31

TenuredS0 S1eden

Page 26: Introduction to Java performance tuning

Heap: Example

42

TenuredS0 S1eden

Page 27: Introduction to Java performance tuning

Heap: Example

3

TenuredS0 S1eden

Page 28: Introduction to Java performance tuning

Garbage Collector basics

SweepCompact

Copy

Page 29: Introduction to Java performance tuning

Garbage Collector sweep

Page 30: Introduction to Java performance tuning

Garbage Collector compact

Page 31: Introduction to Java performance tuning

Garbage Collector copy

Page 32: Introduction to Java performance tuning

Garbage Collector(s)

Serial GCParallel CollectorParallec CompactionConcurrent Mark Sweep CollectorG1

Page 33: Introduction to Java performance tuning

Garbage Collector(s)

Azul ZingShenandoah

...

Page 34: Introduction to Java performance tuning

HotSpot & JIT

Java source code

javac

.class file

Code cache

RuntimeHotSpot

Profiler JIT

Method cacheclass loader

java

Page 35: Introduction to Java performance tuning

What is performance?

The efficiency with which something reacts or

fulfills its intended purpose

Page 36: Introduction to Java performance tuning

What is performance?

Perceived Performance Issues

Some issues can be fixed by simply providing more information to the user

Page 37: Introduction to Java performance tuning

Response Time

How Long does it take for a system to react to a user's request

Page 38: Introduction to Java performance tuning

Throughput

How much data can be processed by the system within a given amount of time?

Page 39: Introduction to Java performance tuning

Load

Amount of work assigned at a given time

Page 40: Introduction to Java performance tuning

Utilization

Measure of how much of a system’s capacity is being consumed at a givenwork loads

Page 41: Introduction to Java performance tuning

Availability

Amount of time that an application is available to the end user

Page 42: Introduction to Java performance tuning

Technique

Estimate theoretical values and compare to measured values

Page 43: Introduction to Java performance tuning

Response timePoo

rAc

cept

able

Time

Load

Page 44: Introduction to Java performance tuning

Response timePoo

rAc

cept

able

Time

Load

Page 45: Introduction to Java performance tuning

ThroughputPoo

rAc

cept

able

Throughput

Load

Page 46: Introduction to Java performance tuning

ThroughputPoo

rAc

cept

able

Throughput

Load

Page 47: Introduction to Java performance tuning

ThroughputThroughput

Load

Page 48: Introduction to Java performance tuning

ThroughputThroughput

Load

Page 49: Introduction to Java performance tuning

CPU

100% CPU

Page 50: Introduction to Java performance tuning

CPU

100% CPU

Page 51: Introduction to Java performance tuning

Performance tips

A tip is a workaround for a

known problem

-Xmx == -Xms turns off adaptive sizing

Page 52: Introduction to Java performance tuning

Components that affect Performance

CPU

● Other processes running that are monopolizing CPU time● Single vs Parallel Processing

Input/Output

● File System ● Database ● Network Data Stores

Page 53: Introduction to Java performance tuning

The performance Tuning Lifecycle

1 Define Requirements

2 Measure / Test (create baseline)

3 Identify Bottleneck

4 Implements Fixes

5 Measure / Test (New Baseline)

6 Compare to Old Baseline & Requirements

7 If necessary repeat steps 3-6

Page 54: Introduction to Java performance tuning

The performance Tuning workflowsys cpu > 10%

user cpu

idle > 0% Memory efficient? GC

logs

system profiling: netstat, mpstat, iostat sar strace, gc logs, strace, etc...

App/CPU profilingMemory profiling, size frequency, life span,...

GC tuning, pool sizes, collectors...

Thread starvationThread dump

Application

NoneJVM

SystemYes

No

NoNo

Yes Yes

Page 55: Introduction to Java performance tuning

That’s all folks!