5.3 ProcessThread Spawning Strategies

I l @ ve RuBoard

5.3 Process/Thread Spawning Strategies

There are various strategies for spawning processes and threads. Different strategies can be used to optimize concurrent server performance under different circumstances, thereby enabling developers to tune server concurrency levels to match client demands and available OS processing resources. As shown below, the different strategies trade off decreased startup overhead for increased resource consumption.

Eager spawning. This strategy prespawns one or more OS processes or threads at server creation time. These "warm-started" execution resources form a pool that improves response time by incurring service startup overhead before requests must be serviced. This pool can be expanded or contracted statically and/or dynamically depending on various factors, such as number of available CPUs, current machine load, or the length of a client request queue. Figure 5.3 (1) depicts an eager spawning strategy for threads. This design uses the Half-Sync/Half-Async pattern [SSRB00], which feeds requests from an I/O layer up to a worker in the pool of threads.

Figure 5.3. Thread Pool Eager Spawning Strategies

An alternative eager spawning strategy is to manage a thread pool using the Leader/Followers pattern [SSRB00], as shown in Figure 5.3 (2). This pattern defines an efficient concurrency model where multiple threads take turns sharing a set of event sources to detect, demultiplex, dispatch, and process service requests that occur on the event sources. The Leader/Followers pattern can be used in lieu of the Half-Sync/Half-Async pattern to improve performance when there are no synchronization or ordering constraints on the processing of requests by pooled threads.

On-demand spawning creates a new process or thread in response to the arrival of client connection and/or data requests, as the thread-per - request and thread-per-connection models shown in Section 5.1. Figure 5.4 illustrates this strategy for threads. The primary benefit of on - demand spawning strategies is their reduced consumption of resources. The drawbacks, however, are that these strategies can degrade performance in heavily loaded servers and determinism in real-time systems due to the costs incurred when spawning processes/threads and starting services.

Figure 5.4. Thread-per-Request On-Demand Spawning Strategy

Logging service Section 9.2 on page 191 presents a logging server implemented with a thread-per-connection, on-demand spawning strategy. Examples that illustrate eager spawning strategies are presented in [SH]. In that book, we show how ACE frameworks can be applied to implement both half-sync/half-async and leader/followers thread pool models.

I l @ ve RuBoard


C++ Network Programming
C++ Network Programming, Volume I: Mastering Complexity with ACE and Patterns
ISBN: 0201604647
EAN: 2147483647
Year: 2001
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net