docker and jvm. a good idea?
TRANSCRIPT
![Page 1: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/1.jpg)
Docker and the JVM, a good idea?
Christopher Batey@chbatey
![Page 2: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/2.jpg)
@chbatey
Overview
● Motivation● How they work● What you need to know
○ Tools○ Problems by example
■ Thread per request (Dropwizard/Jetty)■ Thread per core (Ratpack/Netty)
![Page 3: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/3.jpg)
@chbatey
![Page 4: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/4.jpg)
@chbatey
![Page 5: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/5.jpg)
@chbatey
rat-pack
dropwizard
wiremock
● 12 cores w/ hyper-threading● 64GB RAM
Apache Benchmark
![Page 6: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/6.jpg)
@chbatey
Motivation
5
![Page 7: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/7.jpg)
@chbatey
Deployment models
Host
App
![Page 8: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/8.jpg)
@chbatey
So why?
![Page 9: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/9.jpg)
@chbatey
Multiple JVMs on the same machine?
![Page 10: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/10.jpg)
@chbatey
JVM ergonomics
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html
![Page 11: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/11.jpg)
@chbatey
What
9
![Page 12: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/12.jpg)
@chbatey
Docker
● Namespaces○ Process○ Mounts○ Networking
● CGroups○ CPU○ Memory
![Page 13: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/13.jpg)
Tools & Examples
12.5
![Page 14: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/14.jpg)
@chbatey
Tools
● Ps, Htop and Top● Systemd-cg{ls, top}● Dstat● Cadvisor● Heapster● Jcmd● dmesg
![Page 15: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/15.jpg)
@chbatey
Images
![Page 16: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/16.jpg)
@chbatey
Images
![Page 17: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/17.jpg)
@chbatey
PID namespace
![Page 18: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/18.jpg)
@chbatey
Tool: Htop
![Page 19: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/19.jpg)
@chbatey
Tool: Top
![Page 20: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/20.jpg)
@chbatey
Tool: systemd-cgls
![Page 21: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/21.jpg)
@chbatey
Wtf?
![Page 22: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/22.jpg)
@chbatey
Control Groups (cgroups)
● CPU - shares● Memory - limit
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-cpu.html
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-memory.html
![Page 23: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/23.jpg)
@chbatey
Memory
20
![Page 24: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/24.jpg)
@chbatey
Limiting memory
![Page 25: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/25.jpg)
Free inside a container
/proc/* is not control group aware
![Page 26: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/26.jpg)
@chbatey
Limiting memory
![Page 27: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/27.jpg)
@chbatey
Tool: Dmesg
![Page 28: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/28.jpg)
@chbatey
More memory
![Page 29: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/29.jpg)
@chbatey
Survives \o/
![Page 30: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/30.jpg)
@chbatey
Survives \o/ but is slow :(
![Page 31: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/31.jpg)
@chbatey
Tool: systemd-cgtop
![Page 32: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/32.jpg)
@chbatey
Tool: DStat
![Page 33: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/33.jpg)
@chbatey
Tool: systemd-cgtop
![Page 34: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/34.jpg)
@chbatey
Tool: Htop
![Page 35: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/35.jpg)
@chbatey
Disabling swap
![Page 36: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/36.jpg)
@chbatey
Disabling swap
![Page 37: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/37.jpg)
@chbatey
Sizing the memory for a JVM
● Heap● Threads ● Metaspace● Code● GC● Native (direct ByteBuffers and sun.misc.Unsafe)
30
![Page 38: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/38.jpg)
@chbatey
Native Memory Tracking
-XX:NativeMemoryTracking=summary
![Page 39: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/39.jpg)
@chbatey
Tool: jcmd
● JCmd allows us to see a JVMs memory usage
![Page 40: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/40.jpg)
@chbatey
Tool: jcmd
● Jcmd VM.native_memory● 100+ Threads?
![Page 41: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/41.jpg)
@chbatey
Tool: Jcmd
Jcmd Thread.print
![Page 42: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/42.jpg)
@chbatey
It isn’t just one thread pool in Jetty!
jcmd 26 Thread.print | grep "dw" | wc -l
65
jcmd 26 Thread.print | grep "selector" | wc -l
24
jcmd 26 Thread.print | grep "acceptor" | wc -l
12
![Page 43: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/43.jpg)
@chbatey
Wtf?
![Page 44: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/44.jpg)
@chbatey
Overriding
![Page 45: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/45.jpg)
@chbatey
Solution?
![Page 46: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/46.jpg)
@chbatey
Solution?
![Page 47: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/47.jpg)
@chbatey
Ratpack threads
jcmd 26 Thread.print | grep "ratpack-compute" | wc -l
24
![Page 48: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/48.jpg)
@chbatey
It isn’t just your web framework
jcmd 26 Thread.print | grep G1 | wc -l
15
jcmd 26 Thread.print | grep "C1\|C2" | wc -l
4
![Page 49: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/49.jpg)
@chbatey
It isn’t just your web framework
![Page 50: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/50.jpg)
@chbatey
CPU
40
![Page 51: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/51.jpg)
@chbatey
![Page 52: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/52.jpg)
@chbatey
![Page 53: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/53.jpg)
@chbatey
![Page 54: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/54.jpg)
@chbatey
![Page 55: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/55.jpg)
@chbatey
Limiting CPU - shares
![Page 56: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/56.jpg)
@chbatey
![Page 57: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/57.jpg)
@chbatey
Tool: systemd-cgtop
![Page 58: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/58.jpg)
@chbatey
Understanding CPU shares
1024 512 512
CPU 0 CPU 1
![Page 59: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/59.jpg)
@chbatey
Understanding CPU shares
1024 512 512
![Page 60: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/60.jpg)
CPU quota
Cpu_period = 100000
One cores = 100000
Two cores = 200000
etc
![Page 61: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/61.jpg)
@chbatey
That is more like it! Or is it?
![Page 62: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/62.jpg)
@chbatey
![Page 63: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/63.jpg)
@chbatey
JVM inside containers
● Get an appropriate number of threads● Size memory and test
![Page 64: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/64.jpg)
@chbatey
Thanks for listening
Github: https://github.com/chbatey/docker-jvm-talk
Twitter: @chbatey
Want to work (in London) with Docker, Rkt, Kubernetes, Go, Java, Python, Cassandra, MySQL? [email protected]
![Page 65: Docker and jvm. A good idea?](https://reader031.vdocuments.us/reader031/viewer/2022021812/589d9b341a28abfb3d8b5a1b/html5/thumbnails/65.jpg)
@chbatey
Why I care
● Accidently become a Platform Engineer / Site Reliability Engineer○ Team of three that builds an internal PaaS for 100s of applications
● Tech:○ AWS○ Docker○ Kubernetes (custom build)○ Cassandra○ MySQL○ Prometheus