[squeak-dev] RemoteTask for poor man's multiprocessing with Squeak

David T. Lewis lewis at mail.msen.com
Tue Jan 26 04:30:40 UTC 2010


I was driving home from Peoria today, listening to podcasts on the car radio,
and here was this Industry Misinterpretations podcast about taking advantage
of multi-core CPUs by spawning worker images:
          http://www.cincomsmalltalk.com/audio/2009/industry_misinterpretations163.mp3

I realized that this was probably the same thing I was doing with Squeak
a while back using ReferenceStreams and CommandShell/OSProcess, but I don't
have a multi-core CPU to test it, so I don't know if it actually produces
any performance benefits.

If someone has a multi-core PC running some flavor of Unix/Linux/OS X,
I'd be interested to know if this provides any actual performance benefit.
The multi-processing version of the test is slower on my single CPU system
(as expected), but would presumably run faster if executed on a quad-core CPU.

How to test it:
1) Load OSProcess and CommandShell from SqueakSource (latest versions, updated today)
2) Try this:

  "Make a large interval of large integers, broken into 3 chunks with elements
  to be tested for #isPrime."
  oc := OrderedCollection new. "collection of three intervals of large integers"
  taskCount := 3.
  start := 100000000000000000000000000000. "a big number"
  chunkSize := 2000. "integers per interval, to be tested in remote task"
  end := chunkSize * (taskCount - 1) + start.
  (start to: end by: chunkSize) do: [:e |
  	oc add: (e to: e + chunkSize - 1)].
  
  "Run tests in local image, processing everything serially in this Squeak image.
  For each interval, find all the prime elements and answer them as strings.
  Note: Passing large integers through a ReferenceStream seems to be buggy,
  hence the conversion to strings."
  Time millisecondsToRun: [
  	oc collect: [:e |
  		e select: [:f | f isPrime] thenCollect: [:s | s asString]]] "==> 55499"
  
  "Split the work into tasks and assign the tasks to RemoteTask worker images.
  For each interval, find all the prime elements and answer them as strings.
  Processing is parallel, with each interval evaluated in a separate RemoteTask,
  and the results collected in this image after all RemoteTask processing is
  complete."
  Time millisecondsToRun: [
  	tasks := oc collect: [:e | RemoteTask start: [e select: [:f | f isPrime] thenCollect: [:s | s asString]]].
  	tasks collect: [:t | t result]] "==> 79280"

The hope would be that the second test using RemoteTask would run faster
than the first on a multi-core CPU, by virtue of using three worker images
to run the three tasks more or less in parallel.

Dave




More information about the Squeak-dev mailing list