Unveiling Poonawalla Fincorp’s Phenomenal Performance Under Abhay Bhutada’s L...
Tutorial on Constructing a Web-Server with Patterns at ADC 2004
1. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Pra 03
Constructing a Web-
Servers with Patterns
Michael Stal
Siemens Corporate Technology
Bemerkungen
Michael Stal – Aufbau eines Web- 1
Servers mit Hilfe von Patterns
Case Study
Bemerkungen
A High-Performance
Web Server
Dein Name – Dein Vortragstitel Pra 01 - S. 1
2. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Web Server: The Domain
Web Servers provide
content and content
delivery services to
internet users.
Bemerkungen
Web Server: Key
Challenges
Different end user needs and traffic
workloads require configurable web
server architectures regarding the
following aspects:
Concurrency models: thread per request,Bemerkungen
thread pool, ...
Event demultiplexing models: synchronous
or asynchronous
File caching models: least-recently used
(LRU), least-frequently used (LFU), ...
Content delivery protocols: HTTP/1.0,
HTTP/1.1, HTTP-NG
Operating system: UNIX, Win32, ...
Dein Name – Dein Vortragstitel Pra 01 - S. 2
3. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Event Demultiplexing (I)
A Web server must demultiplex and
process multiple types of event, such
as CONNECT and HTTP GET requests.
To be adaptable towards different usage
scenarios, its concrete event demultiplexing
and dispatching architecture should:
Support changing the event demultiplexing
and dispatching code independently of
event processing code.
Allow the integration of new or improved
versions of the event processing services.
Support a high throughput.
Be simple to use.
Bemerkungen
Event Demultiplexing (II)
Separate event demultiplexing and
dispatching from event processing
via Reactor:
Event handlers (HTTP_Handler)
represent the web server‘s services for
dispatches
processing events that can occur on an
* Event_
Bemerkungen
Reactor
Handler
associated event source.
maintains owns
Handles (Handle) represent event
*
*
sources whose events must be
select() Handle
notifies
processed.
An event demultiplexer (select())
HTTP_ HTTP_
Handler 1 Handler 2
discovers and demultiplexes events that
occur on handles.
A reactor (Reactor) provides the web
server‘s event loop and dispatches
events that occurred on Handles to
their associated HTTP_Handler.
Dein Name – Dein Vortragstitel Pra 01 - S. 3
4. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Reactor: Problem
Reactor (POSA2)
Clients
Problem: Event-driven applications must be
prepared to receive multiple service requests
simultaneously, but to simplify programming,
Logging
these requests should be processed serially. How
Records
This is a
logging
This is a
record
can we provide such an infrastructure so that:
logging
record
This is a
logging
record
Event
an application does not block on any single event
Sources
source and exclude other event sources from
being serviced.
Logging Server
application developers are shielded from low-level
event detection, de-multiplexing, and dispatching
mechanisms.
an application is extensible with new event
handling components.
Bemerkungen
a high throughput can be achieved.
Output Media
Reactor: Structure
Solution Structure: Separate event
dispatches
*
demultiplexing and dispatching from event
Reactor Event Handler
processing.
handle_event()
register() maintains
get_handle()
unregister()
handle_events()
The OS provides mechanisms to represent
owns
event sources (Handles) and to detect and
* Bemerkungen
Concrete
demultiplex events that occur on these event
Handle
Event Handler
* sources (Event Demultiplexers like
Event
Demuxer select()).
void handle_event(Event e) {
notifies
switch (e) {
A Reactor encapsulates the OS event
select() case READ_EVENT: // …
case WRITE_EVENT: // …
demultiplexing mechanisms and provides
// …
}
}
functionality to dispatch events to application
void handle_events() {
// Listen for events to occur.
services.
result = select(…);
// Dispatch event handler.
Event Handlers provide functionality to process
for (HANDLE h = 0; h < max_Handle; ++h) {
if (FD_ISSET (&read_fds, h)
certain types of event that occur on a certain
handler_table[h].event_handler->
handle_event(READ_EVENT);
event source. They register with the reactor to
// Same for WRITE and EXCEPT events.
}
}
get dispatched when the respective events
occur on their event source.
Dein Name – Dein Vortragstitel Pra 01 - S. 4
5. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Reactor: Dynamics
Solution Dynamics: Dispatch an event handler
whenever an event occurs on its handle for
Reactor Handler 1 Handler 2
which it has registered.
register(handle, events)
The Concrete Event Handlers register their
register(handle, events)
Handle and all events of interest with the
Reactor.
handle_events
The application’s main event loop calls the
select
Reactor to listen for events to occur on all
registered Handles.
Once one or more events occurred on the
handle_event(event)
Handles, the Reactor serially dispatches their
Event Handlers to process the occurred
events, if the Handlers had registered for
them.Bemerkungen
Reactor: Consequences
Benefits
Separation of concerns: event de-multiplexing and
dispatching infrastructure is separated from application-
specific event processing.
Reusability: the event de-multiplexing and dispatching
Bemerkungen
infrastructure is a reusable component.
Extensibility: new or improved event handlers can be
added easily.
Ease of use: a Reactor provides a simple, serial event
handling architecture.
Liabilities
Restricted applicability: requires appropriate OS support.
Non-pre-emptive: in single-threaded applications, long
running event handlers can prevent the processing of
other events.
Dein Name – Dein Vortragstitel Pra 01 - S. 5
6. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Reactor: Example
TAO: The high-performance,
real-time CORBA ORB
TAO, The ACE ORB, uses
a multi-threaded Reactor
design as its central
server-side ORB core
event handling
infrastructure.
Bemerkungen
Reactor
Reactor: Known Uses
Object Request Brokers: The ACE
ORB (TAO) provides Reactor-based
event handling infrastructures.
GUI infrastructures: MFC and Win
Forms provide Reactor-based main
Bemerkungen
event loops.
ACE: The open source ADAPTIVE
Communication Environment provides
several reusable Reactor frameworks
for different types of event
demultiplexers, such as
WaitForMultipleObjects() and
select(), and concurrency models,
such as Leader/Followers.
Dein Name – Dein Vortragstitel Pra 01 - S. 6
7. Advanced Developers Conference
10.-11. Oktober 2004
Connection Establishment
Bemerkungen
(I)
The two key activities performed by a connect
connect
web server are accepting client
connection requests and processing connect
subsequent HTTP requests.
connect
To provide a high throughput and quality
of service to clients, processing a particular
HTTP request must not prevent the web connect
server from accepting new client connect
connection requests.
To support the configuration of the web
get
server towards different environments and get
usage scenarios, it should be possible to
modify connection establishment code
independently of HTTP request processing
Bemerkungen
code.
Connection Establishment
(II)
Separate the establishment of
connections from processing
events via Acceptor-
Connector:
dispatches
* Event_
Reactor
Acceptors (HTTP_Acceptor)
Bemerkungen
Handler
maintains owns
listen for incoming client
*
* connection request and
select() Handle
notifies
create/initialize service handlers to
process subsequent HTTP
HTTP_ HTTP_
requests.
Acceptor Handler
Service handlers (HTTP_Handler)
are created by an acceptor to
process a specific client‘s HTTP
requests.
Dein Name – Dein Vortragstitel Pra 01 - S. 7
8. Advanced Developers Conference
10.-11. Oktober 2004
Acceptor-Connector:
Bemerkungen
Problem
Acceptor-Connector (POSA2)
Clients
Problem: In networked systems, components must
first connect to one another before they can
interact. However:
2: Send
1: Establish
Logging
Connection
in many systems components can act both as
Record
This is a
clients that initiate a connection to a remote
logging
record
component or as servers that accept connection
requests from remote clients.
the code for connection establishment is largely
Logging Server
independent of service processing code and can
also alter independently.
if connection establishment code is interwoven
with service processing code, components
cannot handle new connection requests while
they are processing service requests.
Bemerkungen
Output Media
Acceptor-Connector:
Structure
Solution Structure: Separate
Connector Service Handler Acceptor
connection establishment from
connect() handle_event() accept()
service processing.
Service Handlers implement the
components that want to interact.
Concrete Concrete Concrete
Connector Service Handler Acceptor
Bemerkungen
Connectors actively establish new
connections on behalf of a Service
Handler to a remote Acceptor.
activates creates and/or
activates
Acceptors passively accept
connection requests from remote
void connect(Service_Handler *h) { void accept() {
Connectors and initialize a Service
// Establish connection for // Create new Service Handler.
// Service Handler h. Service_Handler *h = new …;
Handler to service the connection.
if (IPC_mechanism.connect(*h))
// Activate Handler, e.g., // Establish a connection
// to register // between the client and
Note: both synchronous and
//with a Reactor. // the newly created
activate(h) // Service Handler.
asynchronous connection
else IPC_mechanism.accept(h);
// Error handling.
establishment can be supported.
} // Activate Handler, e.g., to
// register with a Reactor.
activate(h);
}
Dein Name – Dein Vortragstitel Pra 01 - S. 8
9. Advanced Developers Conference
10.-11. Oktober 2004
Acceptor-Connector:
Bemerkungen
Dynamics
Solution Dynamics: Let Connector
and Acceptor establish a connection
Handler 1 Acceptor
Connector
and pass them on to interacting
Service Handlers.
A Concrete Service Handler asks a
connect(this)
Concrete Connector to establish a
accept
connection to a specific remote
Handler 2
activate
Concrete Service Handler.
The Connector sends a connection
interact
request to a Concrete Acceptor
residing on the respective server.
Connector and Acceptor establish
the connection and pass them on to
‘their’ Concrete Service Handlers,
which then interact.
Bemerkungen
Acceptor-Connector:
Consequences
Benefits
Separation of concerns: connection establishment is
separated from application-specific service processing.
Reusability: connectors and acceptors are reusable
Bemerkungen
components.
Efficiency: while service handlers still interact, connectors
and acceptors can already establish a new connection.
Liabilities
Complexity: complex infrastructure and complex
implementation for the asynchronous connection
establishment.
Dein Name – Dein Vortragstitel Pra 01 - S. 9
10. Advanced Developers Conference
10.-11. Oktober 2004
Acceptor-Connector:
Bemerkungen
Example
Call center applications, such as the
Ericsson EOS Call Center Management
System or Siemens FlexRouting, use
Acceptor-Connector configurations to
establish connections actively with
passive supervisors (or agents).
Public
Network
Bemerkungen
Acceptor-Connector:
Known Uses
Web Browsers: Internet Explorer, Netscape to connect to servers
associated with images embedded in html pages.
Object Request Brokers: The ACE ORB (TAO) and Orbix 2000 to
establish connections to ORB services.
Bemerkungen
ACE: provides a reusable Acceptor-Connector framework
Call Center Management Systems: Ericsson, Siemens to establish
connections to supervisors.
Dein Name – Dein Vortragstitel Pra 01 - S. 10
11. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Concurrency (I)
A web server must serve multiple
clients simultaneously and at a high-
quality of service.
Multi-threaded, concurrent event processing
is a typical response to this requirement.
Yet:
Thread management overhead should be
minimized to not degrade performance
unnecessarily.
Resource consumption should be
predictable to avoid server saturation.
Throughput is important. All events are
therefore of identical priority, they are
processed in the order of their arrival.Bemerkungen
Concurrency (II)
Let multiple Leader/Followers service
threads share a common set of
event sources by taking turns
discovering demultiplexing,
dispatching, and processing
Thread_
shares Pool coordinates
events:
Bemerkungen
(de)activates
A thread pool (Thread_Pool)
*
Event_
coordinates a group of event handler
Reactor
Handler
threads to share a common set of event
maintains owns
* * sources to process events.
*
select() Handle
Event handlers (HTTP_Handler,
notifies
HTTP_Acceptor) join the thread pool
to process client HTTP requests.
HTTP_ HTTP_
Acceptor Handler
A Reactor (Reactor) maintains the set
of shared event sources.
Handles (Handle) represent the set of
event sources shared by the event
handler threads.
Dein Name – Dein Vortragstitel Pra 01 - S. 11
12. Advanced Developers Conference
10.-11. Oktober 2004
Leader/Followers:
Bemerkungen
Problem
Leader/Followers (POSA2)
Clients
Problem: An event-driven application may use
multi-threading to serve multiple client requests
simultaneously. However:
Concurrency overhead, such as thread-creation,
context switching, thread coordination, should
not outweigh the benefits of multi-threading.
Resource consumption should be predictable to
avoid saturation of the event-driven
Logging Server
application.
Some concurrent application also trade general
throughput and performance over scheduling
and prioritizing.
Requests are structured, repetitive, require
immediate response, and can be served via
Bemerkungen
short, atomic, and isolated processing actions.
Output Media
Leader/Followers:
Structure
Solution Structure: Introduce a thread
demultiplexes
Thread Pool Event Handler
* pool in which multiple service instances
join() handle_event()
share a common event source.
uses
leader()
Events arrive on a Handle Set shared by
Concrete
all threads.
Event Handler
Handle Set
Bemerkungen
Event Handler threads implement
application services:
follower
threads
• A Leader Thread gets exclusive access to
processing
Event
threads
the Handle Set, and blocks until an event
Handler
Event
arrives.
Handler
• Follower Threads queue up behind the
Event Event
leader and wait until it is their turn to be
Handler Handler
the leader.
• Processing Threads are processing an
Event Event
Handler Handler
event they received when being the
leader.
Handle
Set
A Thread Pool coordinates the Event
leader
thread
events
Handler threads.
Dein Name – Dein Vortragstitel Pra 01 - S. 12
13. Advanced Developers Conference
10.-11. Oktober 2004
Leader/Followers:
Bemerkungen
Dynamics
Solution Dynamics: Let the Event
follower
threads
Handler threads take turns on the
shared Handle Set.
processing
Event
threads
All threads are spawned. One thread obtains
Handler
Event
access to the Handle Set and becomes the
6 Handler
Leader thread (1), all other threads become
Followers.
An event occurs on the Handle Set and is
Event Event
received by the Leader thread (2).
Handler Handler
promote
The Leader thread changes its role to a
leader
Processing thread and processes the request
5
(3), the Thread Pool promotes one Follower
4
Event Event
to become the new Leader (4).
Handler Handler
While the event is processed (5), steps (2) -
3 1
(4) recur.
Handle
When the event processing finished the
Set 2
Processing thread changes its role to a
Bemerkungen
leader
Follower and waits until it becomes the new
thread
events
Leader again (6).
Leader/Followers:
Consequences
Benefits
Simple thread management: threads
coordinate themselves via the pool; all threads are spawned
at system start-up.
Bemerkungen
Predictable resource consumption: the thread pool is of fixed
size
Performance: One of the fastest—if not the fastest—
concurrency architecture.
Liabilities
Most suitable for applications with a small set of atomic
services.
Only suitable for systems whose services have a small
memory footprint.
No scheduling / priority handling possible.
Dein Name – Dein Vortragstitel Pra 01 - S. 13
14. Advanced Developers Conference
10.-11. Oktober 2004
Leader/Followers:
Bemerkungen
Example
On-Line Transaction Processing (OLTP)
Systems, such as for travel agencies,
financial services, or broker information,
often use the a Leader/Followers
concurrency architecture to perform high-
volume transaction processing on backend
database servers.
Bemerkungen
Leader/Followers: Known
Uses
Object Request Brokers: The ACE ORB
(TAO) and to handle network events.
Application Servers: Application Server to
handle network events.
Bemerkungen
Transaction Monitors: Tuxedo, MTS
Transaction Service to process transactions.
TAO Features
• Open-source
• 500+ classes
• 500,000+ lines of C++
• ACE/patterns-based
• 30+ person-years of effort
• Ported to UNIX, Win32, MVS,
and many RT & embedded OSs
(e.g., VxWorks, LynxOS,
Chorus, QNX)
Dein Name – Dein Vortragstitel Pra 01 - S. 14
15. Advanced Developers Conference
10.-11. Oktober 2004
Concurrency Coordination
Bemerkungen
(I)
To avoid concurrency hazards like race
conditions, the access sequence of HTTP Processing Threads
threads to shared web server HTTP_ HTTP_
components must be coordinated. HTTP_ HTTP_
Handler Handler
HTTP_ HTTP_
Handler Handler
Handler Handler
Some of these shared components—such as the
Thread_Pool—are relatively small-sized Thread_Pool
objects with a fairly simple, straight-forward
logic. Reactor
It is crucial that the Thread_Pool executes
efficiently—it is the heart of the web servers The thread pool
Is shared by the
event handling infrastructure. Therefore, the HTTP_Handlers
thread coordination mechanism should be To get access to
The web server‘s
efficient. Event sources.
Expensive thread coordination overhead Bemerkungen
should be avoided.
Concurrency Coordination
(II)
Coordinate the access to the
Thread_Pool by implementing it as
Thread_
a Monitor Object:
shares Pool dispatches
join()
The thread pool (Thread_Pool) is a
leader()
* Bemerkungen
monitor object.
(de)
Event_
Reactor activates
The thread pool‘s services (join(),
Handler
maintains owns
Thread_Pool::join() {
leader()) are synchronized methods.
// Acquire mutex lock automatically.
* *
Guard<Thread_Mutex> guard (mutex_);
*
select() Handle
The tread pool implementation uses a
// run the leader, follower, processor loop.
notifies
for (;;) { // for ever ...
// We have a leader, so sleep ...
monitor lock (mutex_) and a condition
while (leader_thread != NO_LEADER)
condition_.wait(timeout);
variable (condition_) to synchronize
HTTP_ HTTP_
// Allow other threads to join the pool.
Acceptor Handler
guard.release();
the access to its services transparently
// We are the leader, so access the
// event sources.
for the HTTP processing threads
reactor_->handle_events();
(HTTP_Acceptor , HTTP_Handler).
// Reenter monitor to serialize the test.
guard.acquire();
}
}
Dein Name – Dein Vortragstitel Pra 01 - S. 15
16. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Monitor Object: Problem
Monitor Object (POSA2)
Problem: Concurrent access to ‘small’
A Call
Processing
concurrent objects such as a queues or
System
stacks should be as simple as possible:
Synchronization should be easy to
implement.
+49/89/909090
Threading and synchronization overhead
should be minimized or, even better,
+49/89/232323
A Call
avoided.
Processing +49/89/111222
Queue
Yet clients should not notice that the object
+49/89/999999
is shared.
+49/89/987654
+49/89/303030
Bemerkungen
Monitor Object: Structure
Solution Structure: Synchronize
Monitor Object
an object’s methods so that only
sync_method1()
one method can execute at any
sync_method2()
one time:
uses uses 1..*
A Monitor Object is an object
Monitor Lock Monitor Cond.
Bemerkungen multiple threads.
shared among
acquire() wait()
release() notify()
Synchronized Methods
implement thread-safe functions
of the Monitor Object.
void sync_method1() {
lock.acquire(); // Acquire monitor lock.
One or more Monitor Conditions
void sync_method2() {
... // Start processing.
lock.acquire();
allow the Synchronized Methods
// Suspend thread on a monitor condition
... // Start processing.
// if immediate progress is impossible.
to schedule their execution.
if (progress_impossible)
if (progress_impossible)
condition_1.wait();
condition_2.wait();
A Monitor Lock ensures a
... // Resume processing.
... // Resume processing.
serialized access to a Monitor
// Notify waiting threads that can
condition_1.notify();
Object.
// potentially resume their processing
// because we are done.
lock.release();
condition_2.notify();
}
lock.release(); // Release monitor lock.
}
Dein Name – Dein Vortragstitel Pra 01 - S. 16
17. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Monitor Object: Dynamics
Solution Dynamics: Let the Monitor
Object schedule its own method
Client Client Monitor Monitor Monitor
execution sequence.
Thread1 Thread2 Object Lock Cond.
A Client Thread invokes a Synchronized
method acquire
Method. The method acquires the Monitor
Lock and starts executing.
wait
automatic
At some point, the method cannot proceed,
automatic release
suspend
therefore it suspends itself on the Monitor
Condition, which automatically releases the
acquire
method
lock and puts the calling thread to sleep.
Another thread can execute a Synchronized
notify
Method on the monitor object. Before
terminating, this method notifies the Monitor
Condition on which the first thread is waiting.
release
If the Monitor Condition evaluates to true, it
automatic
resumption automatic
automatically re-acquires the Monitor Lock
acquisition
and resumes the suspended thread as well as
release
the suspended Synchronized Method.
Bemerkungen
Monitor Object:
Consequences
Benefits
Simple yet effective: Simplification of concurrency
control; simplification of scheduling method execution.
Bemerkungen
Liabilities
Limited scalability: clients can block.
Hard to extend: functionality and synchronization logic
are tightly coupled.
Nested Monitor Lockout Problem.
Dein Name – Dein Vortragstitel Pra 01 - S. 17
18. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Monitor Object: Example
class Message_Queue {
Message queues are often
public:
enum { MAX_MESSAGES = /* ... */; };
implemented as Monitor
Message_Queue (size_t max_messages = MAX_MESSAGES);
/* synchronized */ void put (const Message &msg);
/* synchronized */ Message get ();
Objects to ensure their thread-
/* synchronized */ bool empty () const;
/* synchronized */ bool full () const;
safe operation.
private:
void put_i (const Message &msg);
Message get_i ();
bool empty_i () const;
bool full_i () const; bool Message_Queue::empty () const {
Guard<Thread_Mutex> guard (monitor_lock_);
size_t message_count_; return empty_i ();
size_t max_messages_; }
mutable Thread_Mutex monitor_lock_;
Thread_Condition not_empty_; bool Message_Queue::full () const {
Thread_Condition not_full_; Guard<Thread_Mutex> guard (monitor_lock_);
} return full_i ();
}
void Message_Queue::put (const Message &msg) {
Guard<Thread_Mutex> guard (monitor_lock_);
while (full_i ())
not_full.wait ();
put_i (msg);
not_empty.notify ();
}
Message Message_Queue::get () {
Guard<Thread_Mutex> guard (monitor_lock_);
while (empty_i ())
not_empty.wait ();
Bemerkungen Message m = get_i ();
not_full.notify ();
return m;
}
Monitor Object: Known
Uses
ADAPTIVE Communication Environment:
ACE provides a communication gateway
application that uses Monitor Objects to
improve performance on multi-processors.
Bemerkungen
.NET, Java: the main synchronization
mechanism in .NET and Java is based on
Monitors.
Dein Name – Dein Vortragstitel Pra 01 - S. 18
19. Advanced Developers Conference
10.-11. Oktober 2004
Efficient Content Access
Bemerkungen
(I)
To achieve a high throughput and
a good quality of service, a
web server must access URLs
requested by clients efficiently.
Retrieving the URLs from the file
system for every access to them
introduces performance penalties,
however:
Some URLs are more frequently
accessed than others.
Individual clients often return to an
URL they already visited before.
Bemerkungen
Efficient Content Access
(II)
Virtual_
Introduce a virtual file system to
Filesystem
have the content of frequently
accessed URLs readily
accessible via Caching:
Thread_
A cache (Virtual_Filesystem)
Bemerkungen
shares Pool dispatches
join()
keeps URL content in memory once
leader()
* it got accessed and loaded from the
(de)
Event_
Reactor activates
file system for the first time. For
Handler
maintains owns
subsequent accesses, this content is
* *
* readily available
select() Handle
notifies
HTTP_Handlers first check the
HTTP_ HTTP_
cache for URL availability before
Acceptor Handler
they load it from the file system.
Dein Name – Dein Vortragstitel Pra 01 - S. 19
20. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Caching: Problem
Caching (POSA3) Clients
Problem: Repetitious
acquisition, initialization, 2: Send Logging
1: Establish
and release of resources Record
Connection
4: Send Logging
causes unnecessary 3: Establish This is a
logging
Record
record
Connection
performance overhead: 6: Send Logging
5: Establish
Record
Connection
The costs of acquisition, Expensive,
initialization, and release of Logging Server
if we must
create the
frequently used resources connection
should be minimized. each time!
Access to the resources
should be simple.
Bemerkungen
Output Media
Caching: Structure
Solution Structure: Instead of
releasing a resource after its usage,
temporarily store it in an in-memory
buffer:
Cache
Client
Resources represent entities that
Bemerkungen acquire()
application functionality uses to release()
execute its business logic, such as maintains
threads, network connections, file *
handles, memory, etc. Resource
A Cache keeps currently unused
resources of a specific type readily
available for subsequent use.
Clients use the Resources maintained
by the Cache to execute their own
functionality.
Dein Name – Dein Vortragstitel Pra 01 - S. 20
21. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Caching: Dynamics
Solution Dynamics: Create resources once and
re-cycle them often:
Client Cache
A Client requests a Resource from the Cache.
create
acquire
The Cache checks if the Resource is available
Resource
and creates one, if not
Resource
The Client uses the Resource.
use
The Client releases the resource by passing it
back to the Cache.
release
Resource
The Cache keeps the Resources for
subsequent uses.
The Client requests the Resource from the
acquire
Cache again.
Resource
The Cache returns the already existing
use
Resource.
The Client ‚re-uses‘ the Resource.
Bemerkungen
Caching: Consequences
Benefits
• Performance: Quick access to resources, minimized resource
acquisition and release costs.
• Predictability: Explicit control of resource usage possible.
Bemerkungen
Liabilities
• Cache maintenance overhead: If the cache is full, its ‚re-
organization‘ can cause performance penalties in accessing
and using resources.
Dein Name – Dein Vortragstitel Pra 01 - S. 21
22. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
Caching: Example
Web Browsers: Web Browsers like Netscape and
Internet Explorer use a cache to keep local
copies of frequently accessed documents.
Bemerkungen
Caching: Known Uses
Web Browsers: Internet Explorer
and Netscape cache frequently
accessed documents.
Web Servers: Apache and Jaws
cache frequently requested Bemerkungen
documents.
Object Request Brokers:
The ACE ORB (TAO) caches
unused network connections and
re-cycles them for new client
connections.
High-performance applications:
Almost every high-performance
software uses caches to speed-up
performance.
Dein Name – Dein Vortragstitel Pra 01 - S. 22
23. Advanced Developers Conference
10.-11. Oktober 2004
Bemerkungen
One Cache Only (I)
To achieve predictability
regarding resource Virtual_
One file
Filesystem
consumption, there should system only,
please!
only be one virtual file system
in the web server. Thread_
Pool
shares dispatches
join()
However, OO languages do not leader()
*
Event_
support an instance-controlled
(de)
Reactor
Handler
activates
object creation.
maintains owns
* *
*
select() Handle
notifies
HTTP_ HTTP_
Acceptor Handler
Bemerkungen
One Cache Only (II)
Virtual_
Ensure that the web server‘s
Filesystem
Virtual_Filesystem can be
class Virtual_Filesystem {
static Virtual_Filesystem *theInstance;
instantiated just once by making
Virtual_Filesystem () { /* ... */ };
it a Singleton:
public:
static Virtual_Filesystem *instance() {
Thread_
// Create file system, if necessary.
if (! theInstance)
Bemerkungen
A singleton
shares Pool dispatches
theInstance = new Virtual_Filesystem ;
// Return the unique file system instance
join()
(Virtual_Filesystem) keeps its
return theInstance;
}
leader()
}
* constructors and destructors private
(de)
Event_
// Static initialization of the singleton.
Reactor activates
Virtual_Filesystem *
so that only itself can create
Handler
Virtual_Filesystem ::theInstance = 0;
maintains owns
instances of itself.
* *
*
select() Handle
notifies
A class access method ensures that
only one instance of a singleton class
HTTP_ HTTP_
can be created and offers clients an
Acceptor Handler
access to this unique instance.
Note that we trade safety for
flexibility here!
Dein Name – Dein Vortragstitel Pra 01 - S. 23