running java applications on docker: practical tips and ... · • by default, container will use...

53
Running Java applications on Docker: practical tips and valuable insights Fernando Babadopulos Tail @babadopulos

Upload: others

Post on 02-Jun-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

Running Java applications on Docker: practical tips and valuable insights

Fernando BabadopulosTail

@babadopulos

Page 2: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 3: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 4: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

MEMORY ALLOCATION

Page 5: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 6: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 7: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 8: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 9: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 10: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

Exception inthread...java.lang.OutOfMemoryError:Javaheap space

Page 11: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 12: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 13: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 14: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

• By default, container will use as much memory and swap as possible

• Can be restricted using -memory, -memory-reservation, —memory-swap

• Java SE 8u121 and earlier : unaware of container’s limited resources

• From Java SE 8u131 and in JDK 9: there is support for cgroup

Page 15: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

CPUs and Threads

Page 16: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

Estimating PIusing the MonteCarlomethod

0 1

1

πr2 =π/41x1=1

Ntotal

=

π ≈4 Ntotal

Page 17: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 18: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 19: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 20: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 21: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 22: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 23: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

LD_PRELOADHack

Page 24: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 25: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 26: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 27: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 28: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

RANDOM NUMBERS AND SECURITY

Page 29: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 30: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 31: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 32: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 33: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

haveged - asimpleentropydaemon

Page 34: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 35: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

DEBUGGING APPLICATIONS

Page 36: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 37: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 38: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 39: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 40: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 41: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 42: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

INTEGRATION TESTS

Page 43: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

STRATEGY:

- ONE DOCKER-COMPOSE.YML FOR THEAPPLICATION, ANOTHER ONE FOR TESTING

- START SERVICES- RUN APPLICATION- RUN INTEGRATION TESTS- STOP SERVICES

Page 44: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

CODE AT

HTTPS://GITHUB.COM/BABADOPULOS/DOCKER-JAVA-ISSUES-DEMO/TREE/MASTER/INTEGRATION-TESTS-SAMPLE

Page 45: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 46: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 47: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 48: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 49: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 50: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 51: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,
Page 52: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

REFERENCES:

Java inside docker: What you must know to not FAIL, byRafael Benevides

HTTPS://DEVELOPERS.REDHAT.COM/BLOG/2017/03/14/JAVA-INSIDE-DOCKER/

CONVERSATIONS WITH ELIJAH ZUPANCIC (@SHITSUKOISARU)

LD_PRELOAD HACK:HTTPS://STACKOVERFLOW.COM/QUESTIONS/22741859/DECEIVE-THE-

JVM-ABOUT-THE-NUMBER-OF-AVAILABLE-CORES-ON-LINUX/22762558#22762558

HTTPS://GITHUB.COM/BABADOPULOS/DOCKER-JAVA-ISSUES-DEMO

Page 53: Running Java applications on Docker: practical tips and ... · • By default, container will use as much memory and swap as possible • Can be restricted using -memory, -memory-reservation,

Running Java applications on Docker: practical tips and valuable insights

Fernando BabadopulosTail

@babadopulos