SlideShare a Scribd company logo
CONSIDERATIONS WHEN
DEPLOYING JAVA
APPLICATIONS TO
KUBERNETES*
* OR ANY CONTAINER BASED ENVIRONMENT
@superserch
AGENDA
• Kubernetes – request and limit
• JVM – Threads and Memory spaces
• Default Ergonomics on JVM
• Conflict
• Tuning recommendations
• Cloud Foundry Paketo buildpacks
KUBERNETES – REQUEST AND LIMIT
• Platform that provides services to deploy Pods (one or more containers)
• Splits CPU and memory of Worker Nodes between all containers in that node
• Uses linux cgroup v2 technology to constrain resources
• CPU shared as processing power by time unit – throttling might happen
• Memory involves all processes runing inside a container – it can be killed by oom
• Request – what needs to be available on a node to be scheduled
• Limit – Usage that Linux kernel will enforce on the container
JVM – THREADS AND MEMORY SPACES
• Java Virtual Machine – Memory is managed by the JVM, not the programmer
• Every Java application is multithreaded
• JVM will configure itself based on the detected environment
• JVM has different memory areas where it stores data
• Heap memory – User data
• Meta space memory – Class metadata and constant pool
• Stack and DirectMemory
• Not every OOME causes the JVM to crash
ERGONOMICS AND HEURISTICS ON JVM
• Ergonomics: the study of working conditions, especially the design of equipment and
furniture, in order to help people work more efficiently
• Heuristics: a method of solving problems by finding practical ways of dealing with
them, learning from past experience
ERGONOMICS ON JVM – GARBAGE COLLECTOR
• Server class machine
• G1GC
• SerialGC
• No server class machine
• SerialGC
ERGONOMICS ON JVM – GARBAGE COLLECTOR
• Server class machine
• G1GC
• SerialGC
• No server class machine
• SerialGC
• Server class machine
• Available Processors > 1
• Available Memory > 2GB (-256MB)
ERGONOMICS ON JVM – MEMORY HEAP
• Memory > 512MB
• 25% MaxHeap
• Memory < 512MB
• Varies from 25% up to 50% MaxHeap
• jmap -histo[:live] <pid>
• Instances and bytes
ERGONOMICS ON JVM – MEMORY HEAP
• Memory > 512MB
• 25% MaxHeap
• Memory < 512MB
• Varies from 25% up to 50% MaxHeap
• jmap -histo[:live] <pid>
• Instances and bytes
ERGONOMICS ON JVM – MEMORY METASPACE
• This is off-heap memory
• Initial reserved space: 1GB
• If CompresedOpps are on MetaSpace will have a location table
• Each class uses ~1K class space and ~8k non-class space per class
• jcmd <pid> VM.metaspace
• Can be limited with -XX:MaxMetaspaceSize and -XX:CompressedClassSpaceSize
ERGONOMICS ON JVM – MEMORY METASPACE
• This is off-heap memory
• Initial reserved space: 1GB
• If CompresedOpps are on MetaSpace will have a location table
• Each class uses ~1K class space and ~8k non-class space per class
• jcmd <pid> VM.metaspace
• Can be limited with -XX:MaxMetaspaceSize and -XX:CompressedClassSpaceSize
CONFLICT
• Kubernetes will try to maintain the desired state
• If a container goes beyond its memory limit it will be killed
• If a container goes beyond its CPU Quota limit it will be throtteled
• If a container does not respond to liveness readines it will be restarted
• JVM will use as many threads as possible to do concurrent tasks
• If too limited internal processes will be limited (GC, Default Executors)
• When under load JVM might be paused by Linux kernel because CPU Quota
• If memory is not set Java Heap might get funny values
TUNING RECOMMENDATIONS - CPU
• Use -XX:ActiveProcessorCount to set the desired concurrency level
• JVM won’t consume more CPU than its quota, but this setting will help in selecting
the paralellism of internal structures
• Is a good idea to know the CPU profile of your application, you could use Jconsole, jfr,
or even top
• Monitor kubernetes for CPU throttling of your containers
TUNING RECOMMENDATIONS – GARBAGE
COLLECTORS
• SerialGC
• Default if less than 2 processors or less than 1792MB of Memory
• No overhead because it stops the world to GC
• GC Pause might be an issue if heap over 1GB or container throtteled
• High tail-latency effect
• -XX:+UseSerialGC
TUNING RECOMMENDATIONS – GARBAGE
COLLECTORS
• ParallelGC
• No overhead because it stops the world to GC
• GC Pause might be an issue if heap over 4GB or container throtteled
• Great for batch workloads
• High tail-latency effect
• Configure at least 2000m cpu_limit
• -XX:+UseParallelGC
TUNING RECOMMENDATIONS – GARBAGE
COLLECTORS
• G1GC
• Default if at least 2 processors and more than 1792MB of Memory
• some overhead because it marks regions that have changed
• GC Pauses might be an issue if allocation rates are too high
• High tail-latency effect
• Configure at least 2000m cpu_limit
• -XX:+UseG1GC
TUNING RECOMMENDATIONS – GARBAGE
COLLECTORS
• ZGC
• moderated overhead because it does marking concurently with app
• GC Pauses are usually under 1ms
• Low tail-latency effect
• JDK17+
• Since JDK23 is generational
• Configure at least 2000m cpu_limit
• -XX:+UseZGC
TUNING RECOMMENDATIONS – GARBAGE
COLLECTORS
• ShenandoahGC
• moderated overhead because it does marking concurently with app
• GC Pauses are usually under 10ms
• Moderated tail-latency effect
• JDK11+
• Configure at least 2000m cpu_limit
• -XX:+UseShenandoahGC
TUNING RECOMMENDATIONS – MEMORY
• It is convenient to know what your application has and does
• Number of classes to be loaded
• Use of ByteBuffer
• Size of Live dataset
• Size of work area
• Number of threads
TUNING RECOMMENDATIONS – MEMORY
• Set the Heap size
• -Xmx
• -Xmx3g
• -XX:MaxRAMPercentage
• -XX:MaxRamPercentage=75
• Consider than memory_limit > Heap + MetaSpace + Stack + DirectMemory + spare
• Monitor Kubernetes OOM resets and adjust heap size or memory_limit
TUNING RECOMMENDATIONS – KUBERNETES
• Make cpu_request = cpu_limit and memory_request = memory_limit
• Kubernetes calculates scheduling of pods based on request values
• Assign enough cpu so application and probes can run concurrently
TUNING RECOMMENDATIONS
• What about setting -Xms = -Xmx ?
• It not just reserves but commits memory for heap
• Avoids heap resizing
CLOUD FOUNDRY PAKETO BUILDPACKS
• Nice tool to build containers
• At this moment defaults to BellSoft Liberica JRE 17
• It can pack a JRE or even a JLINK version of the selected JDK
• It can configure some Application servers or Spring Boot applications
• Adds a launcher layer that inspects environment and sets JVM parameters
• This configuration is aimed to avoid OOM resets
CLOUD FOUNDRY PAKETO BUILDPACKS
Heap
Heap = Total Container Memory - Non Heap - Headroom
Non Heap
Non Heap = Direct Memory + Metaspace + Reserved Code cache +
(Thread Stack * Thread Count )
Headroom defaults to 0
PAKETO DEFAULT VALUES
• Direct Memory – 10MB
• Reserved Code Cache – 240MB
• Thread Stack – 1M (Assumes 250 threads running)
• Metaspace – Calculated on class count (35% * 5800 + 14M)
PAKETO DEFAULT PARAMETERS
• -XX:+ExitOnOutOfMemoryError
• -XX:MaxDirectMemory
• -Xmx
• -XX:MaxMetaspaceSize
• -XX:ReservedCodeCacheSize
• -Xss
• -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary
-XX:PrintNMTStatistics
PAKETO CHANGE DEFAULTS
• Calculator can be configured by passing environment variables
• BPL_JVM_HEAD_ROOM (Percentage to not be used)
• BPL_JVM_LOADED_CLASS_COUNT (Number of loaded classes)
• BPL_JVM_THREAD_COUNT (Number of expected threads)
• BPL_JVM_CLASS_ADJUSTMENT (as %, increments MaxMetaspace)
• BPL_JAVA_NMT_ENABLED (true or false, avoids memory report on OOM)
• JAVA_TOOL_OPTIONS (JVM launch flags, override paketo flags)
PAKETO CONCLUSION
• Sets parameters that fixed size of Non heap memory areas
• This can create OOMEs if not adjusted properly
• Containers may fail to start if memory ~512MB or less
• Once it calculates a Fixed non heap size for a container, if the container grows
the only parameter that will change is -Xmx
• -XX:MaxDirectMemorySize=10M might be too small, default value = Xmx, it might
be changed by passing it in the JAVA_TOOL_OPTIONS
THANKS
QUESTIONS?

More Related Content

PDF
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
PDF
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
ODP
Jvm tuning in a rush! - Lviv JUG
Tomek Borek
 
PDF
Java tuning on GNU/Linux for busy dev
Tomek Borek
 
PDF
GDG Cloud Southlake #20:Stefano Doni: Kubernetes performance tuning dilemma: ...
James Anderson
 
PDF
Mastering java in containers - MadridJUG
Jorge Morales
 
PDF
Java and Containers - Make it Awesome !
Dinakar Guniguntala
 
PDF
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
Jelastic Multi-Cloud PaaS
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
Secrets of Performance Tuning Java on Kubernetes
Bruno Borges
 
Jvm tuning in a rush! - Lviv JUG
Tomek Borek
 
Java tuning on GNU/Linux for busy dev
Tomek Borek
 
GDG Cloud Southlake #20:Stefano Doni: Kubernetes performance tuning dilemma: ...
James Anderson
 
Mastering java in containers - MadridJUG
Jorge Morales
 
Java and Containers - Make it Awesome !
Dinakar Guniguntala
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
Jelastic Multi-Cloud PaaS
 

Similar to Considerations when deploying Java on Kubernetes (20)

PDF
A Glance At The Java Performance Toolbox
Ana-Maria Mihalceanu
 
PDF
Java on Linux for devs and ops
aragozin
 
PDF
Running Java Applications inside Kubernetes with Nested Container Architectur...
Jelastic Multi-Cloud PaaS
 
PPTX
7 jvm-arguments-Confoo
Tier1 app
 
PDF
Taming The JVM
Matthew McCullough
 
PDF
A Glance At The Java Performance Toolbox-TIA.pdf
Ana-Maria Mihalceanu
 
PDF
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
PDF
Basics of JVM Tuning
Vladislav Gangan
 
PPTX
Dev Days Vilnius 2018 : Cloud Native Java with OpenJ9- Fast, Lean and definit...
Steve Poole
 
PPTX
JPrime_JITServer.pptx
Grace Jansen
 
PDF
Tuning Java for Big Data
Scott Seighman
 
PDF
Commit to excellence - Java in containers
Red Hat Developers
 
PPTX
Java performance tuning
Mohammed Fazuluddin
 
PDF
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
PDF
OOPs, OOMs, oh my! Containerizing JVM apps
Sematext Group, Inc.
 
PPTX
JVM Magic
Baruch Sadogursky
 
PDF
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Jean-Philippe BEMPEL
 
PDF
JITServerTalk Nebraska 2023.pdf
RichHagarty
 
PDF
JITServerTalk JCON World 2023.pdf
RichHagarty
 
PDF
JVMs in Containers - Best Practices
David Delabassee
 
A Glance At The Java Performance Toolbox
Ana-Maria Mihalceanu
 
Java on Linux for devs and ops
aragozin
 
Running Java Applications inside Kubernetes with Nested Container Architectur...
Jelastic Multi-Cloud PaaS
 
7 jvm-arguments-Confoo
Tier1 app
 
Taming The JVM
Matthew McCullough
 
A Glance At The Java Performance Toolbox-TIA.pdf
Ana-Maria Mihalceanu
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
Basics of JVM Tuning
Vladislav Gangan
 
Dev Days Vilnius 2018 : Cloud Native Java with OpenJ9- Fast, Lean and definit...
Steve Poole
 
JPrime_JITServer.pptx
Grace Jansen
 
Tuning Java for Big Data
Scott Seighman
 
Commit to excellence - Java in containers
Red Hat Developers
 
Java performance tuning
Mohammed Fazuluddin
 
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
OOPs, OOMs, oh my! Containerizing JVM apps
Sematext Group, Inc.
 
Javaday 2022 - Remèdes aux oomkill, warm-ups, et lenteurs pour des conteneur...
Jean-Philippe BEMPEL
 
JITServerTalk Nebraska 2023.pdf
RichHagarty
 
JITServerTalk JCON World 2023.pdf
RichHagarty
 
JVMs in Containers - Best Practices
David Delabassee
 
Ad

More from superserch (12)

PDF
Identificando problemas en el JVM
superserch
 
PDF
Introducción al manejo de memoria en el JVM
superserch
 
PDF
Lambda & Stream API workshop 2019
superserch
 
PDF
OWASP Top 10 2017
superserch
 
PDF
Garbage Collection en el JVM
superserch
 
PDF
Jvmmx docker jvm
superserch
 
PDF
Cloudino workshopcpmx7
superserch
 
PDF
Workshop: Lambdas y Stream API en Java 8
superserch
 
PDF
Jvmmx jigsaw
superserch
 
PDF
Chela stress test
superserch
 
PDF
Zed Attack Proxy
superserch
 
PDF
Inyección, XSS, CSRF en ChelaJS
superserch
 
Identificando problemas en el JVM
superserch
 
Introducción al manejo de memoria en el JVM
superserch
 
Lambda & Stream API workshop 2019
superserch
 
OWASP Top 10 2017
superserch
 
Garbage Collection en el JVM
superserch
 
Jvmmx docker jvm
superserch
 
Cloudino workshopcpmx7
superserch
 
Workshop: Lambdas y Stream API en Java 8
superserch
 
Jvmmx jigsaw
superserch
 
Chela stress test
superserch
 
Zed Attack Proxy
superserch
 
Inyección, XSS, CSRF en ChelaJS
superserch
 
Ad

Recently uploaded (20)

PPTX
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
PDF
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PDF
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
PDF
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
PPT
FALLSEM2025-26_ISWE304L_TH_VL2025260102786_2025-07-10_Reference-Material-II.ppt
AKSHAYA255427
 
PDF
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
PDF
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PPTX
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
PDF
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
PDF
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
PPTX
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
PPTX
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
DOCX
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
PPTX
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
PDF
Rise With SAP partner in Mumbai.........
pts464036
 
Presentation of Computer CLASS 2 .pptx
darshilchaudhary558
 
Microsoft Teams Essentials; The pricing and the versions_PDF.pdf
Q-Advise
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Community & News Update Q2 Meet Up 2025
VictoriaMetrics
 
Multi-factor Authentication (MFA) requirement for Microsoft 365 Admin Center_...
Q-Advise
 
FALLSEM2025-26_ISWE304L_TH_VL2025260102786_2025-07-10_Reference-Material-II.ppt
AKSHAYA255427
 
Emergency Mustering solutions – A Brief overview
Personnel Tracking
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
How to Seamlessly Integrate Salesforce Data Cloud with Marketing Cloud.pdf
NSIQINFOTECH
 
QAware_Mario-Leander_Reimer_Architecting and Building a K8s-based AI Platform...
QAware GmbH
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Save Business Costs with CRM Software for Insurance Agents
Insurance Tech Services
 
Comprehensive Salesforce Implementation Services.pdf
VALiNTRY360
 
The Role of Automation and AI in EHS Management for Data Centers.pdf
TECH EHS Solution
 
Why Use Open Source Reporting Tools for Business Intelligence.pptx
Varsha Nayak
 
What to Capture When It Breaks: 16 Artifacts That Reveal Root Causes
Tier1 app
 
The Future of Smart Factories Why Embedded Analytics Leads the Way
Varsha Nayak
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
10 Hidden App Development Costs That Can Sink Your Startup.pptx
Lunar Web Solution
 
Rise With SAP partner in Mumbai.........
pts464036
 

Considerations when deploying Java on Kubernetes

  • 1. CONSIDERATIONS WHEN DEPLOYING JAVA APPLICATIONS TO KUBERNETES* * OR ANY CONTAINER BASED ENVIRONMENT @superserch
  • 2. AGENDA • Kubernetes – request and limit • JVM – Threads and Memory spaces • Default Ergonomics on JVM • Conflict • Tuning recommendations • Cloud Foundry Paketo buildpacks
  • 3. KUBERNETES – REQUEST AND LIMIT • Platform that provides services to deploy Pods (one or more containers) • Splits CPU and memory of Worker Nodes between all containers in that node • Uses linux cgroup v2 technology to constrain resources • CPU shared as processing power by time unit – throttling might happen • Memory involves all processes runing inside a container – it can be killed by oom • Request – what needs to be available on a node to be scheduled • Limit – Usage that Linux kernel will enforce on the container
  • 4. JVM – THREADS AND MEMORY SPACES • Java Virtual Machine – Memory is managed by the JVM, not the programmer • Every Java application is multithreaded • JVM will configure itself based on the detected environment • JVM has different memory areas where it stores data • Heap memory – User data • Meta space memory – Class metadata and constant pool • Stack and DirectMemory • Not every OOME causes the JVM to crash
  • 5. ERGONOMICS AND HEURISTICS ON JVM • Ergonomics: the study of working conditions, especially the design of equipment and furniture, in order to help people work more efficiently • Heuristics: a method of solving problems by finding practical ways of dealing with them, learning from past experience
  • 6. ERGONOMICS ON JVM – GARBAGE COLLECTOR • Server class machine • G1GC • SerialGC • No server class machine • SerialGC
  • 7. ERGONOMICS ON JVM – GARBAGE COLLECTOR • Server class machine • G1GC • SerialGC • No server class machine • SerialGC • Server class machine • Available Processors > 1 • Available Memory > 2GB (-256MB)
  • 8. ERGONOMICS ON JVM – MEMORY HEAP • Memory > 512MB • 25% MaxHeap • Memory < 512MB • Varies from 25% up to 50% MaxHeap • jmap -histo[:live] <pid> • Instances and bytes
  • 9. ERGONOMICS ON JVM – MEMORY HEAP • Memory > 512MB • 25% MaxHeap • Memory < 512MB • Varies from 25% up to 50% MaxHeap • jmap -histo[:live] <pid> • Instances and bytes
  • 10. ERGONOMICS ON JVM – MEMORY METASPACE • This is off-heap memory • Initial reserved space: 1GB • If CompresedOpps are on MetaSpace will have a location table • Each class uses ~1K class space and ~8k non-class space per class • jcmd <pid> VM.metaspace • Can be limited with -XX:MaxMetaspaceSize and -XX:CompressedClassSpaceSize
  • 11. ERGONOMICS ON JVM – MEMORY METASPACE • This is off-heap memory • Initial reserved space: 1GB • If CompresedOpps are on MetaSpace will have a location table • Each class uses ~1K class space and ~8k non-class space per class • jcmd <pid> VM.metaspace • Can be limited with -XX:MaxMetaspaceSize and -XX:CompressedClassSpaceSize
  • 12. CONFLICT • Kubernetes will try to maintain the desired state • If a container goes beyond its memory limit it will be killed • If a container goes beyond its CPU Quota limit it will be throtteled • If a container does not respond to liveness readines it will be restarted • JVM will use as many threads as possible to do concurrent tasks • If too limited internal processes will be limited (GC, Default Executors) • When under load JVM might be paused by Linux kernel because CPU Quota • If memory is not set Java Heap might get funny values
  • 13. TUNING RECOMMENDATIONS - CPU • Use -XX:ActiveProcessorCount to set the desired concurrency level • JVM won’t consume more CPU than its quota, but this setting will help in selecting the paralellism of internal structures • Is a good idea to know the CPU profile of your application, you could use Jconsole, jfr, or even top • Monitor kubernetes for CPU throttling of your containers
  • 14. TUNING RECOMMENDATIONS – GARBAGE COLLECTORS • SerialGC • Default if less than 2 processors or less than 1792MB of Memory • No overhead because it stops the world to GC • GC Pause might be an issue if heap over 1GB or container throtteled • High tail-latency effect • -XX:+UseSerialGC
  • 15. TUNING RECOMMENDATIONS – GARBAGE COLLECTORS • ParallelGC • No overhead because it stops the world to GC • GC Pause might be an issue if heap over 4GB or container throtteled • Great for batch workloads • High tail-latency effect • Configure at least 2000m cpu_limit • -XX:+UseParallelGC
  • 16. TUNING RECOMMENDATIONS – GARBAGE COLLECTORS • G1GC • Default if at least 2 processors and more than 1792MB of Memory • some overhead because it marks regions that have changed • GC Pauses might be an issue if allocation rates are too high • High tail-latency effect • Configure at least 2000m cpu_limit • -XX:+UseG1GC
  • 17. TUNING RECOMMENDATIONS – GARBAGE COLLECTORS • ZGC • moderated overhead because it does marking concurently with app • GC Pauses are usually under 1ms • Low tail-latency effect • JDK17+ • Since JDK23 is generational • Configure at least 2000m cpu_limit • -XX:+UseZGC
  • 18. TUNING RECOMMENDATIONS – GARBAGE COLLECTORS • ShenandoahGC • moderated overhead because it does marking concurently with app • GC Pauses are usually under 10ms • Moderated tail-latency effect • JDK11+ • Configure at least 2000m cpu_limit • -XX:+UseShenandoahGC
  • 19. TUNING RECOMMENDATIONS – MEMORY • It is convenient to know what your application has and does • Number of classes to be loaded • Use of ByteBuffer • Size of Live dataset • Size of work area • Number of threads
  • 20. TUNING RECOMMENDATIONS – MEMORY • Set the Heap size • -Xmx • -Xmx3g • -XX:MaxRAMPercentage • -XX:MaxRamPercentage=75 • Consider than memory_limit > Heap + MetaSpace + Stack + DirectMemory + spare • Monitor Kubernetes OOM resets and adjust heap size or memory_limit
  • 21. TUNING RECOMMENDATIONS – KUBERNETES • Make cpu_request = cpu_limit and memory_request = memory_limit • Kubernetes calculates scheduling of pods based on request values • Assign enough cpu so application and probes can run concurrently
  • 22. TUNING RECOMMENDATIONS • What about setting -Xms = -Xmx ? • It not just reserves but commits memory for heap • Avoids heap resizing
  • 23. CLOUD FOUNDRY PAKETO BUILDPACKS • Nice tool to build containers • At this moment defaults to BellSoft Liberica JRE 17 • It can pack a JRE or even a JLINK version of the selected JDK • It can configure some Application servers or Spring Boot applications • Adds a launcher layer that inspects environment and sets JVM parameters • This configuration is aimed to avoid OOM resets
  • 24. CLOUD FOUNDRY PAKETO BUILDPACKS Heap Heap = Total Container Memory - Non Heap - Headroom Non Heap Non Heap = Direct Memory + Metaspace + Reserved Code cache + (Thread Stack * Thread Count ) Headroom defaults to 0
  • 25. PAKETO DEFAULT VALUES • Direct Memory – 10MB • Reserved Code Cache – 240MB • Thread Stack – 1M (Assumes 250 threads running) • Metaspace – Calculated on class count (35% * 5800 + 14M)
  • 26. PAKETO DEFAULT PARAMETERS • -XX:+ExitOnOutOfMemoryError • -XX:MaxDirectMemory • -Xmx • -XX:MaxMetaspaceSize • -XX:ReservedCodeCacheSize • -Xss • -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:PrintNMTStatistics
  • 27. PAKETO CHANGE DEFAULTS • Calculator can be configured by passing environment variables • BPL_JVM_HEAD_ROOM (Percentage to not be used) • BPL_JVM_LOADED_CLASS_COUNT (Number of loaded classes) • BPL_JVM_THREAD_COUNT (Number of expected threads) • BPL_JVM_CLASS_ADJUSTMENT (as %, increments MaxMetaspace) • BPL_JAVA_NMT_ENABLED (true or false, avoids memory report on OOM) • JAVA_TOOL_OPTIONS (JVM launch flags, override paketo flags)
  • 28. PAKETO CONCLUSION • Sets parameters that fixed size of Non heap memory areas • This can create OOMEs if not adjusted properly • Containers may fail to start if memory ~512MB or less • Once it calculates a Fixed non heap size for a container, if the container grows the only parameter that will change is -Xmx • -XX:MaxDirectMemorySize=10M might be too small, default value = Xmx, it might be changed by passing it in the JAVA_TOOL_OPTIONS