This is a basic Spring Boot app which can be used to demonstrate memory consumptions. As any regular microservice app this one would contain:
- rest endpoints
- db repository
- kafka publisher/subscriber
- http client
Before running the app please ensure to compile the following subprojects:
- eureka
- gateway
- microservice
You can compile them with gradle wrapper:
gradlew build
Once all required jars are compiled you can launch the entire stack:
docker-compose up --build
This would start and prepare all necessary components including db, kafka, eureka, gateway, etc.
After the app is launched you can use the following endpoints:
GET http://localhost:8080/microservice
GET http://localhost:8080/microservice/{id}
POST http://localhost:8080/microservice
application/json {"name":"serviceA"}
After the app is launched and you have verified that endpoints work properly it might be required to simulate workload. Execute the following command to launch workload simulation:
docker-compose -f docker-compose-workload.yaml up --build
By default the application is not limited on both docker and java heap.
Modify microservice java command in docker-compose file to add Xmx:
java -Xmx100m
To set limits for microservice app container add the following to docker compose:
deploy:
resources:
limits:
memory: 300M
microservice application is the one that should be examined for memory consumption.
You can check memory consumption by connecting to port 3333.
Simply execute docker stats
. spring-boot-playground_microservice_1 - is the container to be tracked.
Firstly you need to identify java app PID:
docker exec spring-boot-playground_microservice_1 ps
and then execute for required PID:
docker exec spring-boot-playground_microservice_1 jcmd 9 VM.native_memory summary