The Threadmaster
By Jim Jagielski
After several years of design and development, Apache 2.0 is ready for prime time. The most visibleand perhaps most awaitedchange is native support for Unix threads. The proper use of threads can greatly improve the performance of most applications, so it's not surprising that threads generate a lot of discussion in development circles.
The Windows port of Apache 1.3 is, in fact, threaded. But most people use Apache with Unix-based systems, so the thread support in Apache 2.0 is a big step forward. At their most basic, threads are lightweight processes. In Unix, each application runs as a separate process. The operating system starts a new process whenever a user launches a new application. In many cases, the application itself can "fork" a new process to complete some tasks. But forking new processes is expensive: Creating them costs an appreciable amount of server memory and time. If your server is creating a lot of processes, the end result will be very slow response times to requests and actions.
Threads were designed to avoid this bottleneck. Using threads drains fewer server resources than forking a new process. One process can create many threads, all sharing the same memory space. This, too, saves time. For these reasons, it's preferable to use threads when an application needs to perform several tasks, each with the same priority.
Caveats
Threads are great, but it was obvious early in the Apache 2.0 design cycle that restricting all operations to threads was shortsighted.