[Shootout-list] process creation & message passing

Isaac Gouy igouy2@yahoo.com
Thu, 14 Oct 2004 23:30:24 -0700 (PDT)


The new process creation & message passing tests will not provide a
measurement of the time to create a thread, or the time to pass
messages between threads, for most of the languages in the Shootout.

Most of the languages will be excluded. They'll be excluded because
they use kernel threads for concurrency, and there's not enough memory
on the test machine.

imo Good tests would *include* most of the languages.
Here are 2 tests that should provide rankings for languages that
provide concurrency; 2 tests that use the same basic structure.

chainmsg 
- create 3000 *linked* processes/threads/... 
- send message 0 from one end of the chain
- each process/thread/... receives an integer x, stores x, 
and passes x+1 to the next process/thread/... in the chain
: print the final message (which should be 3000)
(2 parameters: how many messages are sent, how many times
'create'/'send-messages' is repeated)

chain 
- create 3000 *linked* processes/threads/...
: print the number of processes 3000 (show program didn't silently
fail)
(1 parameter: how many times 'create' is repeated)

These tests would show how slow Java thread creation is, how slow
Python thread communication is... 


Timing within a Java 'chain' program, gave
java chain 1   -   4.015s
java chain 2   -   7.844s
java chain 3   -  11.625s
java chain 4   -  15.422s
java chain 10  -  38.547s
java chain 100 - 387.25s

In that final test a total of 300,000 threads were created.
Trying to create ~7000 threads causes OutOfMemoryError on this machine.



public class chain {

   public static void main(String args[]) {
      int n = Integer.parseInt(args[0]);
      int length = 3000;

      while (n-- > 0) {
         Thread chain = null;
         Thread link = null;

         synchronized(Link.forge){
            for (int i=1; i<=length; i++){
               link = new Link(chain);             
               link.start();
               chain = link;
            }
         }
      }
      System.out.println(length);
   }
}

class Link extends Thread {
   public static Integer forge = new Integer(0);
   private Thread next;
   
   Link(Thread t){
      next = t;
   }

   public void run() {
      synchronized(forge){}    
   }
}  




		
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com