Docker and jvm. A good idea?
-
Upload
christopher-batey -
Category
Software
-
view
1.671 -
download
0
Transcript of Docker and jvm. A good idea?
Docker and the JVM, a good idea?
Christopher Batey@chbatey
@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)
@chbatey
@chbatey
@chbatey
rat-pack
dropwizard
wiremock
● 12 cores w/ hyper-threading● 64GB RAM
Apache Benchmark
@chbatey
Motivation
5
@chbatey
Deployment models
Host
App
@chbatey
So why?
@chbatey
Multiple JVMs on the same machine?
@chbatey
JVM ergonomics
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html
@chbatey
What
9
@chbatey
Docker
● Namespaces○ Process○ Mounts○ Networking
● CGroups○ CPU○ Memory
Tools & Examples
12.5
@chbatey
Tools
● Ps, Htop and Top● Systemd-cg{ls, top}● Dstat● Cadvisor● Heapster● Jcmd● dmesg
@chbatey
Images
@chbatey
Images
@chbatey
PID namespace
@chbatey
Tool: Htop
@chbatey
Tool: Top
@chbatey
Tool: systemd-cgls
@chbatey
Wtf?
@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
@chbatey
Memory
20
@chbatey
Limiting memory
Free inside a container
/proc/* is not control group aware
@chbatey
Limiting memory
@chbatey
Tool: Dmesg
@chbatey
More memory
@chbatey
Survives \o/
@chbatey
Survives \o/ but is slow :(
@chbatey
Tool: systemd-cgtop
@chbatey
Tool: DStat
@chbatey
Tool: systemd-cgtop
@chbatey
Tool: Htop
@chbatey
Disabling swap
@chbatey
Disabling swap
@chbatey
Sizing the memory for a JVM
● Heap● Threads ● Metaspace● Code● GC● Native (direct ByteBuffers and sun.misc.Unsafe)
30
@chbatey
Native Memory Tracking
-XX:NativeMemoryTracking=summary
@chbatey
Tool: jcmd
● JCmd allows us to see a JVMs memory usage
@chbatey
Tool: jcmd
● Jcmd VM.native_memory● 100+ Threads?
@chbatey
Tool: Jcmd
Jcmd Thread.print
@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
@chbatey
Wtf?
@chbatey
Overriding
@chbatey
Solution?
@chbatey
Solution?
@chbatey
Ratpack threads
jcmd 26 Thread.print | grep "ratpack-compute" | wc -l
24
@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
@chbatey
It isn’t just your web framework
@chbatey
CPU
40
@chbatey
@chbatey
@chbatey
@chbatey
@chbatey
Limiting CPU - shares
@chbatey
@chbatey
Tool: systemd-cgtop
@chbatey
Understanding CPU shares
1024 512 512
CPU 0 CPU 1
@chbatey
Understanding CPU shares
1024 512 512
CPU quota
Cpu_period = 100000
One cores = 100000
Two cores = 200000
etc
@chbatey
That is more like it! Or is it?
@chbatey
@chbatey
JVM inside containers
● Get an appropriate number of threads● Size memory and test
@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]
@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