I am trying to use micronaut to create microservices that have a low memory overhead. From using micronaut I've had some issues with the memory starting low, on startup, but ballooning when put under load and not coming back down.
I am testing it with a small application that takes an item from a rest call, does some work, to simulate a memory spike, and store the results in a database. If I run the jar file the application starts with ~170mb memory and after the induced spike sits around ~700mb. The native image has similar results with albeit lower startup memory. Playing around with the xms and xmx numbers does help the jar version recover after the spike, although it causes the native image to crash during the spike.
Is this an issue with micronaut? Is there anything I can do to help it recover the memory?
Below are my tests and results
Using the micronaut.io/launch to create a java 11 application with kotlin, gradle, and the graalvm plugin. Also I'm using the gradle plugins that are included to build the application and native images.
java -jar build/docker/layers/application.jar
Start up
System memory | heap size |
---|---|
~174 mb | 50mb used 264mb total |
During spike
System memory | heap size |
---|---|
~1125 mb | 250mb used 520mb total |
After spike (which includes a gc call)
System memory | heap size |
---|---|
~711 mb | 24mb used 88mb total |
And with the native image, just the system memory
./build/native-image/application
before | during | after |
---|---|---|
13mb | 800mb | 800mb |