Fork me on GitHub
#clojure
<
2019-06-16
>
Drew Verlee17:06:15

i have a computational and memory heavy function that needs to be applied to a different sets of data (read file, run algorithm, collect results). In some cases the algorithm might take to long or use too much memory. My plan right now is too use core async because i assume it will let me isolate each pipeline to its own thread and because it will let me timeout any processes that are running too long (1 minute is probably enough to signify it will never complete). Does this sound reasonable? Is there a way to set limits on how much memory the thread can use up or monitor it? I assume it makes more sense to use the blocking variant via thread rather then a the go block parking version because these last longer, deal with file io, etc...

andy.fingerhut17:06:57

The JVM has the ability to set the max heap to use for the entire process, but I am not aware of any mechanisms for setting the max heap per thread.

👍 4
andy.fingerhut17:06:40

If the work done in a single thread is long enough that starting up a separate JVM for each one is reasonably small time overhead, you could do that for setting the max memory.

👍 4
carkh20:06:05

is there a testing framework that does clojure and clojurescript, is compatible with the tooling for clojure.test and allows for singling out a test to run very easily ?

vemv01:06:30

I use clojure.test + custom emacs functions (which in any case use vanilla techniques) for clj, I programatically call the deftest via its var metadata : (-> #'some-test meta :name .call). Using the :name enables support of a few other frameworks, which don't have a 1:1 mapping between the test-defining forms, and the invokable functions that they generate for cljs, I eval the following:

(concat  "(.reload js/location true) "
         "(cljs.test/run-block ["
         (cider-symbol-at-point)
         "])")
If interested you can grep this-deftest in https://github.com/zenmacs/.emacs.d/blob/master/lib/non-submodules/vemv.clojure-interaction.el but I don't expect ppl to understand/use my emacs 🙂

carkh16:06:49

i'll bookmark this and steal liberally from it

carkh20:06:34

or a test runner with an easy ui that does the singling out

seancorfield20:06:02

@carkh If I want to run a single test, I do it via the REPL with clojure.test/test-vars

seancorfield20:06:49

Most of the time I run tests via the REPL anyway...

seancorfield20:06:10

The test runners I've used can narrow to a single namespace but not a single test function I think. Some of them let you put metadata on tests and then filter on that metadata -- so that would let you run a single test I guess.

carkh20:06:17

mhh yes indeed

carkh20:06:00

the metadata trick isn't good for my case i think, tooling won't work with that

seancorfield20:06:27

What's you use case? Why do you want to run an individual test?

carkh20:06:54

i find that i'm always alternating between running all tests and running a single one

carkh20:06:10

and i like my little desktop notifications

carkh20:06:56

i'm usually not so hot on testing, but i think it very usefull for data structure and algorithmic work

seancorfield20:06:10

I am pretty big on testing. Of our 87,000 lines of Clojure, about 20k are tests.

seancorfield20:06:44

While I run full test suites from the command line and occasionally just one namespace, I mostly run tests from my editor via the REPL -- just a hot key to run all tests in the current namespace, or to run the single test under the cursor.

carkh20:06:41

clojurescript is complicating things in this regard

carkh20:06:10

but yes it looks like it works

seancorfield20:06:13

True, cljs complicates nearly everything 🙂

carkh20:06:50

thanks for the tip

carkh20:06:30

in javascript land there is this neat testing tool where you just change a letter in your test, and now it will only run this one

carkh20:06:59

that would be great with clojurescript's figwhell/shadow-cljs auto-reloading

aisamu01:06:08

shadow-cljs has the :ns-regexp build option that let's you narrow down the top-level built ns's). I usually paste the target ns there while working - shadow picks that up without restarting.

carkh16:06:35

that's good to narrow tests by namespace

carkh20:06:22

the eheart of the problem is that when debugging i'm littering the code with logging statements

carkh20:06:51

then i end up with a diarrhea of log entries from all tests

carkh20:06:08

which isn't helpfull at all

carkh20:06:38

so the ideal workflow to me would be : mark the test (via ui or code), add a logging statement, save the file, test is run, check the result and move on with more logging without returning to the test namespace

john20:06:03

Is there a way to do a stateful post/prewalk, so that if I detect a particular token, I can do something specific with the next?

john20:06:01

I guess I could pull a last-token atom through the walk?

vemv00:06:42

yes I have used that technique a bunch of times this year 🙂