#clojure logs

2016-12-09

00:31georges_If I'm using clojurescript and this re-frame template https://github.com/Day8/re-frame-template where is the best place to put api calls?
02:16jonathanjISTR something about how (flatten) is the worst thing ever?
02:16dysfunjonathanj: it's not great on efficiency7
02:17jonathanjwhat's a better way to flatten?
02:17opqdonutalso, it can backfire
02:17opqdonutif some of the "elements" are actually sequences
02:17jonathanj(mapcat identity) is probably good enough?
02:17dysfunprobably
02:17luma~flatten
02:17clojurebotflatten is rarely the right answer. Suppose you need to use a list as your "base type", for example. Usually you only want to flatten a single level, and in that case you're better off with concat. Or, better still, use mapcat to produce a sequence that's shaped right to begin with.
02:19jonathanjmmm, is there something like clojure.string/split but for sequences?
02:19dysfunyes
02:19dysfunsplit-at, split-with
02:20jonathanjoh wonderful, thanks
02:21bostonaholic,(apropos "split")
02:21clojurebot(clojure.core/split-at clojure.core/split-with clojure.string/split clojure.string/split-lines)
02:23jonathanjbostonaholic: i always forget about that
02:23bostonaholicit is very handy
02:26deadghosthmm I'm not sure how the jvm works
02:26deadghostmemory usage seems steady whether I spin up 1 site or 40 sites
02:30dysfundeadghost: that's obviously a complex topic, but suffice to say the default settings don't change just because you load more code into them
02:36deadghostdysfun, at this point I'm just seeing what will crash the thing
02:36dysfunOutOfMemoryError will probably be the first one
02:36deadghostbut it seems to be performing much better than I expected
02:36dysfuncause some memory churn so it spends more time GCing than it's supposed to
02:37dysfunor just load a big bit of data into it (like a gig)
02:37deadghostmemory usage seems to be fixed until I access spun up sites
02:37dysfundeployed how?
02:37deadghostthen it increases very slightly
02:38deadghostlein run trampoline + immutant undertow
02:38dysfunoh
02:39dysfuni haven't actually used undertow
02:39dysfuni have no need for servlet support, so aleph is good for me
02:40deadghostdysfun, immutant was mostly just the first production usable thing I nabbed that just worked
02:40dysfuni think generally the community is heading away from servlets
02:41deadghostI haven't shopped around and don't have much knowledge in this area
02:41dysfunokay, well you have two primary methods of deployment
02:41dysfunin an appserver like tomcat or embedding a webserver in your uberjar
02:42dysfunboth clojure and scala tend towards the latter these days
02:42deadghosthmm
02:42deadghostwell
02:42dysfunif you just want a webserver, jetty, aleph and http-kit are all options
02:42deadghostI'm not deploying this to an app server
02:43dysfunyes, i got that
02:43deadghostI also don't think I'm doing anything uberjar related
02:43dysfunyou're not going to deploy lein in production though are you?
02:44jonathanjif i just wrote a reducer that amounted to (reduce (fn [x _] if (... (reduced ...) ...) (range)) what did i just write?
02:44jonathanjignoring my broken parens, since editing code in my irc client is awful
02:44deadghostdysfun, is doing that a problem?
02:44dysfundeploying lein in prod?
02:44dysfunwell it means you have two jvms instead of one for a start
02:45deadghostdoesn't trampoline take care of that?
02:45dysfunyes, trampoline launches a second jvm
02:45dysfuni wouldn't run anything important in lein in production
02:46dysfunlein is a build tool. when you deploy for real, you probably want an uberjar
02:46deadghosthmm ok
02:47dysfunthen in prod you just run java -jar foo-standalone.jar
02:47dysfunprobably through some service manager
02:49dysfundon't worry too much about memory consumption until you're ready to optimise
02:49dysfunthat's when you start having to think about GC etc.
02:50deadghostI was mostly making sure my server can handle a handful of site deployments
02:50dysfunah ok
02:50deadghostsince just deploying my app uses 700M
02:50deadghostand I'd cry if each additional site used near that much
02:50deadghostluckily consumption is very very steady
02:51dysfunessentially the jvm is designed to fit in whatever memory size you give it
02:51dysfungive it more, it does old GCs less often (but they take longer)
02:52dysfuni'm replacing a client's clojure site with cljs/nodejs soon because it's rarely used and the memory would be nice to have back
02:53deadghostany guidelines on much memory to give?
02:53deadghost*how
02:53deadghostI mean if you go too low it'd crash or something right?
02:53dysfunwell, this is where it gets tricky
02:54dysfunmake an educated guess, turn on relevant logging (e.g. GC logs) on the jvm and then start paying attention to the data
02:57dysfunhttps://www.jclarity.com/2016/02/02/how-to-create-useful-gc-and-safepoint-logs/