2

I have written a Spring Boot application with Kotlin and Coroutine. It utilizes springs reactive-stack (Webflux). When looking at the runtime performance, I was a bit spoilt.

enter image description here

The image shows the memory and CPU consumption over time. In the beginning, I run a penetration test which results in high CPU usage and a constant memory increase. What puzzles me is that even when the application idles, memory usage does not decrease any more.

Is this normal behaviour or is there something wrong with the application?

Linde_98
  • 418
  • 4
  • 10
  • Did you check for any leaks ? – Anshul Aug 09 '21 at 18:06
  • 1
    How were those graphs generated?  In particular, did the memory use come from the JVM (e.g. via VisualVM or `jmap`)?  Or was it from the OS?  (I'm guessing the latter.)  Bear in mind that the OS only knows how much memory is allocated to the JVM process; it doesn't know how much of that is allocated to the heap, nor how much of that heap is actually in use.  (JVMs traditionally request more memory from the OS if the heap is getting full, but never return it to the OS even if the heap is empty.) – gidds Aug 09 '21 at 20:31
  • It comes from the os – Linde_98 Aug 11 '21 at 12:41
  • If you're using React, you might be interested in the answer I wrote here https://stackoverflow.com/questions/68681786/java-heap-dump-how-to-find-the-objects-class-that-is-taking-memory-by-1-io-ne/68727220#68727220, since there is also native memory usage to take into account. – Erik Finnman Aug 18 '21 at 14:56

1 Answers1

2

Is this normal behaviour or is there something wrong with the application?

Without more information, it's impossible to say.

This could be normal behaviour. Memory in the JVM is freed up by garbage collection. The garbage collector cleans up objects that are no longer being used. It has its own rules for deciding when and how to do that. In particular, it tries to free up memory when the application needs it. If the application is idle and doesn't need any memory to allocate new objects, the garbage collector might not run.

On the other hand, it might be that your application is still holding references to some data, preventing it from being garbage collected. If there's any variable or data structure in your application that still holds a reference to an object, that object won't be garbage collected. Over time, this would eventually mean that the garbage collector would not be able to free up any new memory and the application would crash.

If you want to be sure, you should try running your test several times. If your application is working well, you will see the memory graph drop right down when the heap starts to get full, and then gradually rise again. This results in a characteristic "sawtooth" memory usage graph.

Sam
  • 8,330
  • 2
  • 26
  • 51