Docker and jvm. A good idea?

65
Docker and the JVM, a good idea? Christopher Batey @chbatey

Transcript of Docker and jvm. A good idea?

Page 1: Docker and jvm. A good idea?

Docker and the JVM, a good idea?

Christopher Batey@chbatey

Page 2: Docker and jvm. A good idea?

@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?

@chbatey

Page 4: Docker and jvm. A good idea?

@chbatey

Page 5: Docker and jvm. A good idea?

@chbatey

rat-pack

dropwizard

wiremock

● 12 cores w/ hyper-threading● 64GB RAM

Apache Benchmark

Page 6: Docker and jvm. A good idea?

@chbatey

Motivation

5

Page 7: Docker and jvm. A good idea?

@chbatey

Deployment models

Host

App

Page 8: Docker and jvm. A good idea?

@chbatey

So why?

Page 9: Docker and jvm. A good idea?

@chbatey

Multiple JVMs on the same machine?

Page 10: Docker and jvm. A good idea?

@chbatey

JVM ergonomics

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html

Page 11: Docker and jvm. A good idea?

@chbatey

What

9

Page 12: Docker and jvm. A good idea?

@chbatey

Docker

● Namespaces○ Process○ Mounts○ Networking

● CGroups○ CPU○ Memory

Page 13: Docker and jvm. A good idea?

Tools & Examples

12.5

Page 14: Docker and jvm. A good idea?

@chbatey

Tools

● Ps, Htop and Top● Systemd-cg{ls, top}● Dstat● Cadvisor● Heapster● Jcmd● dmesg

Page 15: Docker and jvm. A good idea?

@chbatey

Images

Page 16: Docker and jvm. A good idea?

@chbatey

Images

Page 17: Docker and jvm. A good idea?

@chbatey

PID namespace

Page 18: Docker and jvm. A good idea?

@chbatey

Tool: Htop

Page 19: Docker and jvm. A good idea?

@chbatey

Tool: Top

Page 20: Docker and jvm. A good idea?

@chbatey

Tool: systemd-cgls

Page 21: Docker and jvm. A good idea?

@chbatey

Wtf?

Page 22: Docker and jvm. A good idea?

@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?

@chbatey

Memory

20

Page 24: Docker and jvm. A good idea?

@chbatey

Limiting memory

Page 25: Docker and jvm. A good idea?

Free inside a container

/proc/* is not control group aware

Page 26: Docker and jvm. A good idea?

@chbatey

Limiting memory

Page 27: Docker and jvm. A good idea?

@chbatey

Tool: Dmesg

Page 28: Docker and jvm. A good idea?

@chbatey

More memory

Page 29: Docker and jvm. A good idea?

@chbatey

Survives \o/

Page 30: Docker and jvm. A good idea?

@chbatey

Survives \o/ but is slow :(

Page 31: Docker and jvm. A good idea?

@chbatey

Tool: systemd-cgtop

Page 32: Docker and jvm. A good idea?

@chbatey

Tool: DStat

Page 33: Docker and jvm. A good idea?

@chbatey

Tool: systemd-cgtop

Page 34: Docker and jvm. A good idea?

@chbatey

Tool: Htop

Page 35: Docker and jvm. A good idea?

@chbatey

Disabling swap

Page 36: Docker and jvm. A good idea?

@chbatey

Disabling swap

Page 37: Docker and jvm. A good idea?

@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?

@chbatey

Native Memory Tracking

-XX:NativeMemoryTracking=summary

Page 39: Docker and jvm. A good idea?

@chbatey

Tool: jcmd

● JCmd allows us to see a JVMs memory usage

Page 40: Docker and jvm. A good idea?

@chbatey

Tool: jcmd

● Jcmd VM.native_memory● 100+ Threads?

Page 41: Docker and jvm. A good idea?

@chbatey

Tool: Jcmd

Jcmd Thread.print

Page 42: Docker and jvm. A good idea?

@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?

@chbatey

Wtf?

Page 44: Docker and jvm. A good idea?

@chbatey

Overriding

Page 45: Docker and jvm. A good idea?

@chbatey

Solution?

Page 46: Docker and jvm. A good idea?

@chbatey

Solution?

Page 47: Docker and jvm. A good idea?

@chbatey

Ratpack threads

jcmd 26 Thread.print | grep "ratpack-compute" | wc -l

24

Page 48: Docker and jvm. A good idea?

@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?

@chbatey

It isn’t just your web framework

Page 50: Docker and jvm. A good idea?

@chbatey

CPU

40

Page 51: Docker and jvm. A good idea?

@chbatey

Page 52: Docker and jvm. A good idea?

@chbatey

Page 53: Docker and jvm. A good idea?

@chbatey

Page 54: Docker and jvm. A good idea?

@chbatey

Page 55: Docker and jvm. A good idea?

@chbatey

Limiting CPU - shares

Page 56: Docker and jvm. A good idea?

@chbatey

Page 57: Docker and jvm. A good idea?

@chbatey

Tool: systemd-cgtop

Page 58: Docker and jvm. A good idea?

@chbatey

Understanding CPU shares

1024 512 512

CPU 0 CPU 1

Page 59: Docker and jvm. A good idea?

@chbatey

Understanding CPU shares

1024 512 512

Page 60: Docker and jvm. A good idea?

CPU quota

Cpu_period = 100000

One cores = 100000

Two cores = 200000

etc

Page 61: Docker and jvm. A good idea?

@chbatey

That is more like it! Or is it?

Page 62: Docker and jvm. A good idea?

@chbatey

Page 63: Docker and jvm. A good idea?

@chbatey

JVM inside containers

● Get an appropriate number of threads● Size memory and test

Page 64: Docker and jvm. A good idea?

@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?

@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