Skip to content

Instantly share code, notes, and snippets.

@avorobyov
Last active August 23, 2017 02:03
Show Gist options
  • Save avorobyov/268479e85f99d197a1dac644d273029c to your computer and use it in GitHub Desktop.
Save avorobyov/268479e85f99d197a1dac644d273029c to your computer and use it in GitHub Desktop.
Java in Docker pitfalls presentation

Java in Docker pitfalls


Why Java is a special case

  • JVM ergonomics
  • Libraries ergonomics

JVM and libraries decide how much memory and how many threads to use. This decision is based on a host hardware configuration. JVM and some libraries are designed to take a full advantage of all available resources.


Docker is a leaking abstraction

  • Docker uses Linux namespaces and cgroups
  • In a docker instance, an application can access a host hardware configuration
  • Java doesn't know about Docker, cgroups and namespaces (before April 2017)

Memory examples

  • What if memory limit is less than JVM wants to allocate for heap
  • What if memory limit is a little bit more than JVM wants to allocate for heap

JVM allocates memory for

  • Heap
  • Metaspace
  • Code
  • GC
  • Threads
  • Native objects

CPU examples

All dockerised JVMs think they exclusevely have all cores.


Java 9 and Java 8 u131(April 2017)

  • CPU limits work out of the box
  • for a memory, JVM option is still required

Q&A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment