Skip to content

clojure.core/send-off

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 2 Runnable: 1
([a f & args])

Dispatch a potentially blocking action to an agent. Returns the agent immediately. Subsequently, in a separate thread, the state of the agent will be set to the value of:

(apply action-fn state-of-agent args)

Examples

by gstamp on . May have evaluation errors.
by kwladyka on

Note by Benissimo

The example uses "send", this is supposed to be an example for "send-off".

Note by fordsfords

"send" and "send-off" are identical in syntax and semantics. The only difference is the thread pool used to dispatch the agent. "send" uses a fixed-sized thread pool initialized at startup to contain a few more threads than the number of cores on the host computer. Since "send"s thread pool is fixed size, using it to dispatch blocking code can result in all the pool's threads being blocked, and other "send"s queued waiting for a thread to finish its work. This can produce artificially low performance, and in rare conditions, can deadlock (if a queued thread is needed to unblock the blocked pool threads).

"send-off" uses a separate thread pool which can grow as-needed. I.e. a "send-off" request will never be queued waiting for a thread; if the existing pool is empty, a new thread is created. However, if many long-running CPU-bound (not blocking) requests are being submitted, "send-off" can be counter-productive; having more CPU-bound threads than cores results in unnecessary scheduling overhead as the threads are timeshared across the cores. "send"s limited thread pool produces higher throughput for CPU-bound requests.

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.