the conceptual architecture of the apache web
server
octavian andrei
dragoi
, department of computer science, university of
waterloo,
|
assignment 1 for cs746g january
26, 1999
|
abstract:
this report presents the conceptual (abstract)
architecture of the apache web server. it tries to emphasize the overall
structure of the system, without going into implementation details, or
requiring such details to be previously known by the reader. the main purpose
is to make the architecture "intellectually tractable" ().
the
conceptual architecture has been inferred from a number of apache related
documents and from the way source files are grouped and named.
at a high
level the apache server architecture is composed of a core that
implements the most basic functionality of a web server and a set of standard
modules that actually service the phases of handling an http
request.
the server core accepts a http request and implicitly invokes the
appropriate handlers, sequentially, in the appropriate order, to service the
request.
the report shows that the most similar architectural style (in the
sense of )
that can characterize the apache architecture is "implicit invocation"
, although the notion of event does not exist in the architecture.
the
architecture offers great opportunities for extending or changing the apache
functionality, by the means of adding or replacing modules.
keywords:
apache, conceptual architecture, abstract
architecture, web server
available online at:
a good architectural description make the architecture "intellectually
tractable". the paper might, sometimes, simplify the actual architecture order
to achieved the previously stated desiderata.
the report assumes no previous familiarity with the architecture of the
apache web server. so it can serve as an introductory reading on the
architecture of the server.
it should be noted that the architecture described here might not be entirely
accurate. it has been inferred based on several ,
including the overall structure of files and files name. it does not start from
a previously existing complete design document.
1.1. about apache
the apache web server is
currently the most popular web server, according to a . it has maintained
(and improved) its status since mid 1996. originally, the project was based on
ncsa httpd 1.3, were from the name ("a patchy server"). since then
the code base was completely rewritten, and evolved into a completely
independent project.
one of the major reasons for the apache success is the
fact that is an "open source" project (any one can have access to apache code
source, and any one can write its on modules to suits one needs). (source ).
may be here is the place to mention that apache is written to be drop-in
compatible with the ncsa server. this has design consequences due related to
some configuration commands promoted by ncsa server, which cannot be naturally
implemented in apache. these commands are supported in a way that, somehow, is
not in the general "philosophy" of the system.().
(more details in the configuration section).
1.2. overview
the report is organized as follows:
offers a high level view on the conceptual architecture of the apache,
outlining the main building bricks: the apache core and the apache modules. next
gives details on the conceptual architecture of the apache core and
shows what the high level anatomy of a module. it also outlines the phases of
handling an http request as divided by the apache architecture. it ends with a
short description of the most representative standard modules. gives the conceptual architecture of the apache server and analyze the
concurrency in the system. present some additional issues related to the architecture of the system,
mainly how configuration fit into the hole picture, how is data passed between
core and modules and how resources are allocated and managed managed. next comments on the architectural styles (in the sense of ,
)
applicable to the apache architecture, while the elaborates on extensibility issues.
and a end the report.
the function of a web server is to service requests
made through http protocol. typically the server receive a request asking for a
specific resource and returns the resource as a response. a client might
reference in its request a file, and then that file is returned or, for example,
a directory and then the content of that directory (codified in some suitable
form) is returned. a client might also request a program, and it is the web
server task to launch that program (cgi script) and to return the output of that
program to the client. various other resources might be referenced in client's
request.
to summarize: the web server take a request, decode it, obtains the
resource and hands it to the client.
additional concerns related to controlling access authorization and clients
authorizations are also in the responsibility of the web server. as has been
said the web server might execute programs as response to clients requests. it
must ensure that this is not a threat for the host system (were the web server
runs). in addition, the web server must be capable, not only to respond to a
high rate of requests, but also to satisfy a request as quickly as possible.
2.1. description
as opposed to a monolithic server
architecture in which all the activities are done by a single unit (in which
different parts of handling a request are poorly delimited), apache takes a
modular approach. illustrates the high level conceptual architecture. there is a
core part of the server that is responsible for defining and following
the steps in servicing a request and several modules that actually
implement the different phases of handling the request.
as shall be seen
later does not capture an important characteristic of the architecture,
namely, the predefined order in which modules are called, based on their
advertised characteristics.
|
figure 1.high level conceptual
architecture |
the idea is to
keep the basic server code clean while allowing third-parties to override or
extend even basic characteristics.
this section presents in more detail the components of
the apache server architecture. it presents the conceptual parts of the apache
core and how a request is decomposed in a set of phases. it also describe the
anatomy of an apache module (at a conceptual level).
3.1. the core
the core implements the basic
functionality of the server. in addition it implements a number of utility
functions. a worth mentioning utility, is the one that provides resources
allocation on a per request pool. this facility is offered not only to the
server core but also to modules.
the following are the components of the core:
http_protocol.c
: contains routines that directly communicates
with the client (through the socket connection), following the http protocol.
all data transfers to the client are done using this component.
http_main.c
: the component that startup the server and
contains the main server loop that waits for and accepts connections. it is
also in charge of managing timeouts.
http_request.c
the component that handles the flow of the
request processing, dispatching control to the modules in the appropriate
order. it is also in charge with error handling.
http_core.c
: the component implementing the most basic
functionality, which is described in a comment from a source file as being
"just 'barely' functional enough to serve documents, though not terribly
well". another interesting quote from a source file comment illustrates
very well the function of this component:"this file could almost be
mod_core.c". meaning that the component behaves like a module but has to
access some globals directly (which is not characteristic for a module).
- the component that take care of allocating resource pools, and keeping
track of them. (
alloc.c
)
- other utilities, including reading configuration files and managing the
information gathered from those files (
http_config.c
), as well as
support for virtual hosts. an important function of http_config
is that form the list of modules that will be called to service different
phases of the requests.
in the above list the term component
has been used in order to avoid the term module which will be used
only to refers to apache modules |
figure 2. architecture for apache
core |
depicts the interaction between different components of the core. as all
components use the different utilities functions, connectors to utilities and
alloc have not been pictured. interaction is used in a broader sense,
meaning from calling a component service function to "conceptually" relinquish
control to that component.
it is interesting to observed that although the components of the core have
rather distinct functionality, there is not a simple way to depict the
interactions between them. most of the architectural information being in the
names of the modules rather than in the connectors between them.
this is due to the considerably effort done by the designers to move
everything that can be expressed as a separate entity into the modules part of
the apache server. what is left in the core are components too interconnected to
be written as separate modules.
3.2. request phases
a module implements only
portion of the functionality for servicing a client request. more than one
module are necessary to completely respond to a request. however module does not
know one about the other. the control is transfered back and forth between the
core and different modules. this is handled by dividing the handling of the
request into a set of distinct phases.
the following are the phases of handling a request for the apache server:
- uri to filename translation;
- check access based on host address, and other available information;
- get an user id from the http request and validate it;
- authorize the user;
- determine the mime type of the requested object (the content type, the
encoding and the language);
- fix-ups (for example replace aliases by the actual path);
- send the actual data back to the client;
- log the request;
the phases are "controlled" by the http_request
component of the core as has been already stated (see ).
3.3. modules
as has been said the role of the
modules is to implement/override/extend the functionality of the apache web
server. all modules has the same interface to the core of the server. module
does not interact directly one with another. if they interact it is always
through the apache core.(implicit invocation as shall be seen).
|
figure 3. architecture of an apache
module |
apache (1.3) permits
loading of modules when they are needed (they are dynamically linked with the
server) and therefore the initialization and configuration methods might be
called when the module is loaded as opposed to when the server is initialized.
3.4. handlers
a handler is for apache the action
that must be performed in some phase of servicing a request. for example when
the requested object is a file, the handler that returns the the file must open
the file, read the content of the file and hand the content of the file to the
client (through apache core).
handlers are defined by modules, and a module might specify handlers for one,
many or none of the phases of a request. handlers are the part of the module
that is called when the processing of the request enters the phase for which the
handler is defined.
the rationale behind having modules defining handlers for more than one phase
is that a module might save internally data on the request being processed, and
when its handlers for a subsequent phase of the request are called they might
make use of those the data. in theory the module might even save data between
different request (e.g. it might cash some file content for future use).
it should be noted that there are additional functions exported by modules,
related with configuration, and initialization, they are called in the startup
phase of the server.
3.5. standard modules
apache comes with a set of
standard modules for providing the complete functionality of a web server. the
most representative/relevant among the standard modules are listed below. they
also illustrate what kind of manipulation can be done at each phase.
- for uri to file name translation phase:
mod_userdir
: translate the user home directories into
actual paths mod_rewrite apache 1.2 and up
mod_rewrite
: rewrites urls based on regular expressions, it
has additional handlers for fix-ups and for determining the mime type
- for authentication / authorization phases:
mod_auth, mod_auth_anon,mod_auth_db, mod_auth_dbm
: user
authentication using text files, anonymous in ftp-style, using berkeley db
files, using dbm files.
mod_access
: host based access control.
- for determining the mime type of the requested object (the content type,
the encoding and the language):
mod_mime
: determines document types using file extensions.
mod_mime_magic
: determines document types using "magic
numbers" (e.g. all gif files start with a certain code)
- for fix-ups phase:
mod_alias
: replace aliases by the actual path
mod_env
: fix-up the environment (based on information in
configuration files)
mod_speling
: automatically correct minor typos in urls
- for sending actual data back to the client: to chose the appropriate
module for this phase the mime type or the pseudo mime type (e.g. for a
cgi-script) is used.
mod_actions
: file type/method-based script execution
mod_asis
: send the file as it is
mod_autoindex
: send an automatic generated representation
of a directory listing
mod_cgi
: invokes cgi scripts and returns the result
mod_include
: handles server side includes (documents parse
by server which includes certain additional data before handing the document
to the client)
mod_dir
: basic directory handling.
mod_imap
: handles image-map file
- for logging the request phase:
mod_log_*
: various types of logging modules
has shown which are the main components of the apache web server and how
they interact. however it does not illustrate the fact that handlers in modules
are called in a fixed, predefined order, which is the order of the phases of
servicing a request. tries to add the flow information mention above.
for some phases only one module (handler in a module) can be called. such
phases are the authorization, the authentication, the return of the actual
object to the client, and sometimes the uri to filename translation.
other
phases of servicing a request can have more that one handler called. for example
there can be more than one module called to implement the logging part of the
request.
in some phases of processing a request all the handlers (in the registered
modules) might be called until one returns a special code meaning that
subsequent registered handlers for the current phase should not be called. an
example is the uri to filename, translation phase.
further more there might
be the case that a handler returns an error code. in that case the processing of
the request should stop and an error should be returned to the client (i.e. no
other handlers are called, from this phase or subsequent phases).
|
figure 4. conceptual architecture of apache
server |
4.1. concurrency in apache
some web sites are
heavily loaded (many requests per minute or even per second). traditionally
tcp/ip servers fork a new child to handle new incoming request from clients.
however in the situation of a busy web site the overhead of fork-ing a huge
number of children will simply suffocate the machine.
as a consequence, apache uses a different technique, namely persistent
server processes. it forks a fixed number of children, right from the
beginning. the children service incoming requests independently (different
address spaces). concurrency in apache server is pictured in
alternatively, when apache compiles on ms windows (as opposed to
unix), a fixed number of threads is started from the beginning to service the
incoming request (due probably to specific characteristic of this operating
system).
|
figure 5. concurrency on
apache(unix) |
it is
interesting that apache server can dynamically control the number of children it
forks (i.e. increasing or decreasing it), based on current load.
from another point of view one might raise the question if a module is a
separated process or can be implemented as a separated process. in apache module
is not a separated process. however some modules might fork new children in
order to do their job. a readily example is the mod_cgi
module,
which handles the cgi script. it must fork a new child to execute the actual cgi
script (after proper redirection of the standard input and output for the child
process), and wait for it to finish. but this is a characteristic of the
mod_cgi
, many other modules need not to fork children.
a different kind of module is the one that although it is not a separate
process and does not for children it communicate through ipc mechanisms or
sockets in with a different process (which might, for instance, be located on a
different machine). an example of such module would be an authorization module
which communicate with a server that manages users and passwords information.
even the cgi module might be implemented in this way (i.e. the actual script
running as a completely different process not a child) which will result in
improved security, but will have the communication overhead as a penalty.
some
additional issues has been left aside from the description of the conceptual
architecture and are treated in the next sections.
5.1. configuration of apache components
one of the
declared purposes of the apache server architecture is to make it highly
customizable.
configuration files permit to customize not only the behavior
of the server but the one of the modules too. each module can advertise the
custom commands it recognize from configuration files and will be called when
such commands are found. those commands might be completely new commands (not
known in by the server core).
apache permits even per directory customization
via a file call .htaccess. this file also might contain commands
understand only by modules.
an interesting concept implemented by apache is the one of virtual
hosts. the server can respond to more than one name (i.e. www.example and
www2.example), each assigned to one of the multiple ip addresses of the machine.
the multiple ip addresses can be addresses associated with physical network
interfaces or can be addresses associated with virtual network interfaces
(simulated via logical devices by the operating system). apache is able to
"tell" under which name the host has been referenced and use different
configuration options (e.g. allowing more access rights to users accessing the
host through an interface networked in the local network, as opposed to users
accessing the web server via an interface networked in the outside-the-company
network). modules also have accessed to this information.
to summarize, the apache "philosophy" related to configuration is: each
component takes care of its own configuration, and configuration commands. the
server core parse the configuration files and dispatches configuration commands
to the appropriate modules to be interpreted (executed), or interprets
(executes) the command itself if in particular was meant for it (i.e. is a
configuration command for the core not for a module).
5.2. compatibility with ncsa server - impact on
architecture
starting from the code base of the ncsa server apache
was always design to be a drop-in replacement for this server. that means that
apache must understand and follow the configuration commands, and recognize the
configuration files of the ncsa server. however this is not an easy task because
some of the commands must affect behavior that appear in more than one module.
therefore one of the main principle of the apache configuration machinery,
namely each module takes care of its own configuration must be broken .
to "fix" this the problem commands of ncsa server (e.g. options) are
interpreted by the apache core, even when they affect modules. the core make the
configuration available to modules in the same way it make available the general
configuration information.
5.3. data flow / data structures
data is exchanged
with various handlers in modules via a special structure called request
record which includes information about the resource requested (e.g.
filename), information about the configuration data related to the server, the
virtual host, and the directory context in which the request is processed.
another key structure is the one the apache core uses keep track of various
modules. it is a linked list of module records, each holding all the
information related to that module (e.g. handlers, configuration data per
module). the module record is the mean by which the core calls the module.
5.4.resource allocation - resource pool
an
interesting characteristic of the apache server it the concept of resource
pool. all resources related to a request (memory, file handlers) are
allocated and handled through a dedicated resource pool. further more, modules
can define their own sub-resource pools if they want to manage private resources
in a similar manner with general resources.
what is characteristic for the resource pool, is that all resources are freed
at once, when the resource pool is freed, preventing resource leakage. this is
particularly important due to use of persistent processes.
the
conceptual architecture described above, roughly approximate the style of
"implicit invocation". it should be noted however that the architecture
is not exactly an event based architecture, as specified in .
it is usually the case with software architecture that cannot be clearly
classified in a predefined style ("real systems hybridize and amalgamate the
pure style" - ).
to be more specific there
is no such concept as many events that are announced (broadcast). instead the
only event is a request from a http client, which starts a sequence of
predictable implicit invocations.
the core has a fixed order in which will
call the different handlers and will decide based on configuration information
which is the order in which the handlers for the same phase are called.
there is, however, something that might be compared with announcing an event,
namely is the issuing of a sub-request by a module in order to "force" the core
to perform some of the steps for a request on the sub-request (i.e. calling
sequentially handlers for each servicing phase). however this is not
(conceptually) a proper event, because the issuing module does not announce
something to other (unknown to it) modules. it just a mean of "forcing" an
implicit invocation.
there are other characteristics of event systems (as summarized in ) that does not "fit" the description of the
core-modules architecture of apache. for example there is no control asynchrony,
in the sense that the module issuing a the sub-request waits for the sub-request
to be completed.
also two phases of the request cannot be handled in parallel
(one uses the outcome of the precedent one). more over the module is not a
separate process, although it can fork children for some phases - like running a
cgi script.
so although the connectors between modules are implicit invocations
and data flow is a tree - with some restrictions (e.g some phases cannot have
more than one module to handle them, one phase is after the other) the
architecture does not have other characteristics of the event systems.
it can be argued however that as different instances of apache
(sub-processes) can handle in the same time request from different http clients
there is asynchrony. however the different instances are independent and do not
shared information related to the requests processed.
the way a request is serviced, with phases handled one after the other and
the outcome of a request is used (most of the time) by the next phase, has some
similarities with the general style of "pipe line" (as in )). there is no upstream control (i.e. when the
core invokes the handlers for one phase there is no data or control upstream).
however, again, there is no asynchrony and more important the core regain
control after each phase (i.e. after the handler has been invoked, and its
job is done).
further more, some phases does not provide any change in the conceptual
data-flow. and more significant, some handlers might be implemented by the same
module and those handler might exchange information via private data of the
module, bypassing the main data-flow. for example authorization and
authentication does not change the request, they can only deny the execution of
it. to conclude the pipeline is rather poorly reflected by the module
structures, although conceptually the idea exists, therefore the implicit
invocation seems more appropriate to characterize the general conceptual
architectural style.
as
it probably became obvious by now, apache server architecture easily permits
changes of the existing functionality or adding new functionality.
the
modular approach and the effort made by the designers to move as much as
possible from the web server functionality into separate modules make the task
easier. for example if the way uri are translated into file names have to be
extended, it is not necessary to change the module that does this task. it is
sufficient to write a different module which will be called before or after the
standard module has been called.
further more the ability of dynamically loading modules present in apache 1.3
release (no static linking with the server code), make the task of customizing
the server even easier as there is no need to recompile the entire server. it is
necessarily only to change some configuration files.
another feature worth
re-mentioning here is the capability of modules to define their own
configuration commands, for which they are implicitly called to execute.
an important part of the apache web server that cannot be changed only by
changing / adding a module is the one that implements the http protocol. on the
good, side the protocol is implemented as a separate piece of code
(http_protocol.c
), and all communication with the client is done
through it, so only that part must be changed in order to implement a future
version of http. however there is no well defined api, as is the case for
modules.
apache web
server has a modular architecture with a core component that defines the most
basic functionality of a web server (including the http protocol and the reading
of configuration files) and a number of modules which implements the steps of
processing a http request, offering handlers for one or more of the phases.
the core is the one that accepts and manages http connections and calls the
handlers in modules in the appropriate order to service the current request.
the architectural style can be characterized implicit invocation made
by the server core on handlers implemented by the modules. concurrency exists
only between a number of persistent identical processes that service incoming
http requests on the same port. modules are not implemented as separate process
although it is possible to fork children or to cooperate with other independent
process to handle a phase of processing a request.
the functionality of apache can be easily changed by writing new modules
which complements or replace the existing one. the server is also highly
configurable, at different levels (virtual host, directory, module) and modules
can define their own configuration commands.
apiapplication programming interface
componentterm used throughout this report in order to avoid the term module
which has been used in connection to (referring) an apache module. this
distinction is not a standard terminology, and has the only purpose to avoid
confusion.
core (apache core)part of the apache server that defines and manages the steps in answering
the request and implements the http protocol.
cgi (cgi script)common gateway interface, an interface describing how a web server passes
parameters and receive results form another process on the same machine called
cgi-script (executed by the web server when it receive a request referencing the
script).
handlera function of a module that will be implicitly invoked by the core to handle
the phase of processing the http request for which the handler was designed.
httphypertext transport protocol, the protocol that coordinate how the hypertext
files are transfered over the internet. however any files can be transfered via
http.
httpdthe usual name for the web server (stands for http daemon).
ipc (ipc mechanisms)inter process communication mechanisms (e.g. queues, semaphores, shared
memory)
mime typemime stands for multipurpose internet mail extension. mime types are the
types (e.g. gif, html) of the entities defined in mime request for comments
module (apache module)part of apache server that provides some functionality in one or more phases
of servicing an http request. its functions (handler) are implicitly invoked by
the apache core. it is interfaced with the apache core by a special api.
ncsa web server (ncsa httpd)the web server provided and maintained by the development group of the
national center for super-computing applications, at the university of illinois
at urbana - champaign
request (http client request)a message from the client containing information about the resource
requested and how it is wanted to be delivered.
resource (an http resource)a network data object or service which can be identified by a uri
response (http server response)the response from the web server to an http request, contains a header and
usually the actual resource. the header contains status information and
information on the resource (e.g. type, length of the binary representation).
resource poola large data structure allocated in one step by the apache core, which holds
the resources (memory blocks, open files) associated with a given request. when
the resource pool is no longer needed it is deallocated in one step (memory is
freed and files ore closed).
uriuniversal resource identifiers, are formated (fixed syntax) string which
identify objects via location, and other characteristics.
urluniform resource locators, a subclass of uri that locates resources based on
their location and the protocol used to fetch them (e.g.
http://www.uwaterloo.ca/index.html identifies the home page file of university
of waterloo)
virtual hosta single physical host might have more than one network interface, each with
a different ip address and a different host name. for clients it acts as being a
number of virtual hosts, one for each name.
blogjava-凯发k8网页登录
, robert thau, fifth
international world wide web conference, 1996, paris.
, robert s. thau.
, d. garlan, m.shaw, advances in
software engineering and knowledge engineering, vol. i, world scientific
publishing company, 1993.
, r. monroe, d. kompanek, r. melton,
d. garlan, ieee software, january 1997, pp 43-52.
, m. shaw, p. clementes, 1996
]]>