networking and layered styles inf 123 – software architecture [email protected] 1
TRANSCRIPT
2
Reminder: Architectural styles
• Guidelines, recipes
• If you follow the constraints • You’ll gain the benefits
• Tools to understand and criticize architectures– Problem – solution– Why is it working that way?
3
Outline
• Distributed system• The OSI model• The layered style• Client-server• Pipe and filter
4
DISTRIBUTED SYSTEM
5
Host 1
Distributed system
• Collection of interacting components hosted on different networked machines
Component 1
Component 2
Component 3
Host 3
Component 4
Component 5
Host 2
Network interface of the OS
6
Examples of distributed systems
• WWW, DNS, TOR, …• Cell phones + towers• SETI@home• Online games• Peer to peer: Skype, Torrents
7
TOR
• The Onion Router
8
Properties of distributed systems
• Components run concurrently• Components fail independently• No global clock
• Debugging is a pain• Latency = duration between A.send and B.recv– Aka lag or delay– Speed of light: 50 ms to reach the other side of the world– Practically much slower: 40 ms across the US
9
Fallacies of distributed computing
• The network is reliable.• Latency is zero.• Bandwidth is infinite.• The network is secure.• Topology doesn't change.• There is one administrator.• Transport cost is zero.• The network is homogeneous.
10
11
12
THE OSI MODEL
13
OSI model
• Open Systems Interconnection, 1977• The backbone of today’s networking• A model (in the software architecture sense)– Only a subset of the decisions about networking– Multiple visualizations• Different ways to look at the OSI model
14
68 pages!
http://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-X.200-199407-I!!PDF-E&type=items
15
16
17
TCP, UDP
SSL, TLS
DNS, FTP, HTTP, SMTP
datagrams
packets
18
Message encapsulationlayer5-7
4
3
2
19
Web browser asking for a web page
HTTP
TCP
IP
HTTP
TCP
IP
Physical link (copper wire, optic fiber, …)
Web browser Web page
Datagrams
Bits
ElectronsPhotonsCarrier pigeons
Packets
Requests
Frames
7 application
1 physical
4 transport
3 network
20
Web browser asking for a web page
HTTP
TCP
IP
HTTP
TCP
IP
Physical link (copper wire, optic fiber, …)
Transparent!Web browser Web page
21
Dependencies
http://networking.ringofsaturn.com/Protocols/sevenlayer.php
22
TCP vs UDPTCP UDP
Connection Yes. 3-packet handshake (SYN/SYN-ACK/ACK)
Connectionless, Fire-and-forget
Reliability By re-sending None
Ordering Through the sequence number No. Packets can pass each other.
Congestion control
Slow start, congestion avoidance, fast retransmit
None
Fragmentation of big packets
Handled automatically and transparently.
You handle it. Don’t send big packets anyways!
Error checking Checksum, automatically re-send to fix.
Checksum only. You decide what to do with the mess.
Applications (level 7)
HTTP, FTP DNS, Voice over IP, FPS games, streaming
23
THE LAYERED STYLETurtles all the way down
24
Constraints
• Ordered layers (top – bottom)• Connectors: from the current layer to…– … The layer right below (strict layered style)– … Any layer below (non-strict)
• Each layer exposes an interface– Only to the layer above it
• No link within the same layer
Controller Input
Display
Game logic
Sound
25
Gains
• Bottom independent of top• Top independent of bottom– Unless bottom’s interface changes
• Clear dependences• Easy to test
Controller Input
Display
Game logic
Sound
26
Globus grid reference architecture
Mattmann et al, Unlocking the Grid , sunset.usc.edu/classes/cs578_2014b/week3b-supp.ppt
Collective
Application
Connectivity
Resource
Fabric
Profile
ProfileAttributes ResourceAttributes
ProfileElement
DDMResultParser
QueryEngine
ServerPOA
ServerImpl
DatabaseProfileHandler
Dataset
DatasetDisplayer
PageBean
XMLQuery QueryResultTransaction
QueryHeader
Configuration
ConfigurationBean
SearchBean QueryClient
Expression
Result
HTTPFormRecorder
Utilities
ChunkedProductInputStream
DatabaseProfileManager
CORBA_Archive_ServiceHolder
ProfileServiceAdaptor
ProductClient
ProductServiceAdaptor
QueryServicePOA
ProfileClient
QueryServiceHolder
ProductServicePOA
ExecServerProfileServicePOA
CORBA_Archive_ServicePOA
RMIQueryServiceFactory
27
Derivatives
• Tiered style– Layered style for physical deployment
• Client-server– Two layers
• C2 style– Components – connectors – components – … – Aware of layers above, unaware of layers below– Requests go up, notifications go down
28
CLIENT-SERVER
29
Client-server
client client client
server
30
Constraints
• Clients initiate the communication• Communication usually over the network• Server has the main functionality• No client-to-client communication
31
Client-server: pros and cons
• Pros– Computation and data collocated– Server = single authority, trusted– Ignore bad clients without affecting good clients
• Cons– Server = single point of failure– Server can be a bottleneck
32
Fat client
• Most of the functionality or data is client-side• Server for backups, inter-client sync, patches
• Mitigate single-point of failure• Offload some computations to clients– More clients per server
• Most games• Tablet and phone apps• Gmail (“you’ve been disconnected – try now”)
33
Thin client
• Most of the functionality and data is server-side• Client for user input, screen, and audio
• When clients are computationally weak• Reduce the cost of the overall infrastructure
• Game streaming: Onlive, Twitch TV Pokemon • Remote desktop, X terminal, library computers
34
“Subverting” the style
• Using the server as a gateway between peers
• C1 sends to server– {‘from’:C1’, ‘to’: ‘C2’, ‘msg’:’hi’}
• Server forwards blindly to all clients• C1 receives the message and discards it• C2 receives the message and prints it
35
“Subverting” the style
Clients send client list
def on_msg(msg): clients = msg[‘to’] txt = msg[‘txt’] for c in clients: c.send(txt)
Server holds client listclients = []def on_msg(msg):
txt = msg[‘txt’] for c in clients: c.send(txt)
36
“Subverting” the style
endpoints = {}def on_msg(msg): clients = endpoints(msg[‘to’])
txt = msg[‘txt’] for c in clients: c.send(txt)
def on_open(self): name = randint(0,10**9) endpoints[name] = self
clients = []def on_msg(msg):
txt = msg[‘txt’] for c in clients: c.send(txt)
def on_open(self): clients.append(self)
37
“Subverting” the style
• Using the server as a gateway between peers
• Why is it bad?– Messaging functionality replicated in all clients– No messaging functionality in the server– The server is “obeying” the clients
38
Server-side with TCP
• Listen for incoming connections– Create a socket when a client connects– Each socket is administered by a handler– So: each handler is in charge of a client– Use handler to send a message or to close the
connection with that client• Poll connections to receive messages– Kernel vs user space … – Kernel notifies a handler when its socket is readable– Poll/select = Chipotle, epoll = Blaze Pizza
39
Client-side with TCP
• Initiate the connection to the server– Create a socket (handler for convenience)– Use handler to send a message or to close the
connection with that client• Poll the socket to receive messages– Same as server
40
PIPE AND FILTERNOT a layered architecture
41
Assembly line
42
Constraints
• Each task runs in its own process• Stream of data passed between tasks– Input/output format
input simulation/logic display
43
Gains
• Modularity between tasks• Concurrency and speed-ups• Reusable components – Expected input and output formats
44
Beware
• The data can only go one way
• Congestion may cause starvation
45
More reading
• http://msdn.microsoft.com/en-us/library/ff963548.aspx