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

Vishvajit Singh vishvajitsingh at gmail.com
Wed Apr 15 14:26:26 UTC 2009


Ouch.. 89 threads?

I was confused about agents, apparently.. it seems that:

send -> runs on the thread pool
send-off -> creates a new thread

Mea culpa :)

Vish

On Wed, Apr 15, 2009 at 3:15 AM,  <doug at hcsw.org> wrote:
> 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
>
> _______________________________________________
> toronto-lisp mailing list
> toronto-lisp at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/toronto-lisp
>
>




More information about the toronto-lisp mailing list