next up previous contents Back to Operating Systems Home Page
Up: Threading models Previous: One thread per client

Worker threads

This method improves on the scalability, with respect to the previous one, but increases complexity and hence slows the service rate when used for a small number of connections. A primary thread is used to select among ready connections, and dispatch tasks to a fixed number of worker threads. There are a number of ways in which to break down the work between the primary thread and a worker thread. The former can simply indicate to the latter that a certain connection must be serviced: the worker would wake up and do the job, or enqueue it for later processing if it's already busy. Or the main thread can give a first look at the connection request, and tell the worker thread what to do with it.

A problem with this scheme is the choice of the number of workers to use: if too many, the system will thrash, if too few, queues can get longer and longer. In general, a fine tuning of the application is needed on the filed. A commonly used rule of thumb, for multiprocessor machines, is to use at least as many threads as processors. More threads should be added if any of them spends a significant amount of time waiting for disk or network I/O to complete.



Franco Callari