Largest Provider of Commercial Smalltalk
Cincom is one of the largest commercial providers of Smalltalk, with twice as many customers and partners as other commercial providers.

Tom Nies

Get Started

Cincom® ObjectStudio® – Hydra

In older ObjectStudio releases, you could start several operating-system-level threads. Since ObjectStudio 8.0, the VM uses “Green Threads” a.k.a. Smalltalk Processes. In general, Smalltalk Processes are faster to create and easier to use than operating-system threads, but there are times when it would be nice if you could spread the process/threads over several CPUs or CPU cores.

This is where Polycephaly comes into play. Polycephaly allows the user to spawn new copies of your ObjectStudio VM and image. Since Windows sees these new copies as separate programs, it can schedule them on any available CPU.

One use of Polycephaly could be to connect to different web services at the same time and read some data. We currently use Polycephaly to run our SUnit test suite.

The mechanism is to create a list of tests that need to be performed, create a pool of Virtual Machines to run them, distribute the tests to the different Virtual Machines as they are available and collect the results.

With Polycephaly, it is very easy to create a pool of Virtual Machines.

vmPool := Polycephaly.VirtualMachines new: 5.

This creates five new slave images that can run Smalltalk code for you. If you check with the TaskManager or ProcessExplorer, you should see the five new processes right away. The number of new Virtual Machines you create will depend on the number of available CPUs/cores on your hardware. You can create as many as you can use effectively, but you will most likely lose any speed benefit if you create more than the number of physical CPUs/cores you have available.

Now we have to coordinate the tests and the Virtual Machines. The tests are just strings, stored in a Shared Queue. This way, several Smalltalk processes can access the data without interfering with each other.

Since the calls to one of the Virtual Machines are synchronous, we create a new Smalltalk process in the main VM for each drone VM. To make sure all processes are done, we use a Semaphore for synchronization.

So the code to run all tests looks something like this:

runAllTests

| done |

done := Semaphore new.

self vms machines do:

[:vm |

[| testClassName |

[testClassName := self allTests nextAvailable.

testClassName isNil]

whileFalse:

[self results nextPut: testClassName

-> (vm do: [:a |

ObjectStudio.RunSingleTestSuite run: a] with: testClassName)].

done signal] fork].

self vms machines size timesRepeat: [done wait].

self releaseVMs

First, we get the next available test, send it to the VM to execute it with the RunSingleTestSuite class>>run: method and save the result together with the test name. As soon as all tests are done, the Semaphore is signaled and the job for the VM is over.

In the starter process, we just wait for the Semaphore to be done and then release all the VMs.

RunSingleTestSuite is just a very simple class. It takes a string, converts it into a class and runs all the tests.

The Polycephaly framework is a quick and easy way to process data in parallel, but it has its limits:

  • The processes can only be started on a local machine.
  • BOSS framework and pipes are used to communicate between images, so you can maximize the benefit you get by minimizing the complexity of the objects you exchange between Virtual Machines.

There are also considerations specific to using Polycephaly with ObjectStudio:

  • The code has to be saved in the image; proxies don’t work here.
  • Set the #isRuntime flag to true to prevent the GUI from opening in the drone images.
  • Polycephaly is a general-purpose VisualWorks mechanism, so the startup block you pass to the drone images does not use the ObjectStudio compiler. But this is an issue for the start-block or string only. The code invoked after that can be written and tested in ObjectStudio as usual.

If you keep these things in mind and have a problem that could benefit from parallel processing, please take a look at Polycephaly. Maybe it’s the right thing for you.