2016-12-09
| 00: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? |
| 02:16 | jonathanj | ISTR something about how (flatten) is the worst thing ever? |
| 02:16 | dysfun | jonathanj: it's not great on efficiency7 |
| 02:17 | jonathanj | what's a better way to flatten? |
| 02:17 | opqdonut | also, it can backfire |
| 02:17 | opqdonut | if some of the "elements" are actually sequences |
| 02:17 | jonathanj | (mapcat identity) is probably good enough? |
| 02:17 | dysfun | probably |
| 02:17 | luma | ~flatten |
| 02: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. |
| 02:19 | jonathanj | mmm, is there something like clojure.string/split but for sequences? |
| 02:19 | dysfun | yes |
| 02:19 | dysfun | split-at, split-with |
| 02:20 | jonathanj | oh wonderful, thanks |
| 02:21 | bostonaholic | ,(apropos "split") |
| 02:21 | clojurebot | (clojure.core/split-at clojure.core/split-with clojure.string/split clojure.string/split-lines) |
| 02:23 | jonathanj | bostonaholic: i always forget about that |
| 02:23 | bostonaholic | it is very handy |
| 02:26 | deadghost | hmm I'm not sure how the jvm works |
| 02:26 | deadghost | memory usage seems steady whether I spin up 1 site or 40 sites |
| 02: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 |
| 02:36 | deadghost | dysfun, at this point I'm just seeing what will crash the thing |
| 02:36 | dysfun | OutOfMemoryError will probably be the first one |
| 02:36 | deadghost | but it seems to be performing much better than I expected |
| 02:36 | dysfun | cause some memory churn so it spends more time GCing than it's supposed to |
| 02:37 | dysfun | or just load a big bit of data into it (like a gig) |
| 02:37 | deadghost | memory usage seems to be fixed until I access spun up sites |
| 02:37 | dysfun | deployed how? |
| 02:37 | deadghost | then it increases very slightly |
| 02:38 | deadghost | lein run trampoline + immutant undertow |
| 02:38 | dysfun | oh |
| 02:39 | dysfun | i haven't actually used undertow |
| 02:39 | dysfun | i have no need for servlet support, so aleph is good for me |
| 02:40 | deadghost | dysfun, immutant was mostly just the first production usable thing I nabbed that just worked |
| 02:40 | dysfun | i think generally the community is heading away from servlets |
| 02:41 | deadghost | I haven't shopped around and don't have much knowledge in this area |
| 02:41 | dysfun | okay, well you have two primary methods of deployment |
| 02:41 | dysfun | in an appserver like tomcat or embedding a webserver in your uberjar |
| 02:42 | dysfun | both clojure and scala tend towards the latter these days |
| 02:42 | deadghost | hmm |
| 02:42 | deadghost | well |
| 02:42 | dysfun | if you just want a webserver, jetty, aleph and http-kit are all options |
| 02:42 | deadghost | I'm not deploying this to an app server |
| 02:43 | dysfun | yes, i got that |
| 02:43 | deadghost | I also don't think I'm doing anything uberjar related |
| 02:43 | dysfun | you're not going to deploy lein in production though are you? |
| 02:44 | jonathanj | if i just wrote a reducer that amounted to (reduce (fn [x _] if (... (reduced ...) ...) (range)) what did i just write? |
| 02:44 | jonathanj | ignoring my broken parens, since editing code in my irc client is awful |
| 02:44 | deadghost | dysfun, is doing that a problem? |
| 02:44 | dysfun | deploying lein in prod? |
| 02:44 | dysfun | well it means you have two jvms instead of one for a start |
| 02:45 | deadghost | doesn't trampoline take care of that? |
| 02:45 | dysfun | yes, trampoline launches a second jvm |
| 02:45 | dysfun | i wouldn't run anything important in lein in production |
| 02:46 | dysfun | lein is a build tool. when you deploy for real, you probably want an uberjar |
| 02:46 | deadghost | hmm ok |
| 02:47 | dysfun | then in prod you just run java -jar foo-standalone.jar |
| 02:47 | dysfun | probably through some service manager |
| 02:49 | dysfun | don't worry too much about memory consumption until you're ready to optimise |
| 02:49 | dysfun | that's when you start having to think about GC etc. |
| 02:50 | deadghost | I was mostly making sure my server can handle a handful of site deployments |
| 02:50 | dysfun | ah ok |
| 02:50 | deadghost | since just deploying my app uses 700M |
| 02:50 | deadghost | and I'd cry if each additional site used near that much |
| 02:50 | deadghost | luckily consumption is very very steady |
| 02:51 | dysfun | essentially the jvm is designed to fit in whatever memory size you give it |
| 02:51 | dysfun | give it more, it does old GCs less often (but they take longer) |
| 02:52 | dysfun | 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 |
| 02:53 | deadghost | any guidelines on much memory to give? |
| 02:53 | deadghost | *how |
| 02:53 | deadghost | I mean if you go too low it'd crash or something right? |
| 02:53 | dysfun | well, this is where it gets tricky |
| 02:54 | dysfun | make an educated guess, turn on relevant logging (e.g. GC logs) on the jvm and then start paying attention to the data |
| 02:57 | dysfun | https://www.jclarity.com/2016/02/02/how-to-create-useful-gc-and-safepoint-logs/ |