Giter Site home page Giter Site logo

Support Graal Native Image about zio-http HOT 16 OPEN

tusharmath avatar tusharmath commented on July 30, 2024 2
Support Graal Native Image

from zio-http.

Comments (16)

jamesward avatar jamesward commented on July 30, 2024 6

Here is a sample that has the required config: https://github.com/jamesward/hello-zio-http/tree/graalvm

from zio-http.

reibitto avatar reibitto commented on July 30, 2024 3

For Linux, the config @jamesward posted worked as is for me. When I tried to build a native image for macOS (without Docker or anything like that), I got the same errors @kitlangton was seeing.

I was able to get it working by adding the following to the config that's already there:

"--initialize-at-run-time=io.netty.util.AbstractReferenceCounted",
"--initialize-at-run-time=io.netty.channel.kqueue.KQueue",

and then you also have to remove --static on macOS, otherwise you'll get:

com.oracle.svm.core.util.UserError$UserException: DARWIN does not support building static executable images.

After that it worked. Startup is instantaneous 🙂

from zio-http.

jamesward avatar jamesward commented on July 30, 2024 3

@kitlangton You've made it through the Native Image initiation rites! You should see my scars.

from zio-http.

carlosedp avatar carlosedp commented on July 30, 2024 2

As a followup to this issue, according to scala/scala3#13985, the main LazyVal problem is fixed but its still not released (apparently will be on Scala 3.3) and then it will require that all libs are built with this new compiler.

Another option is using scala-cli package command which does the bytecode manipulation as mentioned in the issue (scala/scala3#13985 (comment)) automatically.

I found a couple more flags required to be initialized and added it to a sample repo at https://github.com/carlosedp/ziohttp. It has a script to package the application to a native-image.

For the curious, the bytecode manip code is at https://github.com/VirtusLab/scala-cli/tree/main/modules/scala3-graal/src/main/scala/scala/cli/graal

from zio-http.

jamesward avatar jamesward commented on July 30, 2024 1

I bumped stuff up to the latest:
jamesward/hello-zio-http@4d29152

Note the GraalVM configs in the build.sbt which are for Netty:
https://github.com/jamesward/hello-zio-http/blob/graalvm/build.sbt#L97-L108

Hopefully that helps.

from zio-http.

reibitto avatar reibitto commented on July 30, 2024 1

Oh wow, I also tested this on native Windows and it worked! Setting up the Windows environment for Graal native-image is a little tricky (refer to this), but I didn't have to make any changes to the hello-zio-http project itself. I was not expecting that 😅

Unsurprisingly it also works with WSL.

from zio-http.

reibitto avatar reibitto commented on July 30, 2024 1

Oh, that makes sense. You were using sbt-native-image, not sbt-native-packager, right? sbt-native-image doesn't support Docker.

from zio-http.

kitlangton avatar kitlangton commented on July 30, 2024

Unfortunately, that config isn't working for me in my project. Perhaps things changed with the versions. Or perhaps I'm doing it wrong. :'(

I can't seem to avoid:

 io.netty.util.AbstractReferenceCounted the class was requested to be initialized at run time (from the command line). io.netty.util.AbstractReferenceCounted has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.util.AbstractReferenceCounted
io.netty.channel.DefaultFileRegion the class was requested to be initialized at run time (subtype of io.netty.util.AbstractReferenceCounted). io.netty.channel.DefaultFileRegion has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of io.netty.channel.DefaultFileRegion

from zio-http.

jamesward avatar jamesward commented on July 30, 2024

Nice @reibitto!

from zio-http.

kitlangton avatar kitlangton commented on July 30, 2024

<3 <3 <3 Thank you all so much. I lost an embarrassing number of hours to this yesterday. Excited to try this out :)

from zio-http.

kitlangton avatar kitlangton commented on July 30, 2024

🤖 Native... Image... Ready

😭

from zio-http.

kitlangton avatar kitlangton commented on July 30, 2024

Never has it felt so good to be startled by those words.

from zio-http.

kitlangton avatar kitlangton commented on July 30, 2024

Oh, that makes sense. You were using sbt-native-image, not sbt-native-packager, right? sbt-native-image doesn't support Docker.

Yeah! Your guess was correct (in the zio-http discord) that I'm using it as a local dev server for this https://twitter.com/kitlangton/status/1396918103414427648. Main goal is instant start-up.

from zio-http.

ithinkicancode avatar ithinkicancode commented on July 30, 2024

Can anyone make native-image compile then run successfully when including quill-jdbc-zio? After I added quill-jdbc-zio (I was able to isolate the problem to just this lib in my project), I had to add a lot of more --initialize-at-run-time entries. Then even when it succeeded building the image, my app crashed upon launch with this error message:

java.lang.NoClassDefFoundError: Could not initialize class io.netty.buffer.ByteBufAllocator

@jamesward @reibitto If you can look into this, I'd greatly appropriated. I just wish GraalVM's dev experience is much better than trial'n'errors.
I apologize for asking here @tusharmath... it's not often to get James and Reibitto in the same thread, and I know both have good experience with Graal. Thanks in advance.

from zio-http.

reibitto avatar reibitto commented on July 30, 2024

@ithinkicancode That's weird because I don't think quill even uses netty. If it's complaining about netty, then the problem might be coming from zio-http. But you're saying it only happens when you add quill-jdbc-zio to the project?

I'm actually going to try using native-image in one of my projects which happens to also use quill, so I might learn something in that process. If I manage to do it successfully I can let you know. If I forget, then it's this project. I need a little time though because I have to finish swapping out akka-http for zio-http first.

from zio-http.

joprice avatar joprice commented on July 30, 2024

At least one of the async drivers uses netty: https://github.com/postgresql-async/postgresql-async

from zio-http.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.