1
Simple Tweaks
To Get the Most Out Of Your JVM
Jamie Lee Coleman
Software Engineer/Developer Advocate @ IBM
Twitter: @JamieLeeC
2
What we will be looking at…
• What is a JVM and why is it
important?
• How the cloud has changed
the JVM
• HotSpot, OpenJ9 &
GraalVM Overview
• Picking the right runtime to run
on your JVM
• Tweaking your JVM
• OpenJ9 Class Cache + Demo
• OpenJ9 Idle Tuning
• OpenJ9 JIT Server
• Recap
3
3
Why is the JVM important?
Well firstly without it we would have no Java!
4
What does the JVM do
A Java Virtual Machine (JVM) is responsible for taking your application
bite code and converting it to a machines language for execution.
Most other languages compile code for a specific system but in Java,
the compiler converts the code for a Java Virtual Machine that can be
used on any system hence the phrase “Write once, run anywhere”.
5
Why do people use JVM’s?
• Cross Platform
• Large Library Ecosystem
• Great Garbage collector
• Powerful Monitoring tools
• Proven and Robust!
7
JVM Architecture
Class Loader Subsystem
Runtime Data Area
Method
Area
Heap
JVM
Language
Stack
PC
Registers
Native
Method
Stacks
Execution
Engine
Native
Method
Interface
Native
Method
Library's
8
ClassLoader Subsystem
Loading
• Loads classes using 3 different class loaders named the Bootstrap, Extension
and Application ClassLoaders
Linking
• Verify the generated bite code, prepare all static variables and assign default
values and resolves all symbolic memory references
Initialization
• Assigns static variables with their original values and executes the static block
9
Runtime Data Area
Method Area:
• Stores metadata, constant runtime pool and code for methods.
Heap:
• Common memory shared between multiple threads that stores Object, Instance Variables and Arrays.
JVM Language Stacks:
• Created when a thread is created and stores local variables
PC Registers:
• Every thread has its own Register, and it stores the address of the Java virtual machine instruction which
is currently executing.
Native Method Stack:
• Holds Native method information. For every thread that is created so is a native method stack.
10
Execution Engine
Execution Engine:
• Reads bytecode and executes it using the Interpreter and JIT Compiler
Native method interface (JNI):
• Interacts with the Native Method Libraries to provide the required libraries
for the execution engine.
Native Method Library’s
• A collection of Native Libraries.
11
11
How the cloud has changed
the JVM
$ $ $ $ $
12
Cloud computing
energy = money
Money changes everything
With a measurable and direct relationship between
$£€¥₽ and CPU/RAM, disk etc the financial success
or failure of a project is even easier to see
And that means…
Even more focus on value for money and as a
result focus on energy.
13
Demand
One big server running all the time?
time
What the Cloud offers
14
Demand
One big server running all the time?
time
What the Cloud offers
15
Demand
time
One big server running all the time?
What the Cloud offers
16
Microservices and the JVM
17
Many metrics must be balanced for Java Performance
• Wide variety of use cases means many metrics must be balanced
• Different goals  different design decisions
• No single “right” answer
• Must keep a balance  make sensible trade-offs
• Key performance metrics tracked
• start-up time
• ramp-up time
• memory footprint
• response time
• CPU/Throughput
Optimizing for cloud requires a different balance across these performance metrics
start-up time
footprint
ramp-up
response time
CPU
18
Java ME Inside!
19
JAVA ME REQUIREMENTS
Small footprint
- On disk and runtime.
- Very limited RAM, usually more ROM
Fast startup
- Everybody wants their games to start
quickly
Quick / immediate rampup
- Game shouldn’t play better the longer
you play
Java ME
20
JAVA ME REQUIREMENTS JVM IN THE CLOUD REQUIREMENTS
Small footprint
- On disk and runtime.
- Very limited RAM, usually more ROM
Small footprint
- Improves density for providers
- Improves cost for applications
Fast startup
- Everybody wants their games to start
quickly
Fast startup
- Faster scaling for increased demand
Quick / immediate rampup
- Game shouldn’t play better the longer
you play
Quick / immediate rampup
- GB/hr is key, if you run for less time you pay
less money
Java ME vs the JVM in the Cloud
21
21
Why should developers care
about optimisation of our
Applications?
It does not save that much money!
22
Why should developers care?
There is over 500,000 data centres worldwide
The area of land they consume is around the same as 6,000 football
pitches
UK energy consumption x 1.5 == global data centre energy
consumption.
23
Luckily Hardware efficiency is helping
24
24
The Different JVMs Available
25
There is a JVM for everything
Azul
Codename One (Mobile)
Eclipse OpenJ9
GraalVM
HotSpot
JamVM (IOT Devices)
JikesRVM (Research)
leJOS (Robotics for Lego)
Maxine
Apache Harmony
JOP
Juice
Jupiter
Kaffe
Mika VM (Embedded Devices)
NanoVN (Asuro Robot)
SableVM
SquawkVM
SuperWaba
TakaTuka
TinVM
WonkaVM
26
Most popular JVM’s
• Oracle JDK
• OpenJDK (via Adopt OpenJDK)
• OpenJDK (via Oracle)
• OpenJDK (via Amazon Coretto)
• Azul
• GraalVM
• Eclipse OpenJ9 (via Adopt OpenJDK)
31
31
HotSpot, OpenJ9 and GraalVM
Overview
32
Overview of HotSpot
Formally known as “Java HotSpot Performance Engine”
Original release: 27th April 1999
HotSpot became the default Sun (Now Oracal) JVM in Java 1.3
On 13 November 2006, the HotSpot JVM and the Java Development Kit (JDK)
became Open Source paving the way for OpenJDK and many other JVM
implementations.
“HotSpot continually analyzes the program's performance for hot spots which are
executed often or repeatedly. These are then targeted for optimizing, leading to
high-performance execution with a minimum of overhead for less performance-
critical code” - Wikipedia
33
Overview of OpenJ9
Designed from the start to span all the
operating systems needed by IBM products
This JVM can go from small to large
Can handle constrained environments or
memory rich ones
Is used by the largest enterprises on the
planet
34
Overview of OpenJ9
35
Overview of GraalVM
Original Release: May 2019 v19.0
Based on HotSpot OpenJDK with routes from the Maxine Virtual machine
developed by Sun (Oracal) and the University of Manchester UK.
Why is it different to other JVM’s?
• It has a new JIT compiler for Java, GraalVM Compiler
• It allows the ahead-of-time compilation of Java applications with the GraalVM Native Image
• Truffle Language Implementation framework and the GraalVM SDK to enable additional
programming language runtimes
• LLVM and JavaScript Runtime
36
GraalVM Project Goals:
• To improve the performance of Java virtual machine-based languages to
match the performance of native languages.
• To reduce the startup time of JVM-based applications by compiling them
ahead-of-time with GraalVM Native Image technology.
• To enable GraalVM integration into the Oracle Database, OpenJDK,
Node.js, Android/iOS, and to support similar custom embeddings.
• To allow freeform mixing of code from any programming language in a
single program, billed as "polyglot applications".
• To include an easily extended set of "polyglot programming tools".
37
37
Picking the right Runtime
Open Source Runtimes from IBM & RedHat
38
38
39
Liberty
• Developer friendly
• Just enough application server
• Fast inner loop with dev mode
• Support for industry standard
dev tools
• Jakarta EE, Java EE,
MicroProfile APIs
• Zero Migration
• Cloud Ready
• Container optimized
• Designed for dev/ops
• Small disk footprint
• Efficient memory usage
• Fast startup
• High throughput
• Self-Tuned Thread Pool
40
<feature>servlet-4.0</feature>
<feature>jsf-2.3</feature>
Just Enough Application Server
• You control which features are loaded into each server instance
Kernel
servlet-4.0
http-2.0 appmgr
jsp-2.3 jsf-2.3
Java EE/Jakarta EE
41
API Support
• First shipped in WAS 8.5 in 2012
o Servlet + JSP + JPA
• Web Profile 6 in 2014
• Java EE 7 in 2016 – first commercial
product to certify
• Java EE 8 in 2018 – first to certify
• Jakarta EE 8 in 2019 – first to certify
• Eclipse MicroProfile – first to deliver
1.0-1.4, 2.0-2.1, 3.0
42
43
Quarkus
• Unified Configuration
• Zero config, live reload
• Streamlined code for the 80% common usages
• Native Execution
• Support for many libraries such as MicroProfile
44
Quarkus
45
Other Runtimes
46
46
Tweaking the JVM
Making Your Java Code Perform
47
Making the most out of any JVM
1. Writing efficient code
2. Use the right JVM for your needs
3. Pick a runtime that is right for your application
4. Use Profiling to get the most out of your JVM
5. Tweak your JVM depending on your needs in development and
production
48
1. Writing efficient code
• Use primitives where possible
• Use a StingBuilder rather than an StringBuffer
• Avoid using an Iterator
• Avoid using BigInteger and BigDecimal
49
2. Use the right JVM for your needs
50
3. Pick a runtime that is right for your
application
Architectural style
Functions
Monolith Microservice
API
needs
Smaller
Larger
Macroservice
Open Liberty
WAS
Quarkus
51
4. Profiling
Java Profilers are really useful tools that enable you to monitor Java
bytecode constructs and operations inside the JVM. This includes
things such as:
• Garbage Collections
• Object Creation
• Method Executions
• Iterative Executions
• Thread Executions
52
4. Profiling Cont
Most Popular Java Profilers:
• JProfiler
• YourKit
• Java VisualVM
• NetBeans Profiler
• Oracle Java Mission Control (Included in Oracle JDK)
53
5. Tweak your JVM
• Tune your Garbage Collector (GC)
• Use the AOT Compiler
• Enable Class Data Sharing (HotSpot & OpenJ9)
• Enable Idle Tuning
• Use a JIT Server
• Start with min Heap Size
54
54
OpenJ9 Class Data Sharing
For Super Fast Start-up
55
• A shared classes cache is an area of shared memory of a fixed size that
persists beyond the lifetime of the JVM or a system reboot unless a non-
persistent shared cache is used. Any number of shared caches can exist on
a system, and all are subject to operating system settings and restrictions.
• A shared cache cannot grow in size. When it becomes full, JVMs can still
load classes from it but can no longer store any data into it. You can create a
large, shared classes cache up front, while setting a soft maximum limit on
how much shared cache space can be used. You can increase this limit
when you want to store more data into the shared cache without shutting
down the JVMs that are connected to it.
What is class sharing?
56
When a JVM loads a class, it first looks in the class loader cache to see if the class it needs is already present. If
yes, it returns the class from the class loader cache. Otherwise, it loads the class from the filesystem and writes
it into the cache as part of the defineClass() call. Therefore, a non-shared JVM has the following class loader
lookup order:
• Classloader cache
• Parent
• Filesystem
In contrast, a JVM running with the class sharing feature uses the following order:
• Classloader cache
• Parent
• Shared classes cache
• Filesystem
How does class sharing work?
57
To enable class sharing, add -Xshareclasses[:name=<cachename>] to
an existing Java command line.
You can specify the shared cache size using the parameter -
Xscmx<size>[k|m|g. This parameter only applies if a new shared cache
is created.
How to Enabling class sharing
58
0
2
4
6
8
10
12
Open Liberty 20.0.0.4 TomEE 8.0.0-M3-microprofile Tomcat 9.0.22 + OpenWebBeans
2.0.11(CDI) + CXF 3.3.2 (jaxrs)
Wildfly 17.0.1 javaee JBoss 7.2 Glassfish web 5 Payara web 5.192
PingPerf application startup time with HotSpot
(in seconds)
Startup time comparison (using HotSpot JVM)
59
0
1
2
3
4
5
6
7
8
Open Liberty 20.0.0.4 TomEE 8.0.0-M3-microprofile Tomcat 9.0.22 + OpenWebBeans
2.0.11(CDI) + CXF 3.3.2 (jaxrs)
Wildfly 17.0.1 javaee JBoss 7.2 Glassfish web 5 Payara web 5.192
PingPerf application startup time with OpenJ9 Shared Classes Cache (in seconds)
Startup time comparison (using OpenJ9 JVM)
60
Open Liberty and OpenJ9 shared classes
cache in Docker
0
2
4
6
8
Open Liberty Docker image without shared classes cache Open Liberty Docker image with shared classes cache
AcmeAir MS Startup time in Docker (in seconds)
61
0
0.5
1
1.5
2
2.5
December '18 March '19 April '19 July '19 August '19 September '19 April '20
2018-2020 Progression of OpenLiberty+OpenJ9 startup time (seconds)
Open Liberty with OpenJ9: the road to one
second startup time
OpenJ9 : Improved Cached feature metadata when no change to server.xml Changed bundle activation to start in parallel
Better AOT code RAS processing Optimized loading of CXF JSON/JSONB provider RAS annotation processing at build time
JMX MBeanServer init Cached annotation information for built-in JAX-RS Providers Cached plugin xml and OSGi metadata
OpenJ9 : GC hints in shared classes cache Reduced class loading during startup
Reduced logging overhead
OpenJ9 : More AOT code in shared classes cache
OpenJ9 : Optimize class verification overhead
62
62
OpenJ9 Class Cache
Demo
63
Interactive Demo
If you want to run through the demo’s at the same time please go to:
https://openliberty.skillsnetwork.site/cloud-native-java-made-easy-with-
microprofile
64
64
OpenJ9 Idle Tuning
65
OpenJ9 JVM judiciously uses computing resources
Computing resources ==
Cloud it’s about sharing; do not be greedy in using all resources
• OpenJ9 is conservative with heap growth
• OpenJ9 frees memory used transiently during JIT compilation
0
100
200
300
400
500
600
700
800
1GB 2GB 4GB
Resident
set
size
(MB)
Container limit
Steady state memory footprint in AcmeAir
OpenJ9 Hotspot
For large containers
OpenJ9 uses less than
half the memory
66
Free Resources when Applications are
Idling
-XX:+IdleTuningGcOnIdle
(default setting in container)
Benchmark: https://github.com/blueperf/acmeair
More details: https://developer.ibm.com/javasdk/2017/09/25/still-paying-unused-memory-java-app-idle
anthesisgroup.com: “Some 30 percent of VMs are zombies”
https://anthesisgroup.com/wp-content/uploads/2017/03/Comatsoe-Servers-Redux-2017.pdf
1. Detect idle state
2. Trigger GC
3. Compact Java heap
4. Send OS reclamation hint
OpenJ9 frees resources when applications are idling
67
67
OpenJ9 JIT Server
68
JIT server
JIT
JVM
JITServer
JIT
JVM
JIT
JVM Orchestrator
load balancing, affinity,
scaling, reliability
JITServer
69
JITServer Performance
Throughput benefits grow in constrained environments
0
200
400
600
800
1000
1200
1400
0 100 200 300 400 500 600
Throughput
(pages/sec)
Time (sec)
--cpus=1, -m=300m
JITServer OpenJ9
0
200
400
600
800
1000
1200
1400
0 100 200 300 400 500 600
Throughput
(pages/sec)
Time (sec)
--cpus=1, -m=256m
JITServer OpenJ9
0
200
400
600
800
1000
1200
1400
0 100 200 300 400 500 600
Throughput
(pages/sec)
Time (sec)
--cpus=1, -m=200m
JITServer OpenJ9
Smaller memory limit
JIT server performance : Open Liberty Daytrader7 throughput
70
How to enable a JIT Server
Launch OpenJ9 in client mode so that the VM sends requests to the
JITServer using the following command:
“-XX:+IseJITServer”
Then run the following command to start a JITServer process that
listens for incoming compilation requests:
“jitserver”
73
73
Recap
What if anything have you learned today?
74
How do you get the most out of
your JVM?
Write efficient code
Use the right JVM for your needs
Pick a runtime that is right for your application
Use Profiling
&
Tweaking your JVM
=
Less Money & Energy!
75
Links and Materials
JVM’s
• AdoptOpenJDK: https://adoptopenjdk.net/
• OpenJ9: https://www.eclipse.org/openj9/
• HotSpot JDK: https://openjdk.java.net/groups/hotspot/
• Oracle JDK: https://www.oracle.com/uk/java/technologies/javase-
downloads.html
• GraalVM: https://www.graalvm.org/
• Azul (Zulu): https://www.azul.com/downloads/zulu-community/
• Amazon JDK: https://aws.amazon.com/corretto/
Runtimes
• Open Liberty Site: https://openliberty.io/
• Open Liberty Guides: https://openliberty.io/guides
• Quarkus Site: https://quarkus.io/
Other Useful Links
• Jakarta EE Homepage: https://jakarta.ee/
• OpenJ9 JIT Server Doc:
https://www.eclipse.org/openj9/docs/jitserver/
• OpenJ9 Class Data Sharing Doc:
https://www.eclipse.org/openj9/docs/shrc/
• OpenJ9 Idle Tuning Doc:
https://www.eclipse.org/openj9/docs/xxidletuninggconidle/
76
References to research for this talk
• https://snyk.io/blog/36-of-developers-switched-from-oracle-jdk-to-an-alternate-openjdk-
distribution-over-the-last-year/
• https://en.wikipedia.org/wiki/List_of_Java_virtual_machines
• https://www.guru99.com/java-virtual-machine-
jvm.html#:~:text=Java%20Virtual%20Machine%20(JVM)%20is,code%20for%20a%20pa
rticular%20system.
• https://dzone.com/articles/jvm-architecture-explained
• https://www.quora.com/Whats-the-attraction-of-the-JVM-platform
• https://stackify.com/java-performance-tuning/
• https://en.wikipedia.org/wiki/Comparison_of_Java_virtual_machines
• https://www.baeldung.com/java-profilers
77
77
Thank You
Jamie Lee Coleman
Software Developer/Advocate @ IBM
jlcoleman@uk.ibm.com
@Jamie_Lee_C

Simple tweaks to get the most out of your jvm

  • 1.
    1 Simple Tweaks To Getthe Most Out Of Your JVM Jamie Lee Coleman Software Engineer/Developer Advocate @ IBM Twitter: @JamieLeeC
  • 2.
    2 What we willbe looking at… • What is a JVM and why is it important? • How the cloud has changed the JVM • HotSpot, OpenJ9 & GraalVM Overview • Picking the right runtime to run on your JVM • Tweaking your JVM • OpenJ9 Class Cache + Demo • OpenJ9 Idle Tuning • OpenJ9 JIT Server • Recap
  • 3.
    3 3 Why is theJVM important? Well firstly without it we would have no Java!
  • 4.
    4 What does theJVM do A Java Virtual Machine (JVM) is responsible for taking your application bite code and converting it to a machines language for execution. Most other languages compile code for a specific system but in Java, the compiler converts the code for a Java Virtual Machine that can be used on any system hence the phrase “Write once, run anywhere”.
  • 5.
    5 Why do peopleuse JVM’s? • Cross Platform • Large Library Ecosystem • Great Garbage collector • Powerful Monitoring tools • Proven and Robust!
  • 6.
    7 JVM Architecture Class LoaderSubsystem Runtime Data Area Method Area Heap JVM Language Stack PC Registers Native Method Stacks Execution Engine Native Method Interface Native Method Library's
  • 7.
    8 ClassLoader Subsystem Loading • Loadsclasses using 3 different class loaders named the Bootstrap, Extension and Application ClassLoaders Linking • Verify the generated bite code, prepare all static variables and assign default values and resolves all symbolic memory references Initialization • Assigns static variables with their original values and executes the static block
  • 8.
    9 Runtime Data Area MethodArea: • Stores metadata, constant runtime pool and code for methods. Heap: • Common memory shared between multiple threads that stores Object, Instance Variables and Arrays. JVM Language Stacks: • Created when a thread is created and stores local variables PC Registers: • Every thread has its own Register, and it stores the address of the Java virtual machine instruction which is currently executing. Native Method Stack: • Holds Native method information. For every thread that is created so is a native method stack.
  • 9.
    10 Execution Engine Execution Engine: •Reads bytecode and executes it using the Interpreter and JIT Compiler Native method interface (JNI): • Interacts with the Native Method Libraries to provide the required libraries for the execution engine. Native Method Library’s • A collection of Native Libraries.
  • 10.
    11 11 How the cloudhas changed the JVM $ $ $ $ $
  • 11.
    12 Cloud computing energy =money Money changes everything With a measurable and direct relationship between $£€¥₽ and CPU/RAM, disk etc the financial success or failure of a project is even easier to see And that means… Even more focus on value for money and as a result focus on energy.
  • 12.
    13 Demand One big serverrunning all the time? time What the Cloud offers
  • 13.
    14 Demand One big serverrunning all the time? time What the Cloud offers
  • 14.
    15 Demand time One big serverrunning all the time? What the Cloud offers
  • 15.
  • 16.
    17 Many metrics mustbe balanced for Java Performance • Wide variety of use cases means many metrics must be balanced • Different goals  different design decisions • No single “right” answer • Must keep a balance  make sensible trade-offs • Key performance metrics tracked • start-up time • ramp-up time • memory footprint • response time • CPU/Throughput Optimizing for cloud requires a different balance across these performance metrics start-up time footprint ramp-up response time CPU
  • 17.
  • 18.
    19 JAVA ME REQUIREMENTS Smallfootprint - On disk and runtime. - Very limited RAM, usually more ROM Fast startup - Everybody wants their games to start quickly Quick / immediate rampup - Game shouldn’t play better the longer you play Java ME
  • 19.
    20 JAVA ME REQUIREMENTSJVM IN THE CLOUD REQUIREMENTS Small footprint - On disk and runtime. - Very limited RAM, usually more ROM Small footprint - Improves density for providers - Improves cost for applications Fast startup - Everybody wants their games to start quickly Fast startup - Faster scaling for increased demand Quick / immediate rampup - Game shouldn’t play better the longer you play Quick / immediate rampup - GB/hr is key, if you run for less time you pay less money Java ME vs the JVM in the Cloud
  • 20.
    21 21 Why should developerscare about optimisation of our Applications? It does not save that much money!
  • 21.
    22 Why should developerscare? There is over 500,000 data centres worldwide The area of land they consume is around the same as 6,000 football pitches UK energy consumption x 1.5 == global data centre energy consumption.
  • 22.
  • 23.
  • 24.
    25 There is aJVM for everything Azul Codename One (Mobile) Eclipse OpenJ9 GraalVM HotSpot JamVM (IOT Devices) JikesRVM (Research) leJOS (Robotics for Lego) Maxine Apache Harmony JOP Juice Jupiter Kaffe Mika VM (Embedded Devices) NanoVN (Asuro Robot) SableVM SquawkVM SuperWaba TakaTuka TinVM WonkaVM
  • 25.
    26 Most popular JVM’s •Oracle JDK • OpenJDK (via Adopt OpenJDK) • OpenJDK (via Oracle) • OpenJDK (via Amazon Coretto) • Azul • GraalVM • Eclipse OpenJ9 (via Adopt OpenJDK)
  • 26.
    31 31 HotSpot, OpenJ9 andGraalVM Overview
  • 27.
    32 Overview of HotSpot Formallyknown as “Java HotSpot Performance Engine” Original release: 27th April 1999 HotSpot became the default Sun (Now Oracal) JVM in Java 1.3 On 13 November 2006, the HotSpot JVM and the Java Development Kit (JDK) became Open Source paving the way for OpenJDK and many other JVM implementations. “HotSpot continually analyzes the program's performance for hot spots which are executed often or repeatedly. These are then targeted for optimizing, leading to high-performance execution with a minimum of overhead for less performance- critical code” - Wikipedia
  • 28.
    33 Overview of OpenJ9 Designedfrom the start to span all the operating systems needed by IBM products This JVM can go from small to large Can handle constrained environments or memory rich ones Is used by the largest enterprises on the planet
  • 29.
  • 30.
    35 Overview of GraalVM OriginalRelease: May 2019 v19.0 Based on HotSpot OpenJDK with routes from the Maxine Virtual machine developed by Sun (Oracal) and the University of Manchester UK. Why is it different to other JVM’s? • It has a new JIT compiler for Java, GraalVM Compiler • It allows the ahead-of-time compilation of Java applications with the GraalVM Native Image • Truffle Language Implementation framework and the GraalVM SDK to enable additional programming language runtimes • LLVM and JavaScript Runtime
  • 31.
    36 GraalVM Project Goals: •To improve the performance of Java virtual machine-based languages to match the performance of native languages. • To reduce the startup time of JVM-based applications by compiling them ahead-of-time with GraalVM Native Image technology. • To enable GraalVM integration into the Oracle Database, OpenJDK, Node.js, Android/iOS, and to support similar custom embeddings. • To allow freeform mixing of code from any programming language in a single program, billed as "polyglot applications". • To include an easily extended set of "polyglot programming tools".
  • 32.
    37 37 Picking the rightRuntime Open Source Runtimes from IBM & RedHat
  • 33.
  • 34.
    39 Liberty • Developer friendly •Just enough application server • Fast inner loop with dev mode • Support for industry standard dev tools • Jakarta EE, Java EE, MicroProfile APIs • Zero Migration • Cloud Ready • Container optimized • Designed for dev/ops • Small disk footprint • Efficient memory usage • Fast startup • High throughput • Self-Tuned Thread Pool
  • 35.
    40 <feature>servlet-4.0</feature> <feature>jsf-2.3</feature> Just Enough ApplicationServer • You control which features are loaded into each server instance Kernel servlet-4.0 http-2.0 appmgr jsp-2.3 jsf-2.3 Java EE/Jakarta EE
  • 36.
    41 API Support • Firstshipped in WAS 8.5 in 2012 o Servlet + JSP + JPA • Web Profile 6 in 2014 • Java EE 7 in 2016 – first commercial product to certify • Java EE 8 in 2018 – first to certify • Jakarta EE 8 in 2019 – first to certify • Eclipse MicroProfile – first to deliver 1.0-1.4, 2.0-2.1, 3.0
  • 37.
  • 38.
    43 Quarkus • Unified Configuration •Zero config, live reload • Streamlined code for the 80% common usages • Native Execution • Support for many libraries such as MicroProfile
  • 39.
  • 40.
  • 41.
    46 46 Tweaking the JVM MakingYour Java Code Perform
  • 42.
    47 Making the mostout of any JVM 1. Writing efficient code 2. Use the right JVM for your needs 3. Pick a runtime that is right for your application 4. Use Profiling to get the most out of your JVM 5. Tweak your JVM depending on your needs in development and production
  • 43.
    48 1. Writing efficientcode • Use primitives where possible • Use a StingBuilder rather than an StringBuffer • Avoid using an Iterator • Avoid using BigInteger and BigDecimal
  • 44.
    49 2. Use theright JVM for your needs
  • 45.
    50 3. Pick aruntime that is right for your application Architectural style Functions Monolith Microservice API needs Smaller Larger Macroservice Open Liberty WAS Quarkus
  • 46.
    51 4. Profiling Java Profilersare really useful tools that enable you to monitor Java bytecode constructs and operations inside the JVM. This includes things such as: • Garbage Collections • Object Creation • Method Executions • Iterative Executions • Thread Executions
  • 47.
    52 4. Profiling Cont MostPopular Java Profilers: • JProfiler • YourKit • Java VisualVM • NetBeans Profiler • Oracle Java Mission Control (Included in Oracle JDK)
  • 48.
    53 5. Tweak yourJVM • Tune your Garbage Collector (GC) • Use the AOT Compiler • Enable Class Data Sharing (HotSpot & OpenJ9) • Enable Idle Tuning • Use a JIT Server • Start with min Heap Size
  • 49.
    54 54 OpenJ9 Class DataSharing For Super Fast Start-up
  • 50.
    55 • A sharedclasses cache is an area of shared memory of a fixed size that persists beyond the lifetime of the JVM or a system reboot unless a non- persistent shared cache is used. Any number of shared caches can exist on a system, and all are subject to operating system settings and restrictions. • A shared cache cannot grow in size. When it becomes full, JVMs can still load classes from it but can no longer store any data into it. You can create a large, shared classes cache up front, while setting a soft maximum limit on how much shared cache space can be used. You can increase this limit when you want to store more data into the shared cache without shutting down the JVMs that are connected to it. What is class sharing?
  • 51.
    56 When a JVMloads a class, it first looks in the class loader cache to see if the class it needs is already present. If yes, it returns the class from the class loader cache. Otherwise, it loads the class from the filesystem and writes it into the cache as part of the defineClass() call. Therefore, a non-shared JVM has the following class loader lookup order: • Classloader cache • Parent • Filesystem In contrast, a JVM running with the class sharing feature uses the following order: • Classloader cache • Parent • Shared classes cache • Filesystem How does class sharing work?
  • 52.
    57 To enable classsharing, add -Xshareclasses[:name=<cachename>] to an existing Java command line. You can specify the shared cache size using the parameter - Xscmx<size>[k|m|g. This parameter only applies if a new shared cache is created. How to Enabling class sharing
  • 53.
    58 0 2 4 6 8 10 12 Open Liberty 20.0.0.4TomEE 8.0.0-M3-microprofile Tomcat 9.0.22 + OpenWebBeans 2.0.11(CDI) + CXF 3.3.2 (jaxrs) Wildfly 17.0.1 javaee JBoss 7.2 Glassfish web 5 Payara web 5.192 PingPerf application startup time with HotSpot (in seconds) Startup time comparison (using HotSpot JVM)
  • 54.
    59 0 1 2 3 4 5 6 7 8 Open Liberty 20.0.0.4TomEE 8.0.0-M3-microprofile Tomcat 9.0.22 + OpenWebBeans 2.0.11(CDI) + CXF 3.3.2 (jaxrs) Wildfly 17.0.1 javaee JBoss 7.2 Glassfish web 5 Payara web 5.192 PingPerf application startup time with OpenJ9 Shared Classes Cache (in seconds) Startup time comparison (using OpenJ9 JVM)
  • 55.
    60 Open Liberty andOpenJ9 shared classes cache in Docker 0 2 4 6 8 Open Liberty Docker image without shared classes cache Open Liberty Docker image with shared classes cache AcmeAir MS Startup time in Docker (in seconds)
  • 56.
    61 0 0.5 1 1.5 2 2.5 December '18 March'19 April '19 July '19 August '19 September '19 April '20 2018-2020 Progression of OpenLiberty+OpenJ9 startup time (seconds) Open Liberty with OpenJ9: the road to one second startup time OpenJ9 : Improved Cached feature metadata when no change to server.xml Changed bundle activation to start in parallel Better AOT code RAS processing Optimized loading of CXF JSON/JSONB provider RAS annotation processing at build time JMX MBeanServer init Cached annotation information for built-in JAX-RS Providers Cached plugin xml and OSGi metadata OpenJ9 : GC hints in shared classes cache Reduced class loading during startup Reduced logging overhead OpenJ9 : More AOT code in shared classes cache OpenJ9 : Optimize class verification overhead
  • 57.
  • 58.
    63 Interactive Demo If youwant to run through the demo’s at the same time please go to: https://openliberty.skillsnetwork.site/cloud-native-java-made-easy-with- microprofile
  • 59.
  • 60.
    65 OpenJ9 JVM judiciouslyuses computing resources Computing resources == Cloud it’s about sharing; do not be greedy in using all resources • OpenJ9 is conservative with heap growth • OpenJ9 frees memory used transiently during JIT compilation 0 100 200 300 400 500 600 700 800 1GB 2GB 4GB Resident set size (MB) Container limit Steady state memory footprint in AcmeAir OpenJ9 Hotspot For large containers OpenJ9 uses less than half the memory
  • 61.
    66 Free Resources whenApplications are Idling -XX:+IdleTuningGcOnIdle (default setting in container) Benchmark: https://github.com/blueperf/acmeair More details: https://developer.ibm.com/javasdk/2017/09/25/still-paying-unused-memory-java-app-idle anthesisgroup.com: “Some 30 percent of VMs are zombies” https://anthesisgroup.com/wp-content/uploads/2017/03/Comatsoe-Servers-Redux-2017.pdf 1. Detect idle state 2. Trigger GC 3. Compact Java heap 4. Send OS reclamation hint OpenJ9 frees resources when applications are idling
  • 62.
  • 63.
    68 JIT server JIT JVM JITServer JIT JVM JIT JVM Orchestrator loadbalancing, affinity, scaling, reliability JITServer
  • 64.
    69 JITServer Performance Throughput benefitsgrow in constrained environments 0 200 400 600 800 1000 1200 1400 0 100 200 300 400 500 600 Throughput (pages/sec) Time (sec) --cpus=1, -m=300m JITServer OpenJ9 0 200 400 600 800 1000 1200 1400 0 100 200 300 400 500 600 Throughput (pages/sec) Time (sec) --cpus=1, -m=256m JITServer OpenJ9 0 200 400 600 800 1000 1200 1400 0 100 200 300 400 500 600 Throughput (pages/sec) Time (sec) --cpus=1, -m=200m JITServer OpenJ9 Smaller memory limit JIT server performance : Open Liberty Daytrader7 throughput
  • 65.
    70 How to enablea JIT Server Launch OpenJ9 in client mode so that the VM sends requests to the JITServer using the following command: “-XX:+IseJITServer” Then run the following command to start a JITServer process that listens for incoming compilation requests: “jitserver”
  • 66.
    73 73 Recap What if anythinghave you learned today?
  • 67.
    74 How do youget the most out of your JVM? Write efficient code Use the right JVM for your needs Pick a runtime that is right for your application Use Profiling & Tweaking your JVM = Less Money & Energy!
  • 68.
    75 Links and Materials JVM’s •AdoptOpenJDK: https://adoptopenjdk.net/ • OpenJ9: https://www.eclipse.org/openj9/ • HotSpot JDK: https://openjdk.java.net/groups/hotspot/ • Oracle JDK: https://www.oracle.com/uk/java/technologies/javase- downloads.html • GraalVM: https://www.graalvm.org/ • Azul (Zulu): https://www.azul.com/downloads/zulu-community/ • Amazon JDK: https://aws.amazon.com/corretto/ Runtimes • Open Liberty Site: https://openliberty.io/ • Open Liberty Guides: https://openliberty.io/guides • Quarkus Site: https://quarkus.io/ Other Useful Links • Jakarta EE Homepage: https://jakarta.ee/ • OpenJ9 JIT Server Doc: https://www.eclipse.org/openj9/docs/jitserver/ • OpenJ9 Class Data Sharing Doc: https://www.eclipse.org/openj9/docs/shrc/ • OpenJ9 Idle Tuning Doc: https://www.eclipse.org/openj9/docs/xxidletuninggconidle/
  • 69.
    76 References to researchfor this talk • https://snyk.io/blog/36-of-developers-switched-from-oracle-jdk-to-an-alternate-openjdk- distribution-over-the-last-year/ • https://en.wikipedia.org/wiki/List_of_Java_virtual_machines • https://www.guru99.com/java-virtual-machine- jvm.html#:~:text=Java%20Virtual%20Machine%20(JVM)%20is,code%20for%20a%20pa rticular%20system. • https://dzone.com/articles/jvm-architecture-explained • https://www.quora.com/Whats-the-attraction-of-the-JVM-platform • https://stackify.com/java-performance-tuning/ • https://en.wikipedia.org/wiki/Comparison_of_Java_virtual_machines • https://www.baeldung.com/java-profilers
  • 70.
    77 77 Thank You Jamie LeeColeman Software Developer/Advocate @ IBM jlcoleman@uk.ibm.com @Jamie_Lee_C