dockerized java for transylvanian jug
TRANSCRIPT
Getting Java> docker run --rm -it java java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (build 1.8.0_111...)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
01.
02.
03.
04.
12
Latest OpenJDK> docker run --rm -it openjdk java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131...)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
01.
02.
03.
04.
14
OpenJDKThe reality is that it is easier to get latest version of OpenJDK through
Docker Hub than through upstream distribution repositories (apt or
yum).“15
Easy?docker login container-registry.oracle.com
docker pull container-registry.oracle.com/java/serverjre
01.
02.
22
Azul's ZuluIt's a certified OpenJDK build.
Offers free extension that makes it on-par with HotSpot.
Dockerfiles: https://github.com/zulu-openjdk/zulu-openjdk.
Do not trust me, I haven't tested it! But it looks promising.
••••
26
Shutdown hook Runtime
.getRuntime()
.addShutdownHook(new Thread() {
public void run() { /*
my shutdown code here
*/ }
});
01.
02.
03.
04.
05.
06.
07.
46
ErgonomicsErgonomics is the process by which the Java Virtual Machine (JVM)
and garbage collection tuning, such as behavior-based tuning, improve
application performance. The JVM provides platform-dependent
default selections for the garbage collector, heap size, and runtime
compiler. These selections match the needs of different types of
applications while requiring less command-line tuning. In addition,
behavior-based tuning dynamically tunes the sizes of the heap to meet
a specified behavior of the application.
“48
Server-classA class of machine referred to as a server-class machine has been
defined as a machine with the following:
2 or more physical processors
2 or more GB of physical memory••
49
Server-classOn server-class machines, the following are selected by default:
Throughput garbage collector
Initial heap size of 1/64 of physical memory up to 1 GB
Maximum heap size of 1/4 of physical memory up to 1 GB
Server runtime compiler
••••
50
Namespaces and cgroupsName spaces limit the view of the system visible to the process
Control groups limit resources available to the process••
52
Memory limitsdocker run -dit \
--memory 100M \
--memory-swap -1 \
java \
java -Xmx100M MyServer
01.
02.
03.
04.
05.
53
Threading modelsThread per request (servlets and friends)
Thread per core (vert.x, ratpack, play etc.)••
63
JSON logging <dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.9</version>
</dependency>
01.
02.
03.
04.
05.
80
JSON logging<appender name="json" class="...">
...
<encoder
class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
01.
02.
03.
04.
05.
81
filebeat.ymlfilebeat.prospectors:
- input_type: log
paths: ["...."]
json.keys_under_root: true
json.overwrite_keys: true
json.add_error_key: true
json.message_key: "message"
tags: ["json"]
01.
02.
03.
04.
05.
06.
07.
08.
82
STDOUT as JSON$ docker run -itd jenkins
67aa...
$ tail -f /var/lib/docker/containers/67aa.../67aa..._json.log
...
{"log":"INFO: Jenkins is fully up and running\r\n",
"stream":"stdout","time":"2017-02-06T02:15:23.087459653Z"}
01.
02.
03.
04.
05.
06.
86
Take-awaysBuild base Docker images yourself
Plan the image hierarchy to reduce image deliverable sizes
Carefully tune memory and threads to make sure your Java containers
behave well while working on the same host
Use for the very latest Java 8 and Java 9 for better cgroups-
awareness
Take care of log aggregation (container's life is short)
•••
•
•
90
Referenceshttp://matthewkwilliams.com/index.php/2016/03/17/docker-cgroups-
memory-constraints-and-java-cautionary-tale/
https://www.slideshare.net/kensipe/no-one-puts-java-in-the-container
https://www.slideshare.net/chbatey/docker-and-jvm-a-good-idea
•
••
95
Referenceshttps://developers.redhat.com/blog/2017/03/14/java-inside-docker/
http://blog.jelastic.com/2017/04/13/java-ram-usage-in-containers-top-
5-tips-not-to-lose-your-memory/
https://www.infoq.com/news/2017/02/java-memory-limit-container
••
•
96
ReferencesErgonomics
Shutdown hook••
97
Issueshttps://bugs.openjdk.java.net/browse/JDK-8170888
https://bugs.openjdk.java.net/browse/JDK-8140793
https://bugs.openjdk.java.net/browse/JDK-8146115
•••
98