SlideShare a Scribd company logo
Nobody* puts Java in a Container
@joerg_schad, Mesosphere
© 2017 Mesosphere, Inc. All Rights Reserved. 2
© 2017 Mesosphere, Inc. All Rights Reserved. 3
© 2017 Mesosphere, Inc. All Rights Reserved. 4
What is this about?
© 2017 Mesosphere, Inc. All Rights Reserved. 5
Jörg Schad
Distributed Systems Engineer,
Mesosphere
@joerg_schad
© 2017 Mesosphere, Inc. All Rights Reserved. 6
! Datacenter-wide services to power your apps
! Turnkey installation and lifecycle management
DC/OS Universe
DC/OS
Any Infrastructure
! Container operations & big data operations
! Security, fault tolerance & high availability
! Open Source (ASL2.0)
! Based on Apache Mesos
! Production proven at scale
! Requires only a modern linux distro 

(windows coming soon)
! Hybrid Datacenter
Why do I care?
Datacenter Operating System (DC/OS)
Distributed Systems Kernel (Mesos)
Big Data + Analytics EnginesMicroservices ( containers)
Streaming
Batch
Machine Learning
Analytics
Functions
& Logic Search
Time Series
SQL / NoSQL
Databases
Modern App Components
Any Infrastructure (Physical, Virtual, Cloud)
© Gerard Julien/
Containers
© 2017 Mesosphere, Inc. All Rights Reserved. 8
Write Once Run Any Where
© 2017 Mesosphere, Inc. All Rights Reserved. 9
Virtual Machines vs Container
Server
Host Os
Hypervisor
Guest Os
Bins/Libs
Application
Guest Os
Bins/Libs
Application 2
Server
Host Os
DockerEngine
Bins/Libs Bins/Libs
Application Application 2
Virtual Machine Container
© 2017 Mesosphere, Inc. All Rights Reserved. 10
Virtual Machines vs Container
Server
Host Os
Hypervisor
Guest Os
Bins/Libs
Application
Guest Os
Bins/Libs
Application 2
Server
Host Os
DockerEngine
Bins/Libs Bins/Libs
Application Application 2
! Weaker isolation in
container
! Container run near-native
speed CPU/IO
! Container launch in around
0.1 second (libcontainer)
! Less storage and memory
overhead
Virtual Machine Container
© 2017 Mesosphere, Inc. All Rights Reserved. 11
$ ps faux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 33636 2960 ? Ss Oct17 0:00 /sbin/init
...
root 12972 0.0 3.9 757236 40704 ? Ssl 01:55 0:18 /usr/bin/dockerd --raw-logs
root 12981 0.0 0.9 299096 9384 ? Ssl 01:55 0:01 _ docker-containerd -l unix:///var/run/docker/libcontainerd/docker-
root 13850 0.0 0.4 199036 4180 ? Sl 01:58 0:00 _ docker-containerd-shim 2f86cbc34/var/run/docker/l
root 13867 0.0 0.2 31752 2884 ? Ss 01:58 0:00 | _ nginx: master process nginx -g daemon off;
sshd 13889 0.0 0.1 32144 1664 ? S 01:58 0:00 | _ nginx: worker process
root 17642 0.0 0.4 199036 4188 ? Sl 11:54 0:00 _ docker-containerd-shim /var/run/docker/l
root 17661 99.2 0.0 1172 4 ? Rs 11:54 23:37 | _ md5sum /dev/urandom
root 18340 0.0 0.4 199036 4144 ? Sl 12:16 0:00 _ docker-containerd-shim 4121c64749262112b /var/run/docker/l
vagrant 18353 0.0 0.0 1164 4 ? Ss 12:16 0:00 _ sleep 1000
docker run -d nginx:1.10
© 2017 Mesosphere, Inc. All Rights Reserved. 12
Container …
!=
• container runtime* != container image != container instance
• beyond docker runtime
• Universal Container Runtime
• supports docker images
• CRI{-o}
•…
© 2017 Mesosphere, Inc. All Rights Reserved. 13
Container …
{
"id": "/springboot-demo",
"cmd": "$JAVA_HOME/bin/java -jar MyApp.jar",
"instances": 1,
"fetch": [
{
"uri": "http://…/MyApp.jar",
},
{
"uri": "https://.../jre-8u121-linux-x64.tar.gz",
}
],
© 2017 Mesosphere, Inc. All Rights Reserved. 14
Isolation
© 2017 Mesosphere, Inc. All Rights Reserved. 15
(LINUX) KERNEL
LAYER FS
CGROUPS NAMESPACES
LIBCONTAINER
DOCKER
© 2016 Mesosphere, Inc. All Rights Reserved. 16
Namespaces provide isolated views:
• pid (processes)
• net (network interfaces, routing...)
• ipc (System V IPC)
• mnt (mount points, filesystems)
• uts (hostname)
• user (UIDs)
Control groups control resources:
• cpu (CPU shares)
• cpuacct
• cpuset (limit processes to a CPU)
• memory (swap, dirty pages)
• blkio (throttle reads/writes)
• devices
• net_cls, net_prio: control packet class and
priority
• freezer
Namespaces VS. Cgroups
© 2017 Mesosphere, Inc. All Rights Reserved. 17
Control Groups
© 2017 Mesosphere, Inc. All Rights Reserved. 18
Control groups (v1)
• /sys/fs/cgroup
• Each subsystem (memory, CPU...) has a
hierarchy (tree)
• Each process belongs to exactly 1 node in
each hierarchy
• Each hierarchy starts with 1 node (the root)
• Each node = group of processes (sharing the
same resources)
cgroups V2
© 2017 Mesosphere, Inc. All Rights Reserved. 19
Memory cgroup: limits
docker run -it --rm -m 128m fedora bash
•Each group can have hard and soft limits
•Soft limits are not enforced
•Hard limits will trigger a per-group OOM killer
•No OutOfMemoryError
•Limits can be set for physical, kernel, total memory
© 2017 Mesosphere, Inc. All Rights Reserved. 20
Cpu cgroup
• Simple Accounting
• Metrics: cpuacct.stats user | system
• Limitations
• CPU Shares
• CPU Sets
© 2017 Mesosphere, Inc. All Rights Reserved. 21
CPU Shares
docker run -it --rm -c 512 stress …
• Priority Weighting across all the cores
• default 1024
• Use CFS for hard limit
sudo cgcreate -g cpu:A
sudo cgcreate -g cpu:B
cgroup A: sudo cgset -r cpu.shares=768 A 75%
cgroup B: sudo cgset -r cpu.shares=256 B 25%
© 2017 Mesosphere, Inc. All Rights Reserved. 22
CPU Sets
docker run -it -cpuset=0,4,6 stress
• Pin groups to specific CPU(s)
• Reserve CPUs for specific apps
• Avoid processes bouncing between CPUs
• Also relevant for NUMA systems
© 2017 Mesosphere, Inc. All Rights Reserved. 23
Namespaces
© 2017 Mesosphere, Inc. All Rights Reserved. 24
Namespaces
• Provide container (= process groups) with their
own view of the system
• Multiple namespaces:
– pid, net, mnt, uts, ipc, user
• Each process is in one namespace of each type
© 2017 Mesosphere, Inc. All Rights Reserved. 25
Pid namespace
• Processes within a PID namespace only see processes in the
same PID namespace
• Each PID namespace has its own numbering (starting at 1)
• When PID 1 goes away, the whole namespace is killed
ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 106628 31480 ? Ss 09:00 0:00 /opt/mesosphere/active/mesos/libexec/mesos/mesos-containerizer launch
root 6 0.0 0.2 776872 37712 ? Sl 09:00 0:01 mesos-executor --launcher_dir=/opt/mesosphere/active/mesos/libexec/mesos --
sandbox_directory=/m
root 16 0.0 0.0 4512 792 ? Ss 09:00 0:00 sh -c sleep 100000
root 17 0.0 0.0 4384 664 ? S 09:00 0:00 sleep 100000
root 264 0.2 0.1 106492 31016 ? Ss 09:32 0:00 /opt/mesosphere/active/mesos/libexec/mesos/mesos-containerizer launch
root 265 0.0 0.0 18240 3316 ? S 09:32 0:00 /bin/bash
root 276 0.0 0.0 34428 2872 ? R+ 09:33 0:00 ps aux
© 2017 Mesosphere, Inc. All Rights Reserved. 26
Lets Talk Java
© 2017 Mesosphere, Inc. All Rights Reserved. 27
Java
Java Language + Java Specification + Java Runtime
© 2017 Mesosphere, Inc. All Rights Reserved. 28
Java Memory Impact
• Native JRE
• Heap
• Perm / meta
• JIT bytecode
• JNI
• NIO
• Threads
2* Heap
© 2017 Mesosphere, Inc. All Rights Reserved. 29
From Perm to Metaspace
© 2017 Mesosphere, Inc. All Rights Reserved. 30
JRE default initializations
• Based on core count*
• JIT compiler threads
• HotSpot thresholds and optimizations
• Default # threads for GC
• Number of thread in the common fork-join pool
• …
© 2017 Mesosphere, Inc. All Rights Reserved. 31
Bring it together!
© 2017 Mesosphere, Inc. All Rights Reserved. 32
Java meets Container
• Development
• Java App packaged in a container
© 2017 Mesosphere, Inc. All Rights Reserved. 33
Java meets Container
• Development
• Java App packaged in a container
• Production
• 10 JVM container on a 32 core box
– 10 * (32 cores are seen by each JRE)
– 10 * (32 threads set by default for ForkJoinPool)
– 10 * (32 threads ….)
© 2017 Mesosphere, Inc. All Rights Reserved. 34
Java meets Cgroups
https://cloakable.irdeto.com/2017/08/24/java-is-a-first-class-citizen-in-a-docker-ecosystem-now/
© 2017 Mesosphere, Inc. All Rights Reserved. 35
Where Java retrieve the core count?
• JDK 7/8 - resources from sysconf
sysconf(_SC_NPROCESSORS_ONLN);
• JDK 9 - sched_getaffinity
–accounts for cpusets
© 2017 Mesosphere, Inc. All Rights Reserved. 36
Java with CPU Set
docker run -ti --cpuset=0,4,6 …
• CPUSET
–pin to specific CPUs
• Runtime.getRuntime().availableProcessors(); ==
# cores assigned*
© 2017 Mesosphere, Inc. All Rights Reserved. 37
Java with CPU Share
docker run -ti -c 512 …
• CPU Share
–Priority Weighting across all the cores
–Runtime.getRuntime().availableProcessors(); ==
# cores on node
© 2017 Mesosphere, Inc. All Rights Reserved. 38
How about memory?
• /proc/meminfo
• /proc/vmstat
• /proc/PID/smaps
© 2017 Mesosphere, Inc. All Rights Reserved. 39
But… Java 9
© 2017 Mesosphere, Inc. All Rights Reserved. 40
Java 9
• CPU
• Considers CPU sets
• Not aware of CPU shares…
• Memory
• -XX:+UseCGroupMemoryLimitForHeap
• -XX:+UnlockExperimentalVMOptions
© 2017 Mesosphere, Inc. All Rights Reserved. 41
The two sides of container…
Kirk Pepperdine
• “The good thing about docker containers (and some
other like containers) is that they don’t hide the
underlying hardware from processes like VM
technology does.”
• “The bad thing about docker containers (and some other
like containers) is that they don’t hide the underlying
hardware from processes like VM technology does.”
Thank You!
@joerg_schad
© 2017 Mesosphere, Inc. All Rights Reserved. 43
Thank You!
Learn more by visiting dcos.io and mesosphere.com
P.S.
https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/

More Related Content

PDF
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
PDF
CI / CD / CS - Continuous Security in Kubernetes
PPSX
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
ODP
Testing Wi-Fi with OSS Tools
PDF
Tupperware: Containerized Deployment at FB
PDF
Microservices with Micronaut
PDF
Deploying Kubernetes without scaring off your security team - KubeCon 2017
PPTX
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs...
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
CI / CD / CS - Continuous Security in Kubernetes
Oded Coster - Stack Overflow behind the scenes - how it's made - Codemotion M...
Testing Wi-Fi with OSS Tools
Tupperware: Containerized Deployment at FB
Microservices with Micronaut
Deploying Kubernetes without scaring off your security team - KubeCon 2017
Orchestration tool roundup kubernetes vs. docker vs. heat vs. terra form vs...

What's hot (20)

PDF
Docker and Maestro for fun, development and profit
PDF
What Prometheus means for monitoring vendors
PPTX
Thinking Inside the Container: A Continuous Delivery Story by Maxfield Stewart
PDF
DockerCon EU 2015: The Glue is the Hard Part: Making a Production-Ready PaaS
PDF
Dependencies and Licenses
PDF
How to Monitor Microservices
PDF
All Things Open 2017: How to Treat a Network as a Container
PDF
Troubleshooting Tips from a Docker Support Engineer
PDF
Chaos Engineering for Docker
PDF
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
PDF
runC: The little engine that could (run Docker containers) by Docker Captain ...
PDF
Proactive ops for container orchestration environments
PDF
Microservices: 5 Things I Wish I'd Known - Code Motion Milan 2017
PDF
Container Days Boston - Kubernetes in production
PDF
PDF
Introduction to Ansible
PDF
Global Operations with Docker for the Enterprise - Nico Kabar, Docker
PDF
How to improve ELK log pipeline performance
PDF
What's New in Docker 1.12 (June 20, 2016) by Mike Goelzer & Andrea Luzzardi
PPTX
Container Monitoring with Sysdig
Docker and Maestro for fun, development and profit
What Prometheus means for monitoring vendors
Thinking Inside the Container: A Continuous Delivery Story by Maxfield Stewart
DockerCon EU 2015: The Glue is the Hard Part: Making a Production-Ready PaaS
Dependencies and Licenses
How to Monitor Microservices
All Things Open 2017: How to Treat a Network as a Container
Troubleshooting Tips from a Docker Support Engineer
Chaos Engineering for Docker
Docker 對傳統 DevOps 工具鏈的衝擊 (Docker's Impact on traditional DevOps toolchain)
runC: The little engine that could (run Docker containers) by Docker Captain ...
Proactive ops for container orchestration environments
Microservices: 5 Things I Wish I'd Known - Code Motion Milan 2017
Container Days Boston - Kubernetes in production
Introduction to Ansible
Global Operations with Docker for the Enterprise - Nico Kabar, Docker
How to improve ELK log pipeline performance
What's New in Docker 1.12 (June 20, 2016) by Mike Goelzer & Andrea Luzzardi
Container Monitoring with Sysdig
Ad

Viewers also liked (20)

PDF
Andrea Tosatto - Kubernetes Beyond - Codemotion Milan 2017
PDF
Advanced memory allocation
PPTX
Graduating To Go - A Jumpstart into the Go Programming Language
PPTX
Walk through an enterprise Linux migration
PPTX
Docker Networking
PDF
Scale Up with Lock-Free Algorithms @ JavaOne
PDF
Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)
PDF
OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...
PDF
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
PDF
numPYNQ @ NGCLE@e-Novia 15.11.2017
PPT
DevRomagna / Golang Intro
PPTX
Communication hardware
PPTX
In-Memory Computing Essentials for Architects and Engineers
PPTX
What in the World is Going on at The Linux Foundation?
PDF
Go Execution Tracer
PPTX
Virtualization
PPTX
Server virtualization
PPTX
SDN Architecture & Ecosystem
PDF
In-depth forensic analysis of Windows registry files
PPTX
OpenFlow
Andrea Tosatto - Kubernetes Beyond - Codemotion Milan 2017
Advanced memory allocation
Graduating To Go - A Jumpstart into the Go Programming Language
Walk through an enterprise Linux migration
Docker Networking
Scale Up with Lock-Free Algorithms @ JavaOne
Linux Security APIs and the Chromium Sandbox (SwedenCpp Meetup 2017)
OCCIware, an extensible, standard-based XaaS consumer platform to manage ever...
[若渴計畫] Challenges and Solutions of Window Remote Shellcode
numPYNQ @ NGCLE@e-Novia 15.11.2017
DevRomagna / Golang Intro
Communication hardware
In-Memory Computing Essentials for Architects and Engineers
What in the World is Going on at The Linux Foundation?
Go Execution Tracer
Virtualization
Server virtualization
SDN Architecture & Ecosystem
In-depth forensic analysis of Windows registry files
OpenFlow
Ad

Similar to Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017 (20)

PDF
DOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
PDF
Spark Summit EU talk by Jorg Schad
PDF
No one puts java in the container
PDF
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
PDF
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
PPTX
Why you’re going to fail running java on docker!
PDF
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
PPTX
Introduction to OS LEVEL Virtualization & Containers
PDF
Docker and friends at Linux Days 2014 in Prague
PDF
Evolution of containers to kubernetes
PDF
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
PPTX
Dealing with kubesprawl tetris style !
PDF
You Call that Micro, Mr. Docker? How OSv and Unikernels Help Micro-services S...
PDF
OSDC 2016 - Mesos and the Architecture of the New Datacenter by Jörg Schad
PDF
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
PDF
OSDC 2018 | From batch to pipelines – why Apache Mesos and DC/OS are a soluti...
PDF
Docker Introduction + what is new in 0.9
PDF
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
PPTX
Containerization - The DevOps Revolution
PDF
Java in containers
DOD 2016 - Jörg Schad - Nobody Puts Java in the Conainer
Spark Summit EU talk by Jorg Schad
No one puts java in the container
Lightweight Virtualization with Linux Containers and Docker | YaC 2013
Lightweight Virtualization with Linux Containers and Docker I YaC 2013
Why you’re going to fail running java on docker!
Building Web Scale Apps with Docker and Mesos by Alex Rukletsov (Mesosphere)
Introduction to OS LEVEL Virtualization & Containers
Docker and friends at Linux Days 2014 in Prague
Evolution of containers to kubernetes
"Lightweight Virtualization with Linux Containers and Docker". Jerome Petazzo...
Dealing with kubesprawl tetris style !
You Call that Micro, Mr. Docker? How OSv and Unikernels Help Micro-services S...
OSDC 2016 - Mesos and the Architecture of the New Datacenter by Jörg Schad
Anatomy of a Container: Namespaces, cgroups & Some Filesystem Magic - LinuxCon
OSDC 2018 | From batch to pipelines – why Apache Mesos and DC/OS are a soluti...
Docker Introduction + what is new in 0.9
Docker Introduction, and what's new in 0.9 — Docker Palo Alto at RelateIQ
Containerization - The DevOps Revolution
Java in containers

More from Codemotion (20)

PDF
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
PDF
Pompili - From hero to_zero: The FatalNoise neverending story
PPTX
Pastore - Commodore 65 - La storia
PPTX
Pennisi - Essere Richard Altwasser
PPTX
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
PPTX
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
PPTX
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
PPTX
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
PDF
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
PDF
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
PDF
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
PDF
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
PDF
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
PDF
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
PPTX
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
PPTX
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
PDF
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
PDF
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
PDF
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
PDF
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Pompili - From hero to_zero: The FatalNoise neverending story
Pastore - Commodore 65 - La storia
Pennisi - Essere Richard Altwasser
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Empathic Computing: Creating Shared Understanding
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Cloud computing and distributed systems.
PDF
Electronic commerce courselecture one. Pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
Building Integrated photovoltaic BIPV_UPV.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Review of recent advances in non-invasive hemoglobin estimation
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Empathic Computing: Creating Shared Understanding
Per capita expenditure prediction using model stacking based on satellite ima...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
Assigned Numbers - 2025 - Bluetooth® Document
Cloud computing and distributed systems.
Electronic commerce courselecture one. Pdf
The AUB Centre for AI in Media Proposal.docx

Jörg Schad - NO ONE PUTS Java IN THE CONTAINER - Codemotion Milan 2017

  • 1. Nobody* puts Java in a Container @joerg_schad, Mesosphere
  • 2. © 2017 Mesosphere, Inc. All Rights Reserved. 2
  • 3. © 2017 Mesosphere, Inc. All Rights Reserved. 3
  • 4. © 2017 Mesosphere, Inc. All Rights Reserved. 4 What is this about?
  • 5. © 2017 Mesosphere, Inc. All Rights Reserved. 5 Jörg Schad Distributed Systems Engineer, Mesosphere @joerg_schad
  • 6. © 2017 Mesosphere, Inc. All Rights Reserved. 6 ! Datacenter-wide services to power your apps ! Turnkey installation and lifecycle management DC/OS Universe DC/OS Any Infrastructure ! Container operations & big data operations ! Security, fault tolerance & high availability ! Open Source (ASL2.0) ! Based on Apache Mesos ! Production proven at scale ! Requires only a modern linux distro 
 (windows coming soon) ! Hybrid Datacenter Why do I care? Datacenter Operating System (DC/OS) Distributed Systems Kernel (Mesos) Big Data + Analytics EnginesMicroservices ( containers) Streaming Batch Machine Learning Analytics Functions & Logic Search Time Series SQL / NoSQL Databases Modern App Components Any Infrastructure (Physical, Virtual, Cloud)
  • 8. © 2017 Mesosphere, Inc. All Rights Reserved. 8 Write Once Run Any Where
  • 9. © 2017 Mesosphere, Inc. All Rights Reserved. 9 Virtual Machines vs Container Server Host Os Hypervisor Guest Os Bins/Libs Application Guest Os Bins/Libs Application 2 Server Host Os DockerEngine Bins/Libs Bins/Libs Application Application 2 Virtual Machine Container
  • 10. © 2017 Mesosphere, Inc. All Rights Reserved. 10 Virtual Machines vs Container Server Host Os Hypervisor Guest Os Bins/Libs Application Guest Os Bins/Libs Application 2 Server Host Os DockerEngine Bins/Libs Bins/Libs Application Application 2 ! Weaker isolation in container ! Container run near-native speed CPU/IO ! Container launch in around 0.1 second (libcontainer) ! Less storage and memory overhead Virtual Machine Container
  • 11. © 2017 Mesosphere, Inc. All Rights Reserved. 11 $ ps faux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 33636 2960 ? Ss Oct17 0:00 /sbin/init ... root 12972 0.0 3.9 757236 40704 ? Ssl 01:55 0:18 /usr/bin/dockerd --raw-logs root 12981 0.0 0.9 299096 9384 ? Ssl 01:55 0:01 _ docker-containerd -l unix:///var/run/docker/libcontainerd/docker- root 13850 0.0 0.4 199036 4180 ? Sl 01:58 0:00 _ docker-containerd-shim 2f86cbc34/var/run/docker/l root 13867 0.0 0.2 31752 2884 ? Ss 01:58 0:00 | _ nginx: master process nginx -g daemon off; sshd 13889 0.0 0.1 32144 1664 ? S 01:58 0:00 | _ nginx: worker process root 17642 0.0 0.4 199036 4188 ? Sl 11:54 0:00 _ docker-containerd-shim /var/run/docker/l root 17661 99.2 0.0 1172 4 ? Rs 11:54 23:37 | _ md5sum /dev/urandom root 18340 0.0 0.4 199036 4144 ? Sl 12:16 0:00 _ docker-containerd-shim 4121c64749262112b /var/run/docker/l vagrant 18353 0.0 0.0 1164 4 ? Ss 12:16 0:00 _ sleep 1000 docker run -d nginx:1.10
  • 12. © 2017 Mesosphere, Inc. All Rights Reserved. 12 Container … != • container runtime* != container image != container instance • beyond docker runtime • Universal Container Runtime • supports docker images • CRI{-o} •…
  • 13. © 2017 Mesosphere, Inc. All Rights Reserved. 13 Container … { "id": "/springboot-demo", "cmd": "$JAVA_HOME/bin/java -jar MyApp.jar", "instances": 1, "fetch": [ { "uri": "http://…/MyApp.jar", }, { "uri": "https://.../jre-8u121-linux-x64.tar.gz", } ],
  • 14. © 2017 Mesosphere, Inc. All Rights Reserved. 14 Isolation
  • 15. © 2017 Mesosphere, Inc. All Rights Reserved. 15 (LINUX) KERNEL LAYER FS CGROUPS NAMESPACES LIBCONTAINER DOCKER
  • 16. © 2016 Mesosphere, Inc. All Rights Reserved. 16 Namespaces provide isolated views: • pid (processes) • net (network interfaces, routing...) • ipc (System V IPC) • mnt (mount points, filesystems) • uts (hostname) • user (UIDs) Control groups control resources: • cpu (CPU shares) • cpuacct • cpuset (limit processes to a CPU) • memory (swap, dirty pages) • blkio (throttle reads/writes) • devices • net_cls, net_prio: control packet class and priority • freezer Namespaces VS. Cgroups
  • 17. © 2017 Mesosphere, Inc. All Rights Reserved. 17 Control Groups
  • 18. © 2017 Mesosphere, Inc. All Rights Reserved. 18 Control groups (v1) • /sys/fs/cgroup • Each subsystem (memory, CPU...) has a hierarchy (tree) • Each process belongs to exactly 1 node in each hierarchy • Each hierarchy starts with 1 node (the root) • Each node = group of processes (sharing the same resources) cgroups V2
  • 19. © 2017 Mesosphere, Inc. All Rights Reserved. 19 Memory cgroup: limits docker run -it --rm -m 128m fedora bash •Each group can have hard and soft limits •Soft limits are not enforced •Hard limits will trigger a per-group OOM killer •No OutOfMemoryError •Limits can be set for physical, kernel, total memory
  • 20. © 2017 Mesosphere, Inc. All Rights Reserved. 20 Cpu cgroup • Simple Accounting • Metrics: cpuacct.stats user | system • Limitations • CPU Shares • CPU Sets
  • 21. © 2017 Mesosphere, Inc. All Rights Reserved. 21 CPU Shares docker run -it --rm -c 512 stress … • Priority Weighting across all the cores • default 1024 • Use CFS for hard limit sudo cgcreate -g cpu:A sudo cgcreate -g cpu:B cgroup A: sudo cgset -r cpu.shares=768 A 75% cgroup B: sudo cgset -r cpu.shares=256 B 25%
  • 22. © 2017 Mesosphere, Inc. All Rights Reserved. 22 CPU Sets docker run -it -cpuset=0,4,6 stress • Pin groups to specific CPU(s) • Reserve CPUs for specific apps • Avoid processes bouncing between CPUs • Also relevant for NUMA systems
  • 23. © 2017 Mesosphere, Inc. All Rights Reserved. 23 Namespaces
  • 24. © 2017 Mesosphere, Inc. All Rights Reserved. 24 Namespaces • Provide container (= process groups) with their own view of the system • Multiple namespaces: – pid, net, mnt, uts, ipc, user • Each process is in one namespace of each type
  • 25. © 2017 Mesosphere, Inc. All Rights Reserved. 25 Pid namespace • Processes within a PID namespace only see processes in the same PID namespace • Each PID namespace has its own numbering (starting at 1) • When PID 1 goes away, the whole namespace is killed ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 106628 31480 ? Ss 09:00 0:00 /opt/mesosphere/active/mesos/libexec/mesos/mesos-containerizer launch root 6 0.0 0.2 776872 37712 ? Sl 09:00 0:01 mesos-executor --launcher_dir=/opt/mesosphere/active/mesos/libexec/mesos -- sandbox_directory=/m root 16 0.0 0.0 4512 792 ? Ss 09:00 0:00 sh -c sleep 100000 root 17 0.0 0.0 4384 664 ? S 09:00 0:00 sleep 100000 root 264 0.2 0.1 106492 31016 ? Ss 09:32 0:00 /opt/mesosphere/active/mesos/libexec/mesos/mesos-containerizer launch root 265 0.0 0.0 18240 3316 ? S 09:32 0:00 /bin/bash root 276 0.0 0.0 34428 2872 ? R+ 09:33 0:00 ps aux
  • 26. © 2017 Mesosphere, Inc. All Rights Reserved. 26 Lets Talk Java
  • 27. © 2017 Mesosphere, Inc. All Rights Reserved. 27 Java Java Language + Java Specification + Java Runtime
  • 28. © 2017 Mesosphere, Inc. All Rights Reserved. 28 Java Memory Impact • Native JRE • Heap • Perm / meta • JIT bytecode • JNI • NIO • Threads 2* Heap
  • 29. © 2017 Mesosphere, Inc. All Rights Reserved. 29 From Perm to Metaspace
  • 30. © 2017 Mesosphere, Inc. All Rights Reserved. 30 JRE default initializations • Based on core count* • JIT compiler threads • HotSpot thresholds and optimizations • Default # threads for GC • Number of thread in the common fork-join pool • …
  • 31. © 2017 Mesosphere, Inc. All Rights Reserved. 31 Bring it together!
  • 32. © 2017 Mesosphere, Inc. All Rights Reserved. 32 Java meets Container • Development • Java App packaged in a container
  • 33. © 2017 Mesosphere, Inc. All Rights Reserved. 33 Java meets Container • Development • Java App packaged in a container • Production • 10 JVM container on a 32 core box – 10 * (32 cores are seen by each JRE) – 10 * (32 threads set by default for ForkJoinPool) – 10 * (32 threads ….)
  • 34. © 2017 Mesosphere, Inc. All Rights Reserved. 34 Java meets Cgroups https://cloakable.irdeto.com/2017/08/24/java-is-a-first-class-citizen-in-a-docker-ecosystem-now/
  • 35. © 2017 Mesosphere, Inc. All Rights Reserved. 35 Where Java retrieve the core count? • JDK 7/8 - resources from sysconf sysconf(_SC_NPROCESSORS_ONLN); • JDK 9 - sched_getaffinity –accounts for cpusets
  • 36. © 2017 Mesosphere, Inc. All Rights Reserved. 36 Java with CPU Set docker run -ti --cpuset=0,4,6 … • CPUSET –pin to specific CPUs • Runtime.getRuntime().availableProcessors(); == # cores assigned*
  • 37. © 2017 Mesosphere, Inc. All Rights Reserved. 37 Java with CPU Share docker run -ti -c 512 … • CPU Share –Priority Weighting across all the cores –Runtime.getRuntime().availableProcessors(); == # cores on node
  • 38. © 2017 Mesosphere, Inc. All Rights Reserved. 38 How about memory? • /proc/meminfo • /proc/vmstat • /proc/PID/smaps
  • 39. © 2017 Mesosphere, Inc. All Rights Reserved. 39 But… Java 9
  • 40. © 2017 Mesosphere, Inc. All Rights Reserved. 40 Java 9 • CPU • Considers CPU sets • Not aware of CPU shares… • Memory • -XX:+UseCGroupMemoryLimitForHeap • -XX:+UnlockExperimentalVMOptions
  • 41. © 2017 Mesosphere, Inc. All Rights Reserved. 41 The two sides of container… Kirk Pepperdine • “The good thing about docker containers (and some other like containers) is that they don’t hide the underlying hardware from processes like VM technology does.” • “The bad thing about docker containers (and some other like containers) is that they don’t hide the underlying hardware from processes like VM technology does.”
  • 43. © 2017 Mesosphere, Inc. All Rights Reserved. 43 Thank You! Learn more by visiting dcos.io and mesosphere.com P.S. https://developers.redhat.com/blog/2017/04/04/openjdk-and-containers/