Professional Documents
Culture Documents
Design Principles 4
Design Principles 4
MESSAGE-PASSING
MIDDLEWARE Design Guidelines
May 25, 2003 OS KERNEL OS KERNEL
NETWORK NETWORK
PROTOCOLS
– Motivation
PROTOCOLS
NETWORK NETWORK – Common Design Mistakes
INTERFACE INTERFACE
NETWORK
– Design Rules
Motivation: Goals of the Design Phase (1/2) Motivation: Goals of the Design Phase (2/2)
SUPER
SUPER
VISOR SUPER Decompose system into Specify component interfaces
VISOR VISOR
STREAM
components
DOWNSTREAM
Head
UPSTREAM
– Interfaces should be well-defined
– i.e., identify the software Facilitates component testing
CCM Session Router
Stream Module architecture and team communication
Event Filter
Module
Determine relationships open()=0 Describe component functionality
close()=0
MIB Event Analyzer
between components put()=0
Module svc()=0 – e.g., informally or formally
– e.g., identify component
ACE Switch Adapter
Module Identify opportunities for systematic
RUN-TIME dependencies
reuse
TELECOM Determine intercomponent STREAM
SWITCHES EVENT Tail – Both top-down and bottom-up
SERVER communication mechanisms
– e.g., globals, function calls,
shared memory, IPC/RPC
2 3
specification and apply above process to each
– Make decisions that apply to whole program
Design Principles
implementation assignments
– What to how
– hidden in a component
1. Preliminary Design
family first
general steps:
2. Detailed Design
– Specify each subsystem
change
Design Principles
– Further decomposed subsystems, if necessary
are:
4
5
Design Principles Design Principles
6 7
Design Principles Design Principles
Context: A large and complex production web server Decomposition handles complexity by splitting large problems into
smaller problems
Problems:
This “divide and conquer” concept is common to all life-cycle
– Designing the web server as a large monolithic entity is tedious processes and design techniques
and error-prone
– Web server developers must work concurrently to improve Basic methodology:
productivity 1. Select a piece of the problem (initially, the whole problem)
– Portability and resuability are important quality factors 2. Determine the components in this piece using a design paradigm,
e.g., functional, structured, object-oriented, generic, etc.
3. Describe the components interactions
4. Repeat steps 1 through 3 until some termination criteria is met
– e.g., customer is satisfied, run out of time/money, etc. ;-)
8 9
framework filesystem
1. Don’t design components to correspond to execution steps
– High-performance
Asynchronous completion token Tilde ~ – Flexible concurrency, Since design decisions usually transcend execution time
expander
Component configurator
/home/...
Protocol
Event dispatcher demuxing, and caching 2. Decompose so as to limit the effect of any one design decision on
Acceptor
handler
Protocol
mechanisms the rest of the system
filter
– Uses frameworks based
Pipes and filters
on ACE Anything that permeates the system will be expensive to change
Adapter
Concurrency
3. Components should be specified by all information needed to use
State
10 11
Design Principles Design Principles
12 13
e.g., loops, iterators, frameworks, and multitasking
Design Principles
ACE Information Hiding
EVENT
LOOP
e.g., ADT classes and component models
Streams
Common Types of Abstraction
EVENT
LOOP
LOOP
FUNCTIONALITY
APPLICATION-
interfaces
CALLBACKS
1. Procedural abstraction
LOCAL
CLASSES
CLASSES
ADT
IPC
14
15
16
Design Principles
# rd_ptr_ : size_t
# wr_ptr_ : size_t
Design Principles
# cont_ : ACE_Message_Block *
# next_ : ACE_Message_Block *
Formats
# prev_ : ACE_Message_Block *
# data_block_ : ACE_Data_Block *
Algorithms
– Machine
data types
+ init (size : size_t) : int
+ msg_type (type : ACE_Message_Type) ACE_Data_Block
+ msg_type () : ACE_Message_Type
byte-ordering,
+ msg_priority (prio : u_long) # base_ : char *
character codes
+ clone () : ACE_Message_Block *
+ duplicate () : ACE_Message_Block *
– i.e., using abstract
Data representations
+ release () : ACE_Message_Block *
dependencies, e.g.,
+ set_flags (flags : u_long) : u_long
searching techniques
+ clr_flags (flags : u_long) : u_long
+ copy (buf : const char *,n : size_t) : int
+ rd_ptr (n : size_t)
+ rd_ptr () : char *
+ wr_ptr (n : size_t)
+ wr_ptr () : char *
+ length () : size_t
+ total_length () : size_t
+ size () : size_t
Class characteristics
protocols
Hide messaging implementations from clients
ACE_Message ACE_Message ACE_Message
_Block _Block _Block
memory paging
ACE_Data
_Block ACE_Data_Block
PAYLOAD reference_count() = 2
18
– Same policy can be implemented by
– e.g., ordering of low-level operations,
17
Design Principles
next()
prev()
cont()
head_
SYNCH_STRATEGY
ACE_Message_Queue
Block
Queue
# head_ : ACE_Message_Block *
Message
Message
Design Principles
# tail_ : ACE_Message_Block *
# high_water_mark_ : size_t
SYNCH
# low_water_mark_ : size_t
Data_Block
STRATEGY
+ flush () : int
next()
prev()
cont()
+ is_empty () : int
Block
+ is_full () : int
Message
Data_Block
Block
+ pulse () : int
+ state () : int
transparently
Class characteristics
– Efficiently handles
strategized!
allocators, and reference
arbitrarily-large message
Information Hiding Example: Message Queueing
A Message_Queue is a list of
19
Design Principles Design Principles
20 21
UPSTREAM
– Imports EVENT SINK EVENT SOURCE
Multiplexor
Services requested from STREAM
open()=0 – i.e., read and write Tasks
close()=0
other components, e.g., Define components that Tail put()=0
svc()=0 Each Task contains a
receptacles and event sinks provide multiple interfaces NETWORK INTERFACE
22 23
Design Principles Design Principles
24 25
Principles for Ensuring Modular Designs Challenge 4: “Future Proofing” the Web Server
Language support for components Explicit Interfaces
Context: A production web server whose requirements will change
Components should correspond to Whenever two over time
syntactic units in the language components A and B
communicate, this must Problems:
Few interfaces
be obvious from the text – Certain design aspects seem constant until they are examined in
Every component should of A or B or both the overall structure of an application
communicate with as few others as – Developers must be able to easily refactor the web server to
Information Hiding
possible account for new sources of variation
All information about a
Small interfaces (weak coupling)
component should be
If any two components communicate private unless it’s
at all, they should exchange as little specifically declared
information as possible public
26 27
Design Principles Design Principles
when reopening a component triggers many changes both open and closed
28 29
PRESENTATION
PRESENTATION
APPLICATION
APPLICATION
Systems
TRANSPORT
LINK
TRANSPORT
DATA LINK
NETWORK
PHYSICAL
NETWORK
PHYSICAL
– Modeled after hardware instruction set
HOST B
SESSION
SESSION
A virtual machine layer provides a set of
A virtual machine provides an extended
DATA
Context: A production web server whose requirements will change
GATEWAY B
LINK
DATA LINK
NETWORK
PHYSICAL
Problems:
NETWORK
PHYSICAL
DATA
– To enhance reuse and flexibility, it is often necessary to
PHYSICAL
“software instruction set”
VIRTUAL
LINK
LINK
decompose a web server into smaller, more manageable units
GATEWAY A
LINK
that are layered in order to
DATA LINK
NETWORK
PHYSICAL
NETWORK
PHYSICAL
Enhance reuse, e.g., multiple higher-layer services can share
of similar systems
DATA
lower-layer services
Transparently and incrementally enhancement functionality
PRESENTATION
Improve performance by allowing the selective omission of
PRESENTATION
APPLICATION
APPLICATION
TRANSPORT
LINK
TRANSPORT
DATA LINK
NETWORK
PHYSICAL
NETWORK
PHYSICAL
HOST A
SESSION
SESSION
Design Principles
DATA
Improve implementations, testing, and maintenance
31
30
Abstracts away from details of the underlying OS
Design Principles
masking signals
LOGGING NAME TIME
signal handlers
SERVER SERVER SERVER
signal stack
SERVICE CORBA
FRAMEWORK ACCEPTOR CONNECTOR
HANDLER HANDLER
signals
LAYER
Computer architectures
FACADE
restartable instructions
URATOR
interrupt/trap handlers
PROACTOR
LAYER SYNCH SPIPE SOCK SAP/ FIFO MEM FILE
Hardware Machine
WRAPPERS SAP TLI SAP SAP MAP SAP
blocking interrupts
Operating systems
OS ADAPTATION LAYER
C PROCESSES/ SELECT/
interrupts/traps
WIN32 NAMED SOCKETS/ UNIX DYNAMIC SHARED FILE SYS
interrupt stack
instruction set
PIPES & UNIX
APIS THREADS STREAM PIPES TLI FIFOS IO COMP LINKING MEMORY APIS
e.g., Linux
Design Principles
PROCESS/THREAD COMMUNICATION VIRTUAL MEMORY & FILE
SUBSYSTEM SUBSYSTEM SUBSYSTEM
www.cs.wustl.edu/ schmidt/ACE.html
33
32
34 35
38
Design Principles
Design Principles
Class X
Class Y
REQUEST PROCESSING LAYER
svc_run
svc_run svc_run
A uses relation does not necessarily yield a
36
correctly
Uses relationships can exist between classes, ACE_SOCK_IO ACE_SOCK
Acceptor-
Reactor Proactor
Connector
ACE_SOCK_Stream ACE_SOCK_Connector
Service
Streams Task
Configurator
39 37
Design Principles
The is-composed-of relationship shows how the
The Uses Relation (3/3) The following diagram illustrates some of the
Acceptor
Acceptor
The Is-Composed-Of Relation
HTTP
Sock
X is-composed-of fxig if X is a group of
A hierarchy in the uses relation is essential for designing reusable
system is broken down in components
Handler
However, certain software systems require controlled violation of a
Stream
HTTP
Sock
uses hierarchy
Reactor
– e.g., asynchronous communication protocols, OO callbacks in
frameworks, signal handling, etc.
Handler
Stream
HTTP
– Upcalls are one way to control these non-hierarchical
Sock
dependencies
Rule of thumb:
Design Principles
Handler
– Start with an invocation hierarchy and eliminate those invocations
Stream
purpose
HTTP
Sock
(i.e., “calls”) that are not uses relationships
41
40
HTTP_1_1
– e.g., an HTTP_1_0_Handler Is-A
Handler
via some higher-level component or record structuring technique
ACE_Event_Handler
The Is-A Relation
handle_input()
get_handle()
– component (an entity that hides one or more “secrets”)
– a subprogram (a code unit)
HTTP_1_0
Components and levels need not be identical, as a component may
Handler
appear in several levels of a uses hierarchy
Design Principles
Y.
43
42
46
Design Principles
Design Principles
This “client” relationship is associated with
object-oriented design and programming
languages that possess classes and objects
class X possesses a Has-A relationship with
class Y if instances of class X contain an
instance(s) of class Y.
Design Principles
in args
Design Principles
Problems:
Memento
IDL
SKELETON
REAL-TIME Tilde
ORB RUN-TIME OBJECT Asynchronous Completon Token Expander ~
IDL SCHEDULER
STUBS ADAPTER
/home/...
Protocol Event Dispatcher
REAL-TIME ORB CORE Handler
Acceptor
Protocol
IOP IOP
Service Configurator
Filter
PLUGGABLE PLUGGABLE
ORB & XPORT ORB & XPORT
PROTOCOLS PROTOCOLS
Service Configurator
OS KERNEL ACE components OS KERNEL
HIGH-SPEED HIGH-SPEED
NETWORK INTERFACE NETWORK INTERFACE Framework Framework
(1) THE ACE ORB (TAO) (2) The JAWS Web Server Framework
Software
47
Design Principles
Spiral Model
Backward compatibility
Rapid Application Development
– Build a prototype
– Ship it :-)
routines
Design Principles
48
49
50 51
Design Principles Design Principles
52 53
54 55
Design Principles Design Principles
56 57
58 59
Design Principles Design Principles
60 61
62 63
Design Principles Design Principles
64 65
– Clearly, this is the most frequently violated rule!!! ;-) Design is not simply the act of drawing a picture using a CASE tool
or using graphical UML notation!!!
– Design is a fundamentally creative activity
66 67