thingsboard-edge icon indicating copy to clipboard operation
thingsboard-edge copied to clipboard

GraalVM Native Image

Open ryan-2048 opened this issue 10 months ago • 4 comments

Is it possible to support compiling Native Images with GraalVM? I have encountered reflection issues. If it can be compiled into binary files, it will be a great success for low performance machines!

======================================================================================================================== GraalVM Native Image: Generating 'tb-edge-3.5.1.1EDGE-boot' (executable)...

[1/7] Initializing... (7.3s @ 0.23GB) Version info: 'GraalVM 22.3.5 Java 11 EE' Java version info: '11.0.22+9-LTS-jvmci-22.3-b32' C compiler: gcc (linux, x86_64, 9.4.0) Garbage collector: Serial GC [2/7] Performing analysis... [******] (25.2s @ 1.11GB) 3,547 (75.12%) of 4,722 classes reachable 4,613 (55.13%) of 8,368 fields reachable 17,333 (48.80%) of 35,519 methods reachable 147 classes, 0 fields, and 475 methods registered for reflection 59 classes, 59 fields, and 52 methods registered for JNI access 4 native libraries: dl, pthread, rt, z [3/7] Building universe... (2.6s @ 1.70GB)

Warning: Reflection method java.lang.Class.forName invoked at org.springframework.boot.loader.PropertiesLauncher.wrapWithCustomClassLoader(PropertiesLauncher.java:368) Warning: Reflection method java.lang.Class.forName invoked at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:46) Warning: Reflection method java.lang.Class.getMethod invoked at org.springframework.boot.loader.jar.JarFileEntries.(JarFileEntries.java:66) Warning: Reflection method java.lang.Class.getDeclaredMethod invoked at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:47) Warning: Reflection method java.lang.Class.getDeclaredConstructor invoked at org.springframework.boot.loader.PropertiesLauncher.newClassLoader(PropertiesLauncher.java:385) Warning: Reflection method java.lang.Class.getDeclaredConstructor invoked at org.springframework.boot.loader.jar.Handler.getFallbackHandler(Handler.java:200) Warning: Aborting stand-alone image build due to reflection use without configuration. Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception

                    1.0s (2.7% of total time) in 15 GCs | Peak RSS: 2.25GB | CPU load: 3.25

======================================================================================================================== Failed generating 'tb-edge-3.5.1.1EDGE-boot' after 35.5s. Generating fallback image... Warning: Image 'tb-edge-3.5.1.1EDGE-boot' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).

ryan-2048 avatar Apr 08 '24 10:04 ryan-2048

Hi, @Kevin-ox.

Could you provide more details of your configuration?

Here is my flow: I recently updated to the latest version of tb-edge on Ubuntu by installing the .deb package from the site. To leverage the capabilities of JVMCI (JVM Compiler Interface), which is supported in Java 11, I made some adjustments to the tb-edge.conf configuration file. Specifically, I appended the following JAVA_OPTS to enable JVMCI and specify GraalVM as the compiler, including an option to display the compiler configuration information:

export JAVA_OPTS="$JAVA_OPTS -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI -XX:+UseJVMCICompiler -Dgraal.ShowConfiguration=info"

As a result, it enabled me to use GraalVM as a compiler with a specific log:

Using Graal compiler configuration 'community' provided by org.graalvm.compiler.hotspot.CommunityCompilerConfigurationFactory loaded from jrt:/jdk.internal.vm.compiler/org/graalvm/compiler/hotspot/CommunityCompilerConfigurationFactory.class

Regarding the status of tb-edge, running service tb-edge status might display some errors, but it's important to note that these don't impact the functioning of Edge, and it operates as expected. image

AndriiLandiak avatar Apr 10 '24 13:04 AndriiLandiak

I am closing this issue due to inactivity. Please feel free to reopen it if you have any more questions.

AndriiLandiak avatar Jun 06 '24 12:06 AndriiLandiak

I wanted to release a native image (instead of a. jar file) to greatly improve performance, but was unsuccessful.

ryan-2048 avatar Jul 18 '24 00:07 ryan-2048

@AndriiLandiak

ryan-2048 avatar Jul 18 '24 00:07 ryan-2048