Fork me on GitHub
#graalvm
<
2020-06-12
>
naomarik14:06:57

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.

borkdude14:06:17

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

lukasz14:06:51

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

borkdude15:06:26

@lukaszkorecki You should probably add reflection config for that class

lukasz15:06:23

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 :-)

lukasz15:06:28

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

borkdude15:06:49

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

borkdude15:06:15

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

lukasz15:06:36

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

borkdude15:06:04

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 🙂

lukasz15:06:42

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

lukasz15:06:59

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

lukasz15:06:11

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

borkdude15:06:24

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

lukasz15:06:20

Yes, as an experiment for now

lukasz15:06:37

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

lukasz15:06:53

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

borkdude15:06:24

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

lukasz15:06:34

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

lukasz15:06:54

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

lukasz15:06:36

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

borkdude15:06:23

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.

lukasz15:06:09

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

borkdude15:06:14

Baking a custom native image will probably be more performant though

borkdude15:06:11

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

lukasz15:06:07

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

valerauko15:06:42

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

valerauko15:06:56

there are no reflection warnings seen by lein check either

borkdude15:06:40

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

borkdude15:06:52

in that case a reflection config helps

lukasz15:06:47

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

valerauko15:06:42

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

lukasz15:06:04

@vale 🙌 yes please!

naomarik15:06:59

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

naomarik15:06:03

for tufte mainly

borkdude15:06:45

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

naomarik15:06:04

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

lukasz15:06:39

Where does the native-image part come in?

naomarik15:06:58

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

naomarik15:06:42

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

borkdude15:06:39

is your log format json, edn or something alike?

naomarik15:06:41

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

naomarik15:06:10

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

borkdude15:06:28

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

borkdude15:06:51

what other binary formats are there, cbor?

naomarik15:06:11

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

naomarik15:06:26

otherwise i would use bb

borkdude15:06:16

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

lukasz15:06:25

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

lukasz15:06:29

its crazy powerful

naomarik15:06:36

any libs you'd recommend?

naomarik15:06:59

ah... will check that out

borkdude16:06:04

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

naomarik16:06:21

a small one yeah 😉

borkdude16:06:52

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.

borkdude16:06:36

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

lukasz16:06:49

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

naomarik16:06:46

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

borkdude17:06:26

confirming that nippy also works with graalvm:

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