I tangled with Clojure agents recently and while agents rock, I had
some unpleasant operational experiences that led me to dig in a bit
deeper. Due to the length, I dropped this in a blog entry that details
some issues and possible solutions:
http://tech.puredanger.com/2010/06/08/clojure-agent-thread-pools/
In very brief summary:
1) Agent thread pools should use named threads - patch for this here:
http://puredanger.com/techfiles/agent-name.diff. I'm happy to log a
ticket and the patch if this seems generally desirable.
2) Agent thread pools use non-daemon threads that can block jvm exit
(or require use of (shutdown-agents)). To me this feels broken. Some
possible solutions:
a) always use daemons and force users that want the jvm-keepalive
behavior to use a keepalive thread
b) always use daemon threads but allow new :sendPool
and :sendOffPool options on agents to pass a custom ExecutorService
that can do whatever you want
c) create new variants of send or use a global *foo* to choose
whether to use daemon or non-daemon
d) ???
3) (shutdown-agents) waits for existing actions to complete - suggests
to mean a complementary (kill-agents) that calls shutdownNow() on the
executor service (instead of shutdown()).
4) (shutdown-agents) is non-reversible - I dislike having magic
functions that irreversibly break parts of the Clojure runtime so
would like removing the need for this (see #2) or making it reversible
(although the concurrency issues are tricky and maybe not worth
doing).
Thanks for your consideration.
Alex Miller