Server Smalltalk Guide

Multithreading and multiprocessing

SST supports multithreading through user threads (Smalltalk processes) and asynchronous C callout (ACO) facilities using OS threads. Calls to blocking OS resources (for example, TCP Sockets) do not block the entire VM and all other running Smalltalk processes. Only the Smalltalk process initiating the OS call is blocked.

However, since the all Smalltalk code is run in one OS thread (and process), SST cannot take advantage of parallel processing resources such as SMP machines. As a result, a single VM running multiple server programs in the same Smalltalk image cannot be load balanced by the OS.

Internally, however, SST is fully multithreaded. For instance, supplied dispatchers such as threaded or pooled dispatchers use several user threads (Smalltalk processes) to execute requests. All components are thread safe.

SST supports multiprocessing to the same degree as normal Smalltalk. In the simplest case two servers simply run as two Smalltalk VMs running different images. Since objects cannot communicate or be shared between the images, it is as though they were on different machines. The normal SST communications infrastructure can be used. Running on the same machine, SST uses shared memory and ICs to reduce both the footprint and startup time of each server process. Multiprocessing configurations can take advantage of OS-level processing resources and load-balancing.

The model you should choose for particular applications depends on their requirements. Multiprocessing is simpler to program and manage as the unit of concurrency is an OS process, which forms a high barrier of protection. A drawback of this is that communication and sharing between concurrent entities is more costly.

Multithreading allows entities to pass data by simply passing a pointer and control access using quick and easy locking (for exmple, semaphores). Unfortunately, Smalltalk does not provide very many thread-safe classes in its library so you must be careful to avoid race conditions and other concurrency problems.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]