core.async threadpool size

929 views
Skip to first unread message

icamts

unread,
Mar 27, 2014, 10:55:42 AM3/27/14
to clo...@googlegroups.com
Hi all,
quite a funny question. Thread pool size in core.async is twice the number of processors plus 42.


42? The question is:

1) should it be 4 or 2?
2) 42 is the response to life, universe and everything
3) for some technical reason 42 is also a good minimum number for a thread pool

Luca

Ben Mabey

unread,
Mar 27, 2014, 11:01:16 AM3/27/14
to clo...@googlegroups.com
I asked Timothy Baldridge about this on IRC when the change was made that added 42 and this was the reply I got:

   we're trying to strike a balance there, we don't want people to do IO inside a go block, but if they have to we'd don't want it to totally stall out.

Here is the full conversation:

http://clojure-log.n01se.net/date/2013-08-29.html#15:45a

-Ben
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

icamts

unread,
Mar 27, 2014, 11:24:38 AM3/27/14
to clo...@googlegroups.com
Thank you Ben.

Can we speculate on a go-off macro? Like in agents send / send-off to have go-off blocks executed by a cached thread pool executor?

Luca

Ben Mabey

unread,
Mar 27, 2014, 11:43:51 AM3/27/14
to clo...@googlegroups.com
If you want or need to block in a go-block then you should use the `thread` macro instead of the `go` macro.  A thread macro block will be ran in a cached thread pool as you seem to be wanting:

https://github.com/clojure/core.async/blob/master/src/main/clojure/clojure/core/async.clj#L379

Just note that you will need to use the blocking CSP operator variants, e.g. <!! instead of <!, while inside of `thread`.

-Ben

icamts

unread,
Mar 27, 2014, 12:39:13 PM3/27/14
to clo...@googlegroups.com
Thank you again Ben, now it is more clear.

Luca
Reply all
Reply to author
Forward
0 new messages