Information Technology Reference
In-Depth Information
Read
Static
Page
Read
and
Parse
Send
Page
Connect
Generate
Dynamic
Page
Figure6.3: A staged architecture for a simple web server.
Example: Simple web server. Figure 6.3 shows a staged architecture for
a simple web server that has a first connect stage that uses 1 thread to set up
network connections and that passes each connections to a second read and
parse stage.
The read and parse stage has several threads, each of which repeatedly gets
a connection from the incoming queue, reads a request from the connection,
and parses the request to determine what web page is being requested.
If the request is for a static web page (e.g., an HTML file), the read and parse
stage passes the request and connection to the read static page stage, where
one of the stage's threads reads the specified page from disk. Otherwise,
the read and parse stage passes the request and conection to the generate
dynamic page stage, where one of the stage's threads runs a program that
dynamically generates a page in response to the request.
Once the page has been fetched or generated, the page and connection are
passed to the send page stage, where one of the threads transmits the page
over the connection.
The key property of a staged architecture is that the state of each stage is
private to that stage. This property improves modularity, making it easier to
reason about each stage individually and about interactions across stages.
As an example of the modularity benefits, consider implementing a system
where different stages are produced by different teams or even different com-
panies. Each stage can be designed and tested almost independently, and the
system is likely to work as expected when the stages are brought together. For
example, it is common practice for a web site to use a web server from one com-
pany and a database from another company and for the two to communicate
via messages.
Another benefit of this approach for some applications is improved cache
locality. If a thread on a processor is operating on a subset of the system's
state, it may have a better cache hit rate than a thread that must access state
Search WWH ::




Custom Search