Improvents on agent,user-custom thread pool.

71 views
Skip to first unread message

dennis

unread,
Jul 25, 2010, 6:47:24 AM7/25/10
to Clojure

Agent use two thread pools to execute actions,send use a fixed thread
pool (2+cpus threads),and send-off use a cached thread pool.These
pools are global in clojure system.

I think the Agent should allow users to customize the thread pool,
if no custom, then use the global thread pool.
Why do I need a custom thread pool?
First, the default thread pool is global, send use the thread pool
is a fixed size cpus +2, is likely to become the system bottleneck
sometime. Although you can use the send-off, use the cache thread
pool, but in a real world application, I can not use the cache thread
pool, which will introduce the risk of OutOfMemoryError, normally I
like to use a fixed-size thread pool.

Second, the actions which global thread pool execute are from a
variety of agents, the actions are not homogeneous, and can not
maximize the efficient use of the thread pool, we hope that you can
specify different agent to isolate a particular thread pool to
maximize the use of thread pool .

I think Agent could add two new functions:

(set-executor! agent (java.util.concurrent.Executors/
newFixedThreadPool 2))
(shutdown-agent agent)

set-executor! is to set the agent's custom thread pool,and shutdown-
agent to shutdown the agent's custom thread pool.



Alex Miller

unread,
Jul 25, 2010, 8:54:29 PM7/25/10
to Clojure
Hey Dennis,

I suggested some of the same ideas here (http://tech.puredanger.com/
2010/06/08/clojure-agent-thread-pools/) and Rich said that these
seemed like good suggestions post-1.2. I think allowing you to modify
the agent thread pools after construction seems possibly dangerous
from a concurrency point of view, but maybe that would be ok.

Alex

mnicky

unread,
Jun 7, 2012, 9:56:04 AM6/7/12
to clo...@googlegroups.com
I just came across this thread (and also [1]) when I was googling for a way to customize the Clojure agents. Were any of these 'post 1.2' suggestions reconsidered since then? (I see they haven't been implemented yet).

Marek.

Reply all
Reply to author
Forward
0 new messages