skip to Main Content

I’m running a Java application within a Docker with 1g of maximum RAM. I’ve reduced the Java heap to -Xmx256m. Despite that, the Java process is using much more and very often goes beyond 1g making it being killed by the OS. I’ve read about Java native memory and basically understand what is happening.

But except adding enough swap and accepting the potential performance penalty, is there a way to minimize the required memory (including the native memory) ? I’ve been mentioned to look at GraalVM : any feedback ? Does it mean, for example, I would need to compile my application for the different architectures (Intel, ARM, …) ?

2

Answers


  1. regarding using less RAM at runtime, GraalVM Native Image would definitely give you that. Depends on what your app is doing, you can even go much lower than 256M. But yes you would need to compile for each platform separately. Something like GitHub actions can help there.

    Login or Signup to reply.
  2. JIT (Just-In-Time) and AOT (Ahead-of-Time) compilation are two different approaches to compiling and executing code in a programming language.

    Here are the differences between them

    Compilation Timing

    JIT: In JIT compilation, code is compiled and executed on-the-fly, at runtime. When a program is run, the source code or intermediate code is translated into machine code just before it is executed.

    AOT: AOT compilation occurs ahead of time, typically before the program is run. The entire code is compiled into machine code or a lower-level representation before execution.

    Execution Speed

    JIT: JIT-compiled code can have a slightly slower startup time because of the compilation step, but it may optimize code for the specific runtime environment, potentially improving execution speed during the application’s lifecycle.
    AOT: AOT-compiled code generally has faster startup times because there is no need for on-the-fly compilation. However, it may not adapt to the runtime environment as effectively as JIT-compiled code.

    Resource Utilization

    JIT: JIT compilation can consume additional memory and CPU resources during the compilation process. Once the code is compiled, it can be more memory-efficient because it optimizes for the specific execution paths.
    AOT: AOT-compiled code tends to consume less memory and CPU resources during execution since there is no in-memory compilation process. However, it may not be as resource-efficient as JIT-compiled code in terms of execution speed.

    Portability

    JIT: JIT-compiled code can be more portable since it can adapt to different runtime environments. It is often used in cross-platform applications.

    AOT: AOT-compiled code may be less portable because it is optimized for a specific platform or architecture, and recompilation may be required for different environments.

    enter image description here

    In Java, only JIT Compilation running on jvm was previously available. GraalVM enables AOT Compilation (native compilation)

    It would be better to choose a more appropriate strategy based on the characteristics required by the system. In this situation, saving memory is important, so I think the AOT compilation will be very helpful

    U can Check this Blog. In this blog, when compiled using gralvm, it saves about 40% of memory.

    enter image description here

    https://medium.com/graalvm/graalvm-for-jdk-21-is-here-ee01177dd12d

    I think u r using Spring Boot, Checking this document will be helpful.

    https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search