#clojure log - Dec 09 2016

The Joy of Clojure
Main Clojure site
Google Group
IRC
List of all logged dates

0:31 georges_: 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?

2:16 jonathanj: ISTR something about how (flatten) is the worst thing ever?

2:16 dysfun: jonathanj: it's not great on efficiency7

2:17 jonathanj: what's a better way to flatten?

2:17 opqdonut: also, it can backfire

2:17 if some of the "elements" are actually sequences

2:17 jonathanj: (mapcat identity) is probably good enough?

2:17 dysfun: probably

2:17 luma: ~flatten

2:17 clojurebot: flatten 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.

2:19 jonathanj: mmm, is there something like clojure.string/split but for sequences?

2:19 dysfun: yes

2:19 split-at, split-with

2:20 jonathanj: oh wonderful, thanks

2:21 bostonaholic: ,(apropos "split")

2:21 clojurebot: (clojure.core/split-at clojure.core/split-with clojure.string/split clojure.string/split-lines)

2:23 jonathanj: bostonaholic: i always forget about that

2:23 bostonaholic: it is very handy

2:26 deadghost: hmm I'm not sure how the jvm works

2:26 memory usage seems steady whether I spin up 1 site or 40 sites

2:30 dysfun: deadghost: that's obviously a complex topic, but suffice to say the default settings don't change just because you load more code into them

2:36 deadghost: dysfun, at this point I'm just seeing what will crash the thing

2:36 dysfun: OutOfMemoryError will probably be the first one

2:36 deadghost: but it seems to be performing much better than I expected

2:36 dysfun: cause some memory churn so it spends more time GCing than it's supposed to

2:37 or just load a big bit of data into it (like a gig)

2:37 deadghost: memory usage seems to be fixed until I access spun up sites

2:37 dysfun: deployed how?

2:37 deadghost: then it increases very slightly

2:38 lein run trampoline + immutant undertow

2:38 dysfun: oh

2:39 i haven't actually used undertow

2:39 i have no need for servlet support, so aleph is good for me

2:40 deadghost: dysfun, immutant was mostly just the first production usable thing I nabbed that just worked

2:40 dysfun: i think generally the community is heading away from servlets

2:41 deadghost: I haven't shopped around and don't have much knowledge in this area

2:41 dysfun: okay, well you have two primary methods of deployment

2:41 in an appserver like tomcat or embedding a webserver in your uberjar

2:42 both clojure and scala tend towards the latter these days

2:42 deadghost: hmm

2:42 well

2:42 dysfun: if you just want a webserver, jetty, aleph and http-kit are all options

2:42 deadghost: I'm not deploying this to an app server

2:43 dysfun: yes, i got that

2:43 deadghost: I also don't think I'm doing anything uberjar related

2:43 dysfun: you're not going to deploy lein in production though are you?

2:44 jonathanj: if i just wrote a reducer that amounted to (reduce (fn [x _] if (... (reduced ...) ...) (range)) what did i just write?

2:44 ignoring my broken parens, since editing code in my irc client is awful

2:44 deadghost: dysfun, is doing that a problem?

2:44 dysfun: deploying lein in prod?

2:44 well it means you have two jvms instead of one for a start

2:45 deadghost: doesn't trampoline take care of that?

2:45 dysfun: yes, trampoline launches a second jvm

2:45 i wouldn't run anything important in lein in production

2:46 lein is a build tool. when you deploy for real, you probably want an uberjar

2:46 deadghost: hmm ok

2:47 dysfun: then in prod you just run java -jar foo-standalone.jar

2:47 probably through some service manager

2:49 don't worry too much about memory consumption until you're ready to optimise

2:49 that's when you start having to think about GC etc.

2:50 deadghost: I was mostly making sure my server can handle a handful of site deployments

2:50 dysfun: ah ok

2:50 deadghost: since just deploying my app uses 700M

2:50 and I'd cry if each additional site used near that much

2:50 luckily consumption is very very steady

2:51 dysfun: essentially the jvm is designed to fit in whatever memory size you give it

2:51 give it more, it does old GCs less often (but they take longer)

2:52 i'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

2:53 deadghost: any guidelines on much memory to give?

2:53 *how

2:53 I mean if you go too low it'd crash or something right?

2:53 dysfun: well, this is where it gets tricky

2:54 make an educated guess, turn on relevant logging (e.g. GC logs) on the jvm and then start paying attention to the data

2:57 https://www.jclarity.com/2016/02/02/how-to-create-useful-gc-and-safepoint-logs/

Logging service provided by n01se.net