graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
naomarik 2020-06-12T14:42:57.331700Z

I just spent the last 30 years of my day trying to figure out why my app won't compile properly when using a reitit ring handler and updating clojure to 1.10.2-alpha1 fixed it.

borkdude 2020-06-12T14:58:17.332500Z

congrats. seems 1.10.2-alpha1 has solved a major blocking issue for us GraalVM native-image tinkerers

lukasz 2020-06-12T14:59:51.333700Z

Might be a long-shot, since it's an aleph specific question -but it does relate to graalvm and native-image. Has anybody run into a similar problem before? https://clojurians.slack.com/archives/C0G922PCH/p1591971729018900

borkdude 2020-06-12T15:01:26.334100Z

@lukaszkorecki You should probably add reflection config for that class

lukasz 2020-06-12T15:02:23.334700Z

as in this list? https://github.com/lukaszkorecki/graleph/blob/master/script/compile#L9 - admittedly I just dove head first without doing much research on how to make stuff work in Graal :-)

lukasz 2020-06-12T15:02:58.335400Z

ohhh

lukasz 2020-06-12T15:03:28.336Z

Gotcha, thanks @borkdude - will keep Trying Things Until They Work ™️

borkdude 2020-06-12T15:03:49.336500Z

Preferably you should solve a reflection issue using (set! *warn-on-reflection* true) in the library itself

borkdude 2020-06-12T15:04:15.337Z

but sometimes classes aren't simply used in all possible ways during image generation, in that case a reflection config helps

lukasz 2020-06-12T15:04:36.337500Z

Right, that was my next step to see where the reflective calls are

borkdude 2020-06-12T15:05:04.338Z

is this related to your statsd setup btw? you were hinting at a blog, wonder if that will still happen or if you have moved on to other setups 🙂

lukasz 2020-06-12T15:05:42.338800Z

The blog post is coming along, babashka will get a huge shout out, it's just very meaty and technical so it's taking a bit of time

lukasz 2020-06-12T15:05:59.339300Z

This is the other end of the metrics pipeline - atm we're using CollectD as the statsd server

lukasz 2020-06-12T15:06:11.339700Z

and that doesn't support tagged metrics, just plain old statsd protocol

borkdude 2020-06-12T15:06:24.340200Z

> This is the other end of the metrics pipeline I figured yes, so now you're making your own server.

lukasz 2020-06-12T15:07:20.340600Z

Yes, as an experiment for now

lukasz 2020-06-12T15:07:37.341300Z

but if it works, It might be possible to have a datadog-like setup on the cheap

lukasz 2020-06-12T15:07:53.341700Z

(DataDog is the only hosted metrics thing that supports tagged statsd metrics, as far as I know)

borkdude 2020-06-12T15:08:24.342400Z

why should the server run as a native binary, cheaper memory usage?

lukasz 2020-06-12T15:10:34.344700Z

Yeah, our monitoring node is composed of several daemons - Collectd, FluentD and carbon-relay (C, Ruby and Golang respectively). I could for now just run the JVM version of course. But if the project works as expected (statsd server with tagged metrics support, writing to graphite) - could be useful to open source it and make folks life easier in terms of distribution (single binary) and footprint

lukasz 2020-06-12T15:10:54.345100Z

You're right though: for our own purpose we could just run the jvm version

lukasz 2020-06-12T15:11:03.345300Z

for now

lukasz 2020-06-12T15:12:36.347400Z

Anyway, I'll check the reflection stuff and see how it goes. This also helps me to evaluate if we can migrate some of our own services to run via native-image and reduce the cost even more

borkdude 2020-06-12T15:13:23.348700Z

Exciting. Considering that UDP is so easy, the server can also be POC-ed in babashka itself probably. There are some from the ground up examples of how to do a multi-threaded webserver in bb. FWIW.

lukasz 2020-06-12T15:14:09.349700Z

Definitely. It's just that I'm more familiar with Aleph - our own Statsd client's test harness uses Aleph as a stand-in statsd server

borkdude 2020-06-12T15:14:14.349900Z

Baking a custom native image will probably be more performant though

borkdude 2020-06-12T15:15:11.350600Z

ok cool. there's an overview here of working and not-working projects: https://github.com/BrunoBonacci/graalvm-clojure, also FWIW

lukasz 2020-06-12T15:16:07.351500Z

That repo is great - it was a good jump off point, especially that it has aleph's http server confirmed to be working

valerauko 2020-06-12T15:17:42.352400Z

i tried adding the class to "initialize at run time" list but it still got initialized at build time resulting in an error

valerauko 2020-06-12T15:17:56.352800Z

there are no reflection warnings seen by lein check either

borkdude 2020-06-12T15:18:40.353400Z

@vale sometimes there's reflection happening in the Java implementation of something. this is very common with JDBC drivers

borkdude 2020-06-12T15:18:52.353600Z

in that case a reflection config helps

lukasz 2020-06-12T15:21:47.354400Z

I'll set some time aside later today and report back

valerauko 2020-06-12T15:28:42.355700Z

@lukaszkorecki i think i got it to run without error, should i put up a pr?

lukasz 2020-06-12T15:29:04.356Z

@vale 🙌 yes please!

👍 1
lukasz 2020-06-12T15:45:44.356900Z

@borkdude reflection config did fix the issue https://github.com/lukaszkorecki/graleph/pull/1/files

1
lukasz 2020-06-12T15:45:51.357200Z

thank you @vale

naomarik 2020-06-12T15:45:59.357500Z

hehe i'm also planning on using graalvm for a cheap and quick monitoring tool

naomarik 2020-06-12T15:46:03.357700Z

for tufte mainly

borkdude 2020-06-12T15:46:45.358Z

tufte is a profiling lib - what does it have to do with monitoring?

naomarik 2020-06-12T15:47:04.358500Z

to be able to see the stats in real time while production app is running

borkdude 2020-06-12T15:47:14.358800Z

right

lukasz 2020-06-12T15:47:39.359300Z

Where does the native-image part come in?

naomarik 2020-06-12T15:47:58.359800Z

mainly for fun, i'm outdated when it comes to all the latest build tools and tech

naomarik 2020-06-12T15:49:42.360800Z

also wanted something light/small to just sit on my app server and read from file/io to parse the logs and kill it whenever i want

borkdude 2020-06-12T15:51:39.361100Z

is your log format json, edn or something alike?

naomarik 2020-06-12T15:52:41.362100Z

was talking to peter yesterday about it, i was thinking of serializing using nippy to file/io every few seconds and reading from that

naomarik 2020-06-12T15:54:10.363600Z

just want something super quick and dirty that will make it really easy understand how long my routes are taking and see the performance impact switching to reitit on my main project

borkdude 2020-06-12T15:55:28.364900Z

if you want to have a quick and dirty scripting solution, you could also look at babashka, it's a native binary built with GraalVM, but it can execute clojure expressions. it doesn't support nippy yet though, although that has come up a few times. maybe I should add support for it... hmmmm

borkdude 2020-06-12T15:55:51.365300Z

what other binary formats are there, cbor?

naomarik 2020-06-12T15:56:11.365800Z

i don't know how to make a nice CLI display though, throwing a small dashboard together with reagent and chartjs would take me no time at all

naomarik 2020-06-12T15:56:26.366300Z

otherwise i would use bb

borkdude 2020-06-12T15:57:16.366900Z

hmm, there are libs to make TUIs in Clojure as well. might be cool to try that out with GraalVM

borkdude 2020-06-12T15:58:25.367400Z

there was this one: https://multimud.github.io/clojure-lanterna/

lukasz 2020-06-12T15:58:25.367500Z

Based on my experience BB is a great place to start, before rolling your own tool

lukasz 2020-06-12T15:58:29.367700Z

its crazy powerful

naomarik 2020-06-12T15:58:36.367900Z

any libs you'd recommend?

naomarik 2020-06-12T15:58:59.368200Z

ah... will check that out

borkdude 2020-06-12T16:01:04.368800Z

oh so you want to build a web-app compiled with graalvm

naomarik 2020-06-12T16:01:21.369100Z

a small one yeah 😉

borkdude 2020-06-12T16:02:52.370200Z

I do have one web-app example in bb: https://github.com/borkdude/babashka/blob/master/examples/notes.clj It's built from the ground up because bb doesn't have a built-in webserver (yet), so even the HTTP responses are parsed manually. But it works and starts fast, lol.

borkdude 2020-06-12T16:03:36.370900Z

Rolling a custom GraalVM binary will likely be more performant and less gnarly to write.

borkdude 2020-06-12T16:03:44.371100Z

Good luck.

lukasz 2020-06-12T16:11:49.371800Z

btw aleph's http server compiles with graalvm native-image

naomarik 2020-06-12T16:30:46.372600Z

what's the most performant http server these days? immutant?

borkdude 2020-06-12T17:43:26.373Z

confirming that nippy also works with graalvm:

$ ./bb "(require '[taoensso.nippy :as n]) (n/thaw (n/freeze [1 2 3]))"
[1 2 3]