On Jun 30, 2009, at 5:30 PM, Kai wrote:

From scheduling I know that there are CPU-bound and IO-bound
processes. Perhaps send-off tends to hold off on yielding for longer
durations since it expects frequent interrupts. If this is the case, I
think it would be useful to elaborate on that in the documentation of
send-off, even if that's something implemented mostly in Java.


-------------------------

send-off:
        - is the more general case
        - is somewhat slower on average
        - has a quiescent thread count of 0
        - has a transient thread count that can be arbitrarily high
        - accommodates actions that block.

send-off uses a cached thread pool. The pool grows as necessary to accommodate new high water marks of simultaneously pending actions. When an action completes, the thread that ran it is kept around for a time for possible reuse. If a thread remains idle for a significant amount of time, it's terminated and released. The current Java implementation of Clojure uses a cached thread pool as described here:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newCachedThreadPool%28%29

-------------------------

send:
        - is an optimization for non-blocking actions
        - is somewhat faster on average
        - has a fixed thread count whether it's being used or not
        - fails to operate properly if used with actions that block.

send uses a fixed cache pool whose size is related to the number of processors (cores) that the JVM sees on your machine. The threads are created when Clojure starts up and are not released. They take actions off of a shared queue. send never incurs the overhead of creating a thread. The promise is (roughly) that your action either executes (close to) immediately or waits on a queue because all of the available cores are busy anyway. Blocking one of the fixed pool's threads would be bad and works against fulfilling send's promise. The current Java implementation of Clojure uses a fixed thread pool as described here:

http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/Executors.html#newFixedThreadPool%28int%29

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to