[toronto-lisp] April meeting minutes available on the website

doug at hcsw.org doug at hcsw.org
Wed Apr 15 07:15:02 UTC 2009


On Tue, Apr 14, 2009 at 10:38:44PM -0400 or thereabouts, Vishvajit Singh wrote:
>     Is that actually what's going on in the Ants simulation? Clojure
> agents are something I haven't yet studied. I actually think agents
> run on a thread pool which has a number of threads equal to the number
> of processors.

Let's find out. Before I ran anything:

doug at eclipse:~$ ps -C java -L
  PID   LWP TTY          TIME CMD
doug at eclipse:~$

So no java running. Let's fire up Clojure:

doug at eclipse:~/tp12/clojure$ ls ..
clojure  clojure_20090320.zip
doug at eclipse:~/tp12/clojure$ /home/doug/java/jre1.6.0_13/bin/java -jar clojure.jar
Clojure
user=>

Let's see how many threads:

doug at eclipse:~$ ps -C java -L
  PID   LWP TTY          TIME CMD
31212 31212 pts/12   00:00:00 java
31212 31213 pts/12   00:00:01 java
31212 31214 pts/12   00:00:00 java
31212 31215 pts/12   00:00:00 java
31212 31216 pts/12   00:00:00 java
31212 31217 pts/12   00:00:00 java
31212 31218 pts/12   00:00:00 java
31212 31219 pts/12   00:00:00 java
31212 31220 pts/12   00:00:00 java
doug at eclipse:~$ ps -C java -L|grep -v PID|wc -l
9

So 9 OS threads. Next I loaded the ants.clj file:

user=> (load-file "ants.clj")
nil

Window pops up. Blank except for blue square in middle. CPU
idle. Now we have 13 threads: 

doug at eclipse:~$ ps -C java -L|grep -v PID|wc -l
13

Next I pasted in the following to the clojure REPL (it's from
the bottom of the ants.clj file):

(def ants (setup))
(send-off animator animation)
(dorun (map #(send-off % behave) ants))
(send-off evaporator evaporation)

Simulation starts. CPU pegged at 100%.

doug at eclipse:~$ ps -C java -L|grep -v PID|wc -l
89

89 OS threads. Wow that is even more than I figured.

Oh and I get it now... The ants crawl around searching for
food and bring it back to the nest. ;)

If the objective is to simulate ant movement (as opposed to
testing/benchmarking a thread implementation) you will have
a more efficient and correct program if each ant is not
implemented as its own thread. See The System described
in my previous message for a solution.

>    So we might be criticising Clojure incorrectly here.

Actually I was never criticising Clojure (I don't know enough
about it to do that). I was only discussing the trade-offs
of different concurrency strategies.

Doug
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/toronto-lisp/attachments/20090415/cb5d5578/attachment.sig>


More information about the toronto-lisp mailing list