This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-14
Channels
- # announcements (7)
- # babashka (51)
- # beginners (292)
- # calva (37)
- # chlorine-clover (40)
- # cider (5)
- # clj-kondo (83)
- # cljs-dev (26)
- # cljsrn (36)
- # clojure (172)
- # clojure-argentina (5)
- # clojure-austin (1)
- # clojure-australia (9)
- # clojure-europe (3)
- # clojure-france (7)
- # clojure-gamedev (3)
- # clojure-nl (3)
- # clojure-spec (4)
- # clojure-uk (34)
- # clojurescript (46)
- # community-development (1)
- # conjure (26)
- # core-async (28)
- # data-science (2)
- # datascript (2)
- # datomic (61)
- # devcards (3)
- # emacs (7)
- # events (2)
- # fulcro (65)
- # graalvm (57)
- # instaparse (2)
- # juxt (21)
- # luminus (6)
- # off-topic (21)
- # pathom (1)
- # pedestal (15)
- # reagent (1)
- # shadow-cljs (19)
- # spacemacs (3)
- # specter (1)
- # sql (14)
- # unrepl (4)
- # vscode (1)
- # xtdb (1)
- # yada (4)
If I understand correctly, we can compile Clojure code into LLVM bytecode with GraalVM right?
If this is the case, we could also take this code and convert into Webassmbly?
I dunno whether that's possible and if so, how straightforward it is to do. But, I'm pretty sure it won't be practical in terms of bundle size (assuming browser use) because we'd have to ship the runtime (stuff like GC). May I know the use case you have in mind?
I just want to write a simple numerical function to optimize some computation on the front end
It would be a rolling average function like m_n = m_{n-1} + x_n/n - x_{n-w-1}/n
I heard Rust has a good compile-to-wasm story. That might yield a much smaller output.
Thanks
I will try. I never coded in rust though haha
if you go for rust, i highly recommend checking out this chapter before diving in: https://www.oreilly.com/library/view/programming-rust/9781491927274/ch04.html
I just want to write (reductions + coll)
in rust, I hope it won’t translate into 100s of lines!
Probably not. Rust is pretty concise. BTW we can take this to #other-languages or #off-topic because it isn't relevant to #graalvm or Clojure.
Is it safe to assume that if my Clojure app uses only the JDK (and Clojure's std lib) it should be straight forward to compile it using native-image?
I'm not sure of all the edge cases, but it's way more likely that you'll be good than if you incurred a bunch of random dependencies
I thought that will be the case - all I have to do is to periodically fetch data from an HTTP endpoint, parse the json and send some of the data over to a statsd server - seems like all of these should be doable with just the JDK - JSON is probably the harder part, but I've noticed that babashka has cheshire as a dependency so It Should Work:tm:
@lukaszkorecki writing this as a simple babashka script should also work. equally fast startup, no compilation needed
https://github.com/borkdude/clj-http-lite and https://github.com/borkdude/babashka.curl are two http clients that work with graalvm
@borkdude can babashka do loops, as in (while true (do (something) (Thread/sleep 10))
- I haven't had the time to play with it yet
@lukaszkorecki I've included babashka.curl inside bb. curl can do amazing stuff, talk http over unix sockets for example. don't know about the udp stuff you're talking about
Oh, it would be a simple statsd client - something I wrote before many times (in Common Lisp, Chicken Scheme, C etc etc )
is that doable with a socket? babashka also includes http://java.net.Socket etc
Yeah, http://java.net.Socket should be enough
statsd itself has a clojure implementation based on it https://github.com/statsd/statsd/blob/master/examples/statsd.clj
@lukaszkorecki cool. and if you decide you want to run as a native image anyway, someone made a migration script from bb to native-image: https://github.com/MnRA/nativity 🙂
hmm, I don't think DatagramSocket etc is in bb right now: https://github.com/borkdude/babashka/blob/36c163a4449e43cc99be2ce5b32794d854d4ab68/src/babashka/impl/classes.clj#L56 but it's just a matter of adding it to that list.
@lukaszkorecki was fun listening to the podcast (the REPL) btw!
@lukaszkorecki Are you on Mac or Linux?
@lukaszkorecki With a few of those Datagram classes added, this now works:
$ ./bb -e '(load-file "/tmp/statsd.clj")' -e "(require '[statsd-client :as c]) (c/increment :foo)"
(where statds.clj
is the example you linked to earlier)This is a linux binary: https://6696-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.85-SNAPSHOT-linux-amd64.zip And this is a macos binary: https://6697-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.85-SNAPSHOT-macos-amd64.zip with these classes added. Let me know if this is useful to you. If yes, I'll keep 'em in for the next release 😃.
@lukaszkorecki If this is going to run on Linux alpine, let me know, then you'll need the static binary
target container size is not that important, it's more about the memory/cpu footprint of the tool itself
if it all works - I'm going to write about how we are monitoring our services in ECS with graphite and statsd
@lukaszkorecki Did an additional test with https://www.npmjs.com/package/statsd-logger
$ statsd-logger
Server listening on 0.0.0.0:8125
StatsD Metric: foo:1|c
$ ./bb -e '(load-file "/tmp/statsd.clj")' -e "(require '[statsd-client :as c]) (while true (c/increment :foo) (Thread/sleep 100))"
$ statsd-logger
Server listening on 0.0.0.0:8125
StatsD Metric: foo:1|c
StatsD Metric: foo:1|c
StatsD Metric: foo:1|c
...
@lukaszkorecki If I put (System/gc)
at the end of the iteration, it runs pretty consistently with 11 MB of memory (reported in Activity Monitor on a Macbook Pro)
Nice! Let me wire polling the HTTP server and reporting metrics via UDP to see how it behaves