Distributed System
Distributed System
(CS504)
Syllabus
14
2. Examples of Distributed Systems
Internet/World-Wide Web
15
2.1 Local Area Network
Local area
Web server network
email server
print
File server
other servers
the rest of
the Internet
router/firewall
16
2.2 Database Management System
17
2.3 Automatic Teller Machine Network
18
2.4 Internet
intranet
ISP
backbone
satellite link
desktop computer:
server:
network link:
19
2.4.1 World-Wide-Web
20
3. Common Characteristics
21
3.1 Heterogeneity
Variety and differences in
Networks(IP4 & IP6)
Computer hardware (32 bit and 63 bit)
Operating systems(windows and linux)
Programming languages(c and java)
Implementations by different developers( biswajit & rajib)
Middleware as software layers to provide a programming abstraction as well
as masking the heterogeneity of the underlying networks, hardware, OS, and
programming languages (e.g., CORBA).
Mobile Code to refer to code that can be sent from one computer to another
and run at the destination (e.g., Java applets and Java virtual machine).
22
3.2 Openness
Openness is concerned with extensions and improvements of
distributed systems.
23
3.3 Security
In
a distributed system, clients send requests to access data
managed by servers, resources in the networks:
Doctors requesting records from hospitals
Users purchase products through electronic commerce
Security is required for:
Concealing the contents of messages: security and privacy
Identifying a remote user or other agent correctly (authentication)
New challenges:
Denial of service attack
Security of mobile code
24
3.4 Scalability
Adaptation of distributed systems to
accommodate more users
respond faster (this is the hard one)
25
3.5 Failure Handling (Fault Tolerance)
26
3.6 Concurrency
Components in distributed systems are executed in concurrent
processes.
Components access and update shared resources (e.g. variables,
databases, device drivers).
Integrity of the system may be violated if concurrent updates
are not coordinated.
Lost updates
Inconsistent analysis
27
3.7 Transparency
Distributedsystems should be perceived by users and
application programmers as a whole rather than as a collection
of cooperating components.
Transparency has different aspects.
Theserepresent various properties that distributed systems
should have.
28
Distributed Systems: Hardware Concepts
Multiprocessors
Multicomputers
Networks of Computers
Multiprocessors and
Multicomputers
Distinguishing features:
•Private versus shared memory
•Bus versus switched interconnection
Distributed Systems: Software Concepts
Distributed operating system
Network operating system
Middleware
Distributed Operating System
Some characteristics:
_ OS on each computer knows about the other computers
_ OS on different computers generally the same
_ Services are generally (transparently) distributed across
computers
Network Operating System
Some characteristics:
_ Each computer has its own operating system with networking facilities
_ Computers work independently (i.e., they may even have different operating
systems)
_ Services are tied to individual nodes (ftp, telnet, WWW)
_ Highly file oriented (basically, processors share only files)
Distributed System (Middleware)
Some characteristics:
_ OS on each computer need not know about the other computers
_ OS on different computers need not generally be the same
_ Services are generally (transparently) distributed across computers
Need for Middleware
Concurrency
No global clock
Independent failures
concurrency
In a network of computers, concurrent program execution
is the norm. I can do my work on my computer while you
do your work on yours, sharing resources such as web
pages or files when necessary.
Ticket Producer p=4 Ticket consumer
p=p+1 p=p-1
[ r=p; [r=p;
r=r+1; p=p-1;
time out time out
p=r] p=r]
40
p=3
No global clock
But it turns out that there are limits to the accuracy with which the
computers in a network can synchronize their clocks – there is no single
global notion of the correct time.
42
Independent failures
Faults in the network result in the isolation of the computers that are
connected to it, but that doesn’t mean that they stop running. In fact,
the programs
43
TRENDS IN DISTRIBUTED SYSTEMS
Distributed systems are undergoing a period of significant change
and this can be traced back to a number of influential trends:
44
The delay between the start of a message’s
transmission from one process and the beginning of
its receipt by another is referred to as latency.
result result
Server
Client
Key:
Process: Computer:
45
Computer clocks and timing events
This is because computer clocks drift from perfect time and, more
importantly, their drift rates differ from one another.
46
Client invocation invocation Server
result result
Server
Client
Key:
Process: Computer:
47
Two variants of the interaction model
48
Synchronous distributed systems
• The time to execute each step of a process has known lower and
upper bounds.
• Each process has a local clock whose drift rate from real time
has a known bound.
49
Asynchronous distributed systems
51
Event ordering
In real time, X’s message is sent first, and Y reads it and replies;
Z then reads both X’s message and Y’s reply and sends another
reply, which references both X’s and Y’s messages.
But due to the independent delays in message delivery, the
messages may be delivered as shown in the following figure and
some users may view these two messages in the wrong order.
52
Failure model
The failure model defines the ways in which failure may occur in
order to provide an understanding of the effects of
failures.
54
Omission failures
55
Communication omission failures: Consider the communication
primitives send and receive. A process p performs a send by
inserting the message m in its outgoing message buffer. The
communication channel transports m to q’s incoming message
buffer. Process q performs a receive by taking m from its incoming
message buffer and delivering it. The outgoing and incoming
message buffers are typically provided by the operating system.
56
Arbitrary failures • The term arbitrary or Byzantine failure is
used to describe the worst possible failure semantics, in which
any type of error may occur. For example, a process may set
wrong values in its data items, or it may return a wrong value in
response to an invocation.
57
Timing failures • Timing failures are applicable in synchronous
distributed systems where time limits are set on process
execution time, message delivery time and clock drift rate.
58
Masking failures • Each component in a distributed system is
generally constructed from a collection of other components.
It is possible to construct reliable services from components that
exhibit failures.
59
CLOCKS, EVENTS AND PROCESS STATES
Its state may also include the values of any objects in its local
operating system environment that it affects, such as files.
61
software clock
The operating system reads the node’s hardware clock value, Hit ,
scales it and adds an offset so as to produce a software clock
Cit = Hit + that approximately measures real, physical time t for
process pi .
62
Synchronizing physical clocks
65
Happened before is a partial ordering
Happened before & causal order
• Happened before == could have caused/
influenced
• Preserves causal relations
• Implies a partial order
– Implies time ordering between certain
pairs of events
– Does not imply anything about ordering
between concurrent events
68
Logical clocks
• Idea: Use a counter at each process
• Increment after each event
• Can also increment when there are no
events
– Eg. A clock
• An actual clock can be thought of as such
an event counter
• It counts the states of the process
• Each event has an associated time: The
count of the state when the event happened
69
Lamport clocks
• Keep a logical clock (counter)
• Send it with every message
• On receiving a message, set own clock to
max({own counter, message counter}) + 1
• For any event e, write c(e) for the logical
time
• Property:
– If a⟶b, then c(a) < c(b)
– If a || b, then no guarantees
70
Concurrency and Lamport clocks
• If e1⟶e2
– Then no Lamport clock C exists with
C(e1)==C(e2)
72
The Purpose of Lamport Clocks
• If a⟶b, then c(a) < c(b)
• If we order all events by their Lamport
clock times
– We get a partial order, since some events have
same time
– The partial order satisfies “causal relations”
• Suppose there are events in different machines
– Transactions, money in/out, file read, write,
copy
• An ordering of events that guarantees
preserving causality
73
Total order from Lamport clocks
• If event e occurs in process j at time C(e)
– Give it a time (C(e), j)
– Order events by (C, process id)
– For events e1 in process i, e2 in process j:
• If C(e1)<C(e2), then e1<e2
• Else if C(e1)==C(e2) and i<j, then e1<e2
• Leslie Lamport. Time, clocks and ordering
of events in a distributed system.
74
Vector Clocks
• We want a clock such that:
– If a⟶b, then c(a) < c(b)
– AND
– If c(a) < c(b), then a⟶b
75
Vector Clocks
• Each process i maintains a vector V i
• V i has n elements
– keeps clock V i [j] for every other process j
– On every local event: V i [i] =V i [i]+1
– On sending a message, i sends entire V i
– On receiving a message at process j:
• Takes max element by element
• V j [k] = max(V j [k], V i [k]), for k = 1,2,...,n
• And adds 1 to V j [j]
76
77
Comparing Timestamps
• V = V’ iff V[i] == V’[i] for i=1,2,...,n
• V < V’ iff V[i] < V’[i] for i=1,2,...,n
81
Logical Clocks
• There is no way to have perfect knowledge
on ordering of events
82
Distributed Snapshots
• Take a “snapshot” of a system
• E.g. for backup: If system fails, it can start
up from a meaningful state
• Problem:
– Imagine a sky filled with birds. The sky is
too large to cover in a single picture.
– We want to take multiple pictures that are
consistent in a suitable sense
• Eg. We can correctly count the number of
birds from the snapshot
83
Distributed Snapshots
• Global state:
– State of all processes and communication
channels
• Consistent cuts:
– A set of states of all processes is a consistent
cut if:
– For any states s, t in the cut, s||t
• If a⟶b, then the following is not allowed:
– b is before the cut, a is after the cut
84
Distributed Snapshot Algorithm
• Ask each process to record its state
• The set of states must be a consistent cut
• Assumptions:
– Communication channels are FIFO
– Processes communicate only with neighbors
– (We assume for now that everyone is
neighbor of everyone)
– Processes do not fail
86
Global Snapshot
Chandy and Lamport Algorithm
• One process initiates snapshot and sends a
marker
• Marker is the boundary between “before”
and “after” snapshot
87
Global snapshot: Chandy and Lamport algorithm
• Marker send rule (Process i)
– Process i records its state
– On every outgoing channel where a marker has not been sent:
• i sends a marker on the channel
• before sending any other message
• Marker receive rule
(Process i receives marker on channel C)
– If i has not received the marker before
• Record state of I
• Record state of C as empty
• Follow marker send rule
– Else:
• Record the state of C as the set of messages received on C since
recording i’s state and before receiving marker on C
• Algorithm stops when all processes have received
88
90
Non-stable predicates
• Possibly B:
– B could have happened
• Definitely B:
– B definitely happened
• How can we check for definitely B and
possibly B?
91
Collecting global states
• Each process notes its state & vector
timestamp
– Sends it to a server for recording
– Note: we do not need to save every time a
state changes: only when it affects the
predicates to be checked
• Assuming we know what predicates will be
checked
• The server looks at these and tries to figure
out if predicate B was possibly or definitely
true 92
The circles are ‘states’, and bars are ‘events’
–We are concerned with which pairs of states
form consistent cuts
Mutual exclusion: Concurrent access of processes
to a shared resource or data is executed in
mutually exclusive manner. ... In a distributed
system, shared variables (semaphores) or a local
kernel cannot be used to implement mutual
exclusion. Message passing is the sole means for
implementing distributed mutual exclusion.
Remote Procedure Call
Remote Procedure Call
• Remote Procedure Call (RPC) is a protocol that allows
programs to call procedures located on other machines.
• RPC uses the client/server model. The requesting program is a
client and the service-providing program is the server.
• The client stub acts as a proxy for the remote procedure.
• The server stub acts as a correspondent to the client stub.
Client and Server Stubs
2-8
2-14
2-15