Skip to content

Commit

Permalink
Reduce memory consumption of Docker images #76 (#77)
Browse files Browse the repository at this point in the history
* Reduce memory consumption of Docker images #76

The fix switches from an outdated Oracle Java 8 Docker image
to the current openjdk:8 image. The Java VM of this image
supports the parameters to make the Java VM Docker aware.
With this option it becomes possible to set the memory
limit to 256MB which reduces the memory consumption by
75% and leaves the application still operational.

* Added a NOTE about the Docker VM resource usage on Mac and Win

This closes #76 and hopefully improves the first time user-experience
of the Docker compose way of running the demo microservices.
  • Loading branch information
mrumpf authored and mszarlinski committed May 2, 2018
1 parent cf84ed0 commit 387f824
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ After starting services it takes a while for API Gateway to be in sync with serv
so don't be scared of initial Zuul timeouts. You can track services availability using Eureka dashboard
available by default at http://localhost:8761.

*NOTE: Under MacOSX or Windows, make sure that the Docker VM has enough memory to run the microservices. The default settings
are usually not enough and make the `docker-compose up` painfully slow.*

## Understanding the Spring Petclinic application with a few diagrams
<a href="https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application">See the presentation here</a>

Expand Down
22 changes: 15 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,65 +3,71 @@ services:
config-server:
image: mszarlinski/spring-petclinic-config-server
container_name: config-server
mem_limit: 256M
ports:
- 8888:8888

discovery-server:
image: mszarlinski/spring-petclinic-discovery-server
container_name: discovery-server
mem_limit: 256M
links:
- config-server
depends_on:
- config-server
entrypoint: ["./wait-for-it.sh","config-server:8888","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","config-server:8888","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 8761:8761

customers-service:
image: mszarlinski/spring-petclinic-customers-service
container_name: customers-service
mem_limit: 256M
links:
- config-server
- discovery-server
- tracing-server
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 8081:8081

visits-service:
image: mszarlinski/spring-petclinic-visits-service
container_name: visits-service
mem_limit: 256M
links:
- config-server
- discovery-server
- tracing-server
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 8082:8082

vets-service:
image: mszarlinski/spring-petclinic-vets-service
container_name: vets-service
mem_limit: 256M
links:
- config-server
- discovery-server
- tracing-server
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 8083:8083

api-gateway:
image: mszarlinski/spring-petclinic-api-gateway
container_name: api-gateway
mem_limit: 256M
links:
- config-server
- discovery-server
Expand All @@ -72,32 +78,34 @@ services:
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 8080:8080

tracing-server:
image: mszarlinski/spring-petclinic-tracing-server
container_name: tracing-server
mem_limit: 256M
links:
- config-server
- discovery-server
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 9411:9411

admin-server:
image: mszarlinski/spring-petclinic-admin-server
container_name: admin-server
mem_limit: 256M
links:
- config-server
- discovery-server
depends_on:
- config-server
- discovery-server
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ports:
- 9090:9090
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM java:8
FROM openjdk:8
VOLUME /tmp
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh wait-for-it.sh
RUN bash -c 'chmod +x wait-for-it.sh'
Expand All @@ -7,4 +7,4 @@ ADD ${ARTIFACT_NAME}.jar /app.jar
ENV SPRING_PROFILES_ACTIVE docker
RUN bash -c 'touch /app.jar'
EXPOSE ${EXPOSED_PORT}
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
ENTRYPOINT ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

0 comments on commit 387f824

Please sign in to comment.