7 ms·
My world revolves around Common Lisp (with Python for deep learning), but Clojure is also an important language to me because of both professional use and I wro
by mark_l_watson 5y ago
My world revolves around Common Lisp (with Python for deep learning), but Clojure is also an important language to me because of both professional use and I wrote a Clojure AI book.
What is the Graalvm + Clojure situation? A quick web search shows some use cases. I find the idea of using high programmer-efficient Lisp languages and then building small and fast native applications to be compelling. That said, LispWorks, SBCL, and Allegro CL are all good for building standalone apps.
- zorr 5y agoIf you have a clojure project that builds to a single .jar file at hand, you can give it a quick shot using the native-image command from the GraalVM. If you're not using reflection-heavy libraries chances are it will just work and spit out a binary.
- mark_l_watson 5y agoWonderful, thanks.
- kaba0 5y agoIt can compile Clojure to native executables but do note that Graal’s AOT part doesn’t promise better performance, just faster startup time and reduced memory usage. Using JIT compilers for long running processes (either the usual OpenJDK’s hotspot or Graal’s JIT compiler) will very likely beat the AOT compiled version for long running processes.
- pjmlp 5y agoGraalVM AOT also accepts PGO.
- eklavya 5y agoCan you please share your experience with PGO? I would be interested in some rough performance ballpark numbers for JVM languages.
- pjmlp 5y agoI am just following its development, here is an article about it, https://medium.com/graalvm/improving-performance-of-graalvm-native-images-with-profile-guided-optimizations-9c431a834edb https://medium.com/graalvm/improving-performance-of-graalvm-...
- lkrubner 5y ago"Using JIT compilers for long running processes (either the usual OpenJDK’s hotspot or Graal’s JIT compiler) will very likely beat the AOT compiled version for long running processes." I didn't know this. Why is this?
- vips7L 5y agoThe JIT has runtime and profile guided data to determine what to do. It can observe behaviors about how the program is actually being used and better optimize or even remove code that isn’t going to execute.
- tombert 5y agoI haven't touched GraalVM in a couple years, but the big-ish project that I did with it in Clojure was mostly painless, except for the fact that I had to use type-hinting a lot more frequently, due to the reduced reflection capabilities of GraalVM. Other than that, it was actually very pleasant.
- Borkdude 5y agoExamples of Clojure projects that compile to native: - babashka (https://github.com/babashka/babashka https://github.com/babashka/babashka) - clj-kondo (https://github.com/clj-kondo/clj-kondo https://github.com/clj-kondo/clj-kondo) - jet (https://github.com/borkdude/jet https://github.com/borkdude/jet) SCI (https://github.com/babashka/sci https://github.com/babashka/sci) is a Clojure interpreter that allows you to evaluate Clojure code even inside of the final native binary and is used in all of the above projects. Feel free to bug me with questions in the graalvm channel on Clojurians Slack.
- christophilus 5y agoI want to slap a bunch of side projects on a small VPS. With Go, this is no problem. Scp the binary (which includes an embedded SQLite), configure it to run as a systemd service, add it to my reverse proxy rules. I’d love to use Clojure for this, but it doesn’t seem well suited to running in a small, shared environment. Or is it now that there’s AOT?
- lf-non 5y agoPerhaps fennel+openresty is a better fit for that kind of use case.
- melony 5y agoDepends on how much value you place on performance. For long running processes like web servers, the JVM still reigns supreme.
- stingraycharles 5y agoYou should be fine, but it depends on your definition of “small VPS”. Generally, assume that each process will need about 512MB of memory. You’ll definitely want to restrict the JVM by memory, either by explicit flags (-Xmx ) or by running them in a cgroup or container.
- lvh 5y agoPretty similar with Clojure, though because it's not the default mode of operation, more stuff will break. Still, we do this all the time and it's mostly fine. That said, seems like you should be able to do something pretty similar fairly easily with jars and the JVM (you may not want to run lots of JVMs in the method you're describing, since if you're calling these processes in a one-shot, CGI-style fashion, the JVMs startup time and memory requirements is going to be annoying.) GP also linked babashka which may be closer to your interests, as its an interpreter for small scripts like these, but also comes with a mechanism (pods) for loading dependencies (like SQLite).
- lowecg 5y agoI'm running Clojure code compiled with GraalVM native for AWS Lambda. Cold start times are low and performance is decent enough, even with CE edition. The whole process is reasonably painless through the use of Holy Lambda https://github.com/FieryCod/holy-lambda https://github.com/FieryCod/holy-lambda Not quite what you were asking for, but I wanted to chip in as another happy Clojure + GraalVM native user.