This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-24
Channels
- # announcements (8)
- # aws (12)
- # babashka (84)
- # beginners (380)
- # calva (56)
- # clj-kondo (52)
- # cljdoc (4)
- # cljs-dev (327)
- # cljsrn (4)
- # clojure (154)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (21)
- # clojurescript (52)
- # conjure (133)
- # cursive (64)
- # datomic (33)
- # emacs (22)
- # fulcro (35)
- # graalvm (24)
- # graphql (1)
- # kaocha (1)
- # leiningen (1)
- # off-topic (24)
- # onyx (2)
- # pathom (10)
- # re-frame (3)
- # reagent (3)
- # reitit (3)
- # shadow-cljs (48)
- # spacemacs (12)
- # tools-deps (98)
- # xtdb (7)
Does anyone happen to know why I can't seem to (import '[clojure.lang.Agent])
and resolve clojure.lang.Agent/pooledExecutor
?
@rovanion Because that isn't mapped in babashka yet. Can you explain why you would need this?
So the reason why I want to do this is to implement future
but using a pooled executor instead of the standard cached executor. The normal cached executor will spawn 8000 threads if 8000 futures are created at the same time. The pooled executor gives me the ability to limit the number of threads spawned to not choke the kernel.
Now I used this technique once in normal Clojure when I built a filesystem benchmark, I wanted to benchmark the filesystem and not the kernels ability to juggle threads, but I can totally live with spawning a ton of threads for the application I'm writing now. So no need to map it in just for me.
@rovanion Could you write out the entire program? Because it would not only involve getting access to clojure.lang.Agent
but also interop with executors
But again, no need to do anything about it. I've realised that using the http://clojure.java.io API is probably the wrong API for my current program. I probably want to use java.nio.2
@borkdude I have another suggestion for an addition; would like to use clojure.data/diff
. I'm happy to create a PR, but not sure about what you would suggest for the naming
Why not the clojure.core one?
user=> (require '[clojure.data :as data])
nil
user=> (data/diff [1 2 3] [1 2 4])
[[nil nil 3] [nil nil 4] [1 2]]
How can we use -IO
in babashka script instead of command line? which public api functions are used for this?
b -IO '(filter #(< 1 (:foo %) 4) *input*)' < test.ednl
that would be something like
(ns foo
(:require [clojure.edn :as edn]))
(doseq [x (filter #(< 1 (:foo 4) 4) (edn/read *in*))]
(prn x))
@ahmed1hsn It was slightly more complicated:
(ns foo
(:require [clojure.edn :as edn]))
(defn read-edn []
(take-while #(not (identical? ::EOF %))
(repeatedly #(edn/read {:eof ::EOF} *in*))))
(doseq [x (filter #(< 1 (:foo %)) (read-edn))]
(prn x))
what if *in*
is file instead?
@ahmed1hsn *in*
is from clojure.core
:
user=> (doc *in*)
-------------------------
clojure.core/*in*
A .Reader object representing standard input for read operations.
Defaults to System/in, wrapped in a LineNumberingPushbackReader
Thanks for the above snippet. Is there a way to automatically determine if *in*
has anything on it without hanging the script? This probably isn't bb specific but just curious. I think it's good script etiquette to support args or stdin without unexpected hangs
@borkdude the example I provided, and you tweaked, seems to bug on print-table, is clojure.pprint/print-table not available in 0.0.88-2?
That clj-together board is exciting. Particularly protocols as I'm guessing that would unlock usage of more 3rd party libs in bb. If there's a way to vote on issues, let me know. Otherwise I can drop a comment in an issue
commenting on issues is the only way to "vote" right now, I don't know of any other way
@cldwalker I just discovered that you can sort issues at Github by thumbs up or thumbs down. So giving a thumbs up on an issue counts as voting
Just wanted to say 👏 since babashka's nREPL completion works with my new Conjure completion integration! https://asciinema.org/a/H7136YMD9J9bU7l6GZE1yVNAa so cool!
@lukaszkorecki This is documented at https://github.com/borkdude/babashka/blob/master/doc/dev.md. How is the UDP stuff doing?
Also if you'd like to add stuff, please make an issue with a description of why you would like to add it. I'd like to screen it first, since adding things to babashka is not free in terms of binary size. If it's useful for general purpose scripting, or compatibility with existing libraries, that's often a good reason to add something
@borkdude Thanks, I missed that doc somehow. As for UPD: it's been rock solid since latest fixes Each ECS task deploys a tiny container as a sidecar which scrapes ECS metadata endpoint and sends container metrics via statsd protocol to our graphite server. I'm doing a write up about it - and from the looks of things I can open source it too. https://share.getcloudapp.com/YEu1p5E9 (3 charts we get from that)
Gotcha - I guess I got a bit excited since I almost see Babashka as the low-footprint Clojure I always wanted ;-)
so it's less about scripting, and more about building low-resource usage services which still deliver 80/90% of Clojure experience
(in my ideal world, we just use native-image/graalvm for all our services but that's pretty challenging to pull off atm )
let's just see what it might add in terms of features and size. e.g. adding the postgres support was quite heavy (it added 3mb), but I think it will be very useful
I don't know how much is it relevant for the discussion here, but yesterday I tried something. I took hsqldb and just for sake of curiosity I tried to compiled it with native-image and to my big surprised an 8.6MB binary was spit-out with runnable server-binary (Darwin). It seems from the documentation that hsqldb support in-process connection. I wonder if it's a possible candidate for embedding and eventual alternative to (native) sqlite.
@ales.najmann If you would like to see hsqldb support in babashka, you can help by doing the research: create a graalvm cli that includes next.jdbc and hsqldb and make a POC like https://github.com/yogthos/graal-web-app-example/tree/postgres - it's basically because of that example that it was so easy to support postgres
a very minimal example would suffice, the main thing is to figure out the reflection config
@lukaszkorecki I now added a branch called executor
that can execute this program:
(import '(java.util.concurrent Executors))
(defn run [nthreads niters]
(let [a (atom 0)
pool (Executors/newFixedThreadPool nthreads)
tasks (map (fn [_]
(fn []
(dotimes [_ niters]
(swap! a inc))))
(range nthreads))]
(doseq [future (.invokeAll pool tasks)]
(.get future))
(.shutdown pool)
(prn @a)))
(run 5 10) ;;=> 50
Binaries over here: https://clojurians.slack.com/archives/CSDUA8S6B/p1587751416010300
Binary size seems to be ok, only like 380kb added or sonow we can rely on java.util.concurrent instead of clojure.core.async. Does it include everything in this ns?
java.util.concurrent
ah, package. No I have only added three classes to begin with to make this snippet work. See the executor
branch.
Thanks, still a great start 🎉
Whenever I run something in bb, I get: setrlimit to increase file descriptor limit failed, errno 22
macOS
can you try to start a bb repl by just running bb
and then:
$ pid=$(pgrep bb); lsof -p $pid
This will list all open files by the processmarten-sytemas-macbook:~ marten$ pid=$(pgrep bb); lsof -p $pid
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bb 89181 marten cwd DIR 1,4 480 5126343 /Users/marten/Desktop
bb 89181 marten txt REG 1,4 51327260 8658390464 /usr/local/bin/bb
bb 89181 marten txt REG 1,4 973824 8647962767 /usr/lib/dyld
bb 89181 marten 0u CHR 16,8 0t215324 6049 /dev/ttys008
bb 89181 marten 1u CHR 16,8 0t215324 6049 /dev/ttys008
bb 89181 marten 2u CHR 16,8 0t215324 6049 /dev/ttys008
bb 89181 marten 3r PSXSEM 0t0 /cSunMiscSignal-89181
Hmm, I do see this message in the source code on graalvm: https://github.com/oracle/graal/blob/53a5606875222a64c11d0bddf8eee6fb1d13df8c/substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/PosixNativeLibraryFeature.java#L91
I made a simple Github Action to run clojure.test
☺️
https://twitter.com/uochan/status/1253826555609878529