| <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Apache Dubbo – graalvm support</title><link>https://dubbo.apache.org/en/docs/v3.0/references/graalvm/</link><description>Recent content in graalvm support on Apache Dubbo</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="https://dubbo.apache.org/en/docs/v3.0/references/graalvm/index.xml" rel="self" type="application/rss+xml"/><item><title>Docs:</title><link>https://dubbo.apache.org/en/docs/v3.0/references/graalvm/support-graalvm/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://dubbo.apache.org/en/docs/v3.0/references/graalvm/support-graalvm/</guid><description> |
| <h2 id="overview">Overview</h2> |
| <p>This document will show you how to access GraalVM with a dubbo project and how to compile the project to a binary executable using native-image.</p> |
| <p>For more information about GraalVM, read <a href="https://www.graalvm.org/docs/getting-started/container-images/">https://www.graalvm.org/docs/getting-started/container-images/</a>.</p> |
| <h2 id="demo">Demo</h2> |
| <p>Before compiling the dubbo project, make sure that we are programming based on the GraalVM environment.</p> |
| <ol> |
| <li> |
| <p>Install GraalVM</p> |
| <p>Visite the official website (<a href="https://www.graalvm.org/">https://www.graalvm.org/</a> ) and install the latest version based on your system:</p> |
| </li> |
| </ol> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/graalvmgw.jpg" alt="img"></p> |
| <p>After installation, configure the path of JAVA_HOME. You should see thr following in your local jdk after this step:</p> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/graalvm_env.jpg" alt="img"></p> |
| <p>GraalVM we use here is based on jdk version 1.8. |
| To install native-image, run &lsquo;gu install native-image&rsquo;.</p> |
| <ol start="2"> |
| <li> |
| <p>Pull dubbo code and switch to branch <a href="https://github.com/apache/dubbo">apache:3.0</a>.</p> |
| </li> |
| <li> |
| <p>Manually generate SPI code</p> |
| <p>Currently native-image compiling does not support dynamic code generation. Therefore we need to first manually generate the part of the code that is generated dynamically. The tool function is provided here:</p> |
| </li> |
| </ol> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/code_generator.jpg" alt="img"></p> |
| <p>Execute CodeGenerator can generate SPI code under the dubbo-native module.</p> |
| <ol start="4"> |
| <li> |
| <p>Execute &lsquo;install&rsquo; under the root directory</p> |
| <div class="highlight"><pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-ruby" data-lang="ruby"><span style="display:flex;"><span><span style="color:#cb4b16">MacdeMacBook</span><span style="color:#719e07">-</span>pro<span style="color:#719e07">-</span><span style="color:#2aa198">3</span><span style="color:#2aa198">:incubator</span><span style="color:#719e07">-</span>dubbo mac$ pwd |
| </span></span><span style="display:flex;"><span><span style="color:#dc322f">/Users/m</span>ac<span style="color:#719e07">/</span><span style="color:#cb4b16">Documents</span><span style="color:#719e07">/</span><span style="color:#cb4b16">Mi</span><span style="color:#719e07">/</span>project<span style="color:#719e07">/</span>incubator<span style="color:#719e07">-</span>dubbo |
| </span></span><span style="display:flex;"><span><span style="color:#cb4b16">MacdeMacBook</span><span style="color:#719e07">-</span>pro<span style="color:#719e07">-</span><span style="color:#2aa198">3</span><span style="color:#2aa198">:incubator</span><span style="color:#719e07">-</span>dubbo mac$ mvn clean package install <span style="color:#719e07">-</span><span style="color:#cb4b16">Dmaven</span><span style="color:#719e07">.</span>test<span style="color:#719e07">.</span>skip<span style="color:#719e07">=</span><span style="color:#719e07">true</span> |
| </span></span></code></pre></div></li> |
| <li> |
| <p>Compile the project demo</p> |
| <p>Here we provide a demo project that can be directly compiled: dubbo-demo / dubbo-demo-native. After installation, first go to the provider in dubbo-demo-native and execute native-image compilation:</p> |
| <div class="highlight"><pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span> mvn clean <span style="color:#719e07">package</span> -P <span style="color:#268bd2">native</span> <span style="color:#719e07">-</span>Dmaven<span style="color:#719e07">.</span>test<span style="color:#719e07">.</span>skip<span style="color:#719e07">=</span><span style="color:#cb4b16">true</span> |
| </span></span></code></pre></div><p>Since we have imported native-image plugin in maven, here we can use &lsquo;-P native&rsquo; to execute the plugin.</p> |
| </li> |
| </ol> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/native_image_build.jpg" alt="img"></p> |
| <p>After a success compilation, we can find the generated binary file under target. Succefully iniate a zookeeper locally and execute the binary executable file should show us this:</p> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/run_provider.jpg" alt="img"></p> |
| <p>Compile on consumer&rsquo; side will generate a binary executable file &lsquo;demo-native-consumer&rsquo; under consumer&rsquo;s target. Execute the file will give us the following output:</p> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/run_consumer.jpg" alt="img"></p> |
| <h3 id="additional-steps">Additional Steps</h3> |
| <p>In this demo, we did extra work to make sure the project can be compiled. Here are the additional steps:</p> |
| <ul> |
| <li> |
| <p>Import dependency dubbo-native</p> |
| <div class="highlight"><pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-html" data-lang="html"><span style="display:flex;"><span>&lt;<span style="color:#268bd2">dependency</span>&gt; |
| </span></span><span style="display:flex;"><span> &lt;<span style="color:#268bd2">groupId</span>&gt;org.apache.dubbo&lt;/<span style="color:#268bd2">groupId</span>&gt; |
| </span></span><span style="display:flex;"><span> &lt;<span style="color:#268bd2">artifactId</span>&gt;dubbo-native&lt;/<span style="color:#268bd2">artifactId</span>&gt; |
| </span></span><span style="display:flex;"><span> &lt;<span style="color:#268bd2">version</span>&gt;${project.version}&lt;/<span style="color:#268bd2">version</span>&gt; |
| </span></span><span style="display:flex;"><span>&lt;/<span style="color:#268bd2">dependency</span>&gt; |
| </span></span></code></pre></div><p>Our generated SPI code is in this module.</p> |
| </li> |
| <li> |
| <p>Import native-image plug-in</p> |
| <div class="highlight"><pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-Lua" data-lang="Lua"><span style="display:flex;"><span><span style="color:#719e07">&lt;</span>plugin<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>groupId<span style="color:#719e07">&gt;</span>org.graalvm.nativeimage<span style="color:#719e07">&lt;/</span>groupId<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>artifactId<span style="color:#719e07">&gt;</span>native<span style="color:#719e07">-</span>image<span style="color:#719e07">-</span>maven<span style="color:#719e07">-</span>plugin<span style="color:#719e07">&lt;/</span>artifactId<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>version<span style="color:#719e07">&gt;</span><span style="color:#2aa198">21.0.0.2</span><span style="color:#719e07">&lt;/</span>version<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>executions<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>execution<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>goals<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>goal<span style="color:#719e07">&gt;</span>native<span style="color:#719e07">-</span>image<span style="color:#719e07">&lt;/</span>goal<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;/</span>goals<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>phase<span style="color:#719e07">&gt;</span>package<span style="color:#719e07">&lt;/</span>phase<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;/</span>execution<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;/</span>executions<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>configuration<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>skip<span style="color:#719e07">&gt;</span><span style="color:#cb4b16">false</span><span style="color:#719e07">&lt;/</span>skip<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>imageName<span style="color:#719e07">&gt;</span>demo<span style="color:#719e07">-</span>native<span style="color:#719e07">-</span>provider<span style="color:#719e07">&lt;/</span>imageName<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>mainClass<span style="color:#719e07">&gt;</span>org.apache.dubbo.demo.graalvm.provider.Application<span style="color:#719e07">&lt;/</span>mainClass<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;</span>buildArgs<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--no-fallback</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.slf4j.MDC</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.slf4j.LoggerFactory</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.apache.log4j.helpers.Loader</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.apache.log4j.Logger</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.apache.log4j.helpers.LogLog</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.apache.log4j.LogManager</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.apache.log4j.spi.LoggingEvent</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.slf4j.impl.Log4jLoggerFactory</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.slf4j.impl.Log4jLoggerAdapter</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-build-time=org.eclipse.collections.api.factory.Sets</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.epoll.Epoll</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.epoll.Native</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.epoll.EpollEventLoop</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.epoll.EpollEventArray</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.DefaultFileRegion</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventArray</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.kqueue.KQueueEventLoop</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.kqueue.Native</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.unix.Errors</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.unix.IovArray</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.unix.Limits</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.util.internal.logging.Log4JLogger</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.unix.Socket</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--initialize-at-run-time=io.netty.channel.ChannelHandlerMask</span> |
| </span></span><span style="display:flex;"><span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--report-unsupported-elements-at-runtime</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--allow-incomplete-classpath</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#586e75">--enable-url-protocols=http</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">-</span>H:<span style="color:#719e07">+</span>ReportExceptionStackTraces |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;/</span>buildArgs<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span> <span style="color:#719e07">&lt;/</span>configuration<span style="color:#719e07">&gt;</span> |
| </span></span><span style="display:flex;"><span><span style="color:#719e07">&lt;/</span>plugin<span style="color:#719e07">&gt;</span> |
| </span></span></code></pre></div><p>Generated image names and parameters used for generating image are defined.</p> |
| </li> |
| <li> |
| <p>Mount native-image-agent</p> |
| <p>Since some classes, including reflection and JNI, need to be assigned, we have to use the agent to run the json information that generate these classes.</p> |
| <p>Add the following to startup parameters:</p> |
| <div class="highlight"><pre tabindex="0" style="color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>-agentlib:native-image-agent=config-output-dir=/tmp/config/,config-write-period-secs=300,config-write-initial-delay-secs=5 |
| </span></span></code></pre></div><p>Launch in conventional way, create folder &lsquo;META-INF.native-image&rsquo; under the resources folder and paste the generated files in the local directory into the folder.</p> |
| </li> |
| </ul> |
| <p><img src="https://dubbo.apache.org/imgs/blog/dubbo3.0-graalvm-support/resources.jpg" alt="img"></p> |
| <p>(Missing classes&rsquo; information may exist. These information need to be manually added according to the error message reported while compiling or running.)</p> |
| <p><strong>Finished the steps above, now you can compile your project.</strong></p></description></item></channel></rss> |