five steps to get the most of running your java app in a ...€¦ · about me ex linux kernel and...

19

Upload: others

Post on 30-Apr-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK
Page 2: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Five Steps to Get the Most of Running your Java App in a Kubernetes Environment

Page 3: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

About Me

● Ex Linux Kernel and glibc hacker● Eclipse OpenJ9 Cloud Optimization Architect● Maintain the AdoptOpenJDK community Docker Images for both

Eclipse OpenJ9 and HotSpot● Interested in every aspect of running Java Apps in K8s including

Cloud Native as well as Legacy migration to Cloud

Dinakar Guniguntala (@dinogun)IBM Runtime Technologies

Page 4: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Demo Repo

https://github.com/dinogun/watson-springboot

Page 5: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Step 1: Begin at the Beginning

Build !

Page 6: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Build Goals

● Size Matters – Small is Better !– Affects provisioning / deployment time– Consider Images based on Alpine Linux (5 MB vs 80 MB for Ubuntu)– Slim images (Cloud workloads use only a small subset)– Use jlink to use only the required modules (Java 9 onwards)

● Should be easy to maintain– Consider using standard build tool docker images (Eg. maven / gradle)– Use build tool plugins for Docker where possible

Java Version Latest Slim Alpine

Alpine-Slim

8 (JDK) 338 MB 213 MB 239 MB 98 MB

12 (JDK) 428 MB 357 MB 329 MB 242 MB

https://hub.docker.com/u/adoptopenjdk

Page 7: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Step 2: Expand and Flourish

Startup and Scale !

Page 8: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Startup Goals

Use of a Shared Class Cache helps reduce startup times by upto 40% -Xshareclasses

java -Xshareclasses:cacheDir=/opt/shareclasses -jar /opt/app/japp.jar

docker run -it -v /path/on/host/shareclasses/dir:/opt/shareclasses japp

-Xquickstart mode Good for very short running applications

Page 9: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Step 3: Keep it Steady

Container Aware !

Page 10: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Optimize at Runtime

Container Aware JVM– -XX:+UseContainerSupport to turn on this feature. (Default now

with the latest JVM)– Use -XX:MaxRAMPercentage and -XX:InitialRAMPercentage

instead of -Xmx and -Xms.– Runtime.availableProcessors() based on cgroup limits.

Heap = 2.4G

Container Mem = 3GContainer Mem = 2G

Heap = 1.6GHeap = 3.2G

Container Mem = 4G

-Xmx = 2G -Xmx = 2G-Xmx = 2G

-XX:MaxRAMPercentage=80

Page 11: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Step 4: Don’t Lose When You Snooze

Idle Aware !

Page 12: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Optimize at Idle Time

OpenJ9 reduces footprint on Idle

– -XX:+IdleTuningGcOnIdle and

– -XX:+IdleTuningCompactOnIdle

Page 13: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Step 5: Crashing in the Cloud ? NP !

Javacores and Dumps

Page 14: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Get Debugging Info on the Fly !

Do you have to restart your containerized Java app to dump debugging info ?

NO !

– Use OpenJ9DiagnosticMXBean instead

Page 15: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Javacore Info

1CICONTINFO Running in container : TRUE1CICGRPINFO JVM support for cgroups enabled : TRUE…1CICGRPINFO Cgroup Information NULL -------------------------------------------------CICGRPINFO subsystem : cpu2CICGRPINFO cgroup name : /2CICGRPINFO CPU Period : 200000 microseconds2CICGRPINFO CPU Quota : 100000 microseconds2CICGRPINFO CPU Shares : 1024 2CICGRPINFO Period intervals elapsed count : 16 2CICGRPINFO Throttled count : 2 2CICGRPINFO Total throttle time : 164156409 nanoseconds2CICGRPINFO subsystem : cpuset2CICGRPINFO cgroup name : /2CICGRPINFO CPU exclusive : 0 2CICGRPINFO Mem exclusive : 0 2CICGRPINFO CPUs : 0-3 2CICGRPINFO Mems : 0 2CICGRPINFO subsystem : memory2CICGRPINFO cgroup name : /2CICGRPINFO Memory Limit : 2147483648 bytes2CICGRPINFO Memory + Swap Limit : 4294967296 bytes2CICGRPINFO Memory Usage : 31182848 bytes2CICGRPINFO Memory + Swap Usage : 31182848 bytes2CICGRPINFO Memory Max Usage : 31277056 bytes2CICGRPINFO Memory + Swap Max Usage : 31277056 bytes2CICGRPINFO Memory limit exceeded count : 0 2CICGRPINFO Memory + Swap limit exceeded count : 0 2CICGRPINFO OOM Killer Disabled : 0 2CICGRPINFO Under OOM : 0

$ docker run -m2g --cpu-quota="100000" --cpu-period="200000" -it openj9 java -Xdump:java:events=vmstop App

Page 16: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

What is AdoptOpenJDK

● AdoptOpenJDK provides prebuilt OpenJDK binaries from a fully open source set of build scripts and infrastructure.– https://adoptopenjdk.net

● Extensive testing as part of the CI pipeline.● REST API for scriptable downloads.● Docker Images published at https://hub.docker.com/r/adoptopenjdk/

Page 17: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Useful Links

Demo

– https://github.com/dinogun/watson-springboot

Eclipse OpenJ9 Sources

– https://github.com/eclipse/openj9– https://github.com/eclipse/omr

Downloads– https://adoptopenjdk.net/?variant=openjdk8&jvmVariant=openj9

Docker Images– https://hub.docker.com/r/adoptopenjdk/openjdk8-openj9/

Build / Package

Startup Running Idling Debugging

Page 18: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK

Qs

Page 19: Five Steps to Get the Most of Running your Java App in a ...€¦ · About Me Ex Linux Kernel and glibc hacker Eclipse OpenJ9 Cloud Optimization Architect Maintain the AdoptOpenJDK