3

Currently I'm testing with Microservices and Docker-Container. And during my last try with a Micronaut-Server I saw differences between the start-up-time for starting local (cmd) and starting with Docker. But what made me curios, is the fact that the Container was much faster.

I'm creating a runnable jar (more precisely a shadowjar - not sure what the exact difference is) with Gradle. Then I build a Docker-Image with that jar file. The start command for both is the same (see the Dockerfile below): java -jar micronaut.jar

During my search for a reason for that I found this question which is also about performance of Docker-Container, but the conclusion was more, that the Container should be slightly slower, not faster.

My Dockerfile:

FROM adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim
COPY build/libs/*.jar micronaut.jar
EXPOSE 8080
CMD java -jar micronaut.jar

and the docker command: docker run -p 9999:9999 -it --name dokuserver pge/dokuserver:0.1

I expected that the start-up-time would be the same oder a bit slower for the container but actually the time is.

  • Local: 4000-5000ms
  • Docker: ~2500ms

I tried several times but the outcome ist always nearly the same.

I'm working on a Win10 PC with DockerDesktop (Docker 19.03.1), IntelliJ and Gradle (5.5.1) and used the IntelliJ-Terminal and the windows-cmd for the local start.

I'm no an expert in Docker or the things which happens closer to the hardware so I couldn't find an answer for this speed difference. So I'm asking you:

What could cause that?

Asriel
  • 81
  • 10
  • 6
    You know if you want to compare Container against Host you must put the same OS right? I think maybe Win is slower than Linux even as a container. Also it is possible Java virtual implementations to be very different for the different platforms. – Level_Up Aug 08 '19 at 09:51
  • 2
    On windows & linux, already they all called JVM, but they actually two different apps, meanwhile as @Level_Up said, they are 2 different os, there are no meaning to do the compare here. – atline Aug 08 '19 at 09:55
  • Oh, I didn't knew that there are differences in JVMs. That could be a good explanation. Thank you two :) But it's an interessing fact, that the Linux version is faster than the Windows one. At least in this aspect. – Asriel Aug 08 '19 at 10:49

1 Answers1

5

AdoptOpenJDK has builds with two different JVMs: HotSpot and OpenJ9

HotSpot and OpenJ9 are totally different implementations of JVM with different JIT compilers, GC algorithms and internal architecture.

As your docker file suggests, you are using adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim which is a name suggests OpenJ9 based.

On Windows your are likely to use HotSpot based JVM (java -version to know for sure).

OpenJ9 has less aggressive compiler optimizations so difference in start up time is not surprising.

Alexey Ragozin
  • 8,081
  • 1
  • 23
  • 23
  • Ah. That's a good explanation. And after a bit more research for OpenJ9 and HotSpot it makes even more sense. Thank you vrey much! – Asriel Aug 09 '19 at 07:35
  • J9 does not have "less aggressive" compiler optimizations. It's just that the J9 team focused on balanced startup performance (to see the great results OP is seeing), but get elaborate as the program runs. There are benchmarks out there with single and sometimes double digit throughput advantages of J9 over HotSpot for the same Java code. – vmhacker Oct 19 '20 at 04:49