This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-09
Channels
- # aleph (4)
- # arachne (3)
- # beginners (41)
- # boot (300)
- # cider (17)
- # cljs-dev (37)
- # cljsjs (4)
- # cljsrn (5)
- # clojure (249)
- # clojure-boston (3)
- # clojure-czech (4)
- # clojure-dev (14)
- # clojure-greece (183)
- # clojure-nl (2)
- # clojure-russia (11)
- # clojure-spec (135)
- # clojure-uk (37)
- # clojurescript (56)
- # community-development (8)
- # cursive (22)
- # data-science (4)
- # datomic (150)
- # devcards (6)
- # emacs (5)
- # euroclojure (8)
- # funcool (18)
- # hoplon (29)
- # immutant (1)
- # jobs (1)
- # lambdaisland (3)
- # lein-figwheel (7)
- # leiningen (18)
- # mount (1)
- # om (81)
- # onyx (95)
- # planck (50)
- # proton (6)
- # re-frame (62)
- # reagent (2)
- # ring (1)
- # robots (1)
- # spacemacs (2)
- # specter (88)
- # test-check (32)
- # untangled (23)
- # yada (1)
I'm finding that when I issue an 'sh' with a long-running CPU-bound command (5-10 seconds on average), planck itself also uses 100% CPU. That doesn't seem right to me
[I have 8 cores and end up using 200/800% during each of these-- 100% for each of planck and the command executed]
@johanatan: Does the command itself emit a lot to stdout?
I agree. That does appear to be odd. There are a few bugs surrounding sh
, this one being the most troubling: https://github.com/mfikes/planck/issues/88
@mfikes: I filed the issue and am now thinking that I'd like to take a stab at solving it. Do you have any tips/advice for how to approach this one?
@johanatan: Here is where external shell tasks are executed: https://github.com/mfikes/planck/blob/master/planck/PLKSh.m#L117
@johanatan: There is a Wiki page here describing stuff surrounding building Planck: https://github.com/mfikes/planck/wiki/Development
If there is a better way, perhaps some other mechanism could be used, one that also doesn’t hang like NSTask appears to do
I think it would be better to return immediately and allow the terminationHandler to 'wake' us back up: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/#//apple_ref/occ/instp/NSTask/terminationHandler
I'm super-confused by these lines: https://github.com/mfikes/planck/blob/0dee6638aa7487f251042dce5418324ccd738b4a/planck/PLKClojureScriptEngine.m#L200-L202
Do you have any example in the code where an async method call from JS -> Obj-C -> JS is performed?
If planck.shell/sh
gains async, we’d have to figure out a way to support the older sync interface, and also, play the same trick to keep Planck processing alive when there are outstanding async tasks
So, just replace the call to 'waitUntilExit' (which stupidly polls killing the CPU) with use of dispatch_semaphore
.
[but yes going forward when the time is right for async, i think we'd want to follow the pattern of the timers on the js -> objc bridge side of things and use core.async/andare on the JS side]
The real problem (apart from hogging some CPU) is the inexplicable hanging that occurs if you try to use Planck to, say, run something that does a maven build or lein build, which makes it hard to use Planck to automate dev stuff
These changes didn't help the CPU usage:
Jonathans-MacBook-Pro:planck jonathan$ git diff
diff --git a/planck/PLKSh.m b/planck/PLKSh.m
index 4e4b8b1..9387b26 100644
--- a/planck/PLKSh.m
+++ b/planck/PLKSh.m
@@ -111,11 +111,17 @@ NSDictionary* cljs_shell(NSArray *args, id arg_in, NSString *encoding_in, NSStri
[errData appendData:data];
[errLock unlock];
}];
-
+
+ NSLog(@"doing semaphore thingie\n");
+ dispatch_semaphore_t sema = dispatch_semaphore_create(0);
+ aTask.terminationHandler = ^(NSTask *task) {
+ dispatch_semaphore_signal(sema); };
+
// We'll block during execution
@try {
[aTask launch];
- [aTask waitUntilExit];
+ dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
+ NSLog(@"done doing semaphore thingie\n");
}
@catch (NSException *exception) {
return @{@"exit": @(-1),
[According to 'Barry' on this page: http://stackoverflow.com/questions/4326350/how-do-i-wait-for-an-asynchronously-dispatched-block-to-finish , quote: "Yep, this is ghetto polling that will murder the battery" lol