Lecture #23: Distributed Systems
Download
Report
Transcript Lecture #23: Distributed Systems
Lecture 23
Chapter 16/18:
Distributed Systems
Principles of Computer Operating Systems
Modified from Silberschatz, Galvin and Gagne
Chapter 16: Distributed System Structures
Motivation
Types of Network-Based Operating Systems
Network Structure
Network Topology
Communication Structure
Communication Protocols
Robustness
Design Issues
An Example: Networking
Principles of Computer Operating Systems
2
Chapter Objectives
To provide a high-level overview of distributed systems and the
networks that interconnect them
To discuss the general structure of distributed operating systems
Principles of Computer Operating Systems
3
Motivation
Distributed system is collection of loosely coupled processors
interconnected by a communications network
Processors variously called nodes, computers, machines, hosts
Site is location of the processor
Reasons for distributed systems
Resource sharing
sharing and printing files at remote sites
processing information in a distributed database
using remote specialized hardware devices
Computation speedup – load sharing
Reliability – detect and recover from site failure, function transfer,
reintegrate failed site
Communication – message passing
Principles of Computer Operating Systems
4
A Distributed System
Principles of Computer Operating Systems
5
Network-Operating Systems
Users are aware of multiplicity of machines.
Access to resources of various machines is done explicitly by:
Remote logging into the appropriate remote machine (telnet, ssh)
Remote Desktop (Microsoft Windows)
Transferring data from remote machines to local machines, via the
File Transfer Protocol (FTP) mechanism
Principles of Computer Operating Systems
6
Distributed-Operating Systems
Users not aware of multiplicity of machines
Access to remote resources similar to access to local resources
Data Migration
transfer data by transferring entire file, or
transferring only those portions of the file necessary for the
immediate task
Computation Migration
transfer the computation, rather than the data, across the system
Principles of Computer Operating Systems
7
Distributed-Operating Systems (Cont.)
Process Migration
execute an entire process, or parts of it, at different sites
Load balancing
–
Computation speedup
–
process execution may require specialized processor
Software preference
–
subprocesses can run concurrently on different sites
Hardware preference
–
distribute processes across network to even the workload
required software may be available at only a particular site
Data access
–
run process remotely, rather than transfer all data locally
Principles of Computer Operating Systems
8
Network Structure
Local-Area Network (LAN) – designed to cover small geographical area.
Multiaccess bus, ring, or star network
Speed 10 – 100 megabits/second
Broadcast is fast and cheap
Nodes:
usually workstations and/or personal computers
a few mainframes
Principles of Computer Operating Systems
9
Network Types (Cont.)
Wide-Area Network (WAN) – links geographically separated sites
Point-to-point connections over long-haul lines
often leased from a phone company
Speed 1.544 – 45 megbits/second
Broadcast usually requires multiple messages
Nodes:
usually a high percentage of mainframes
Principles of Computer Operating Systems
10
Network Topology
Sites in the system can be physically connected in a variety of ways;
They are compared with respect to the following criteria:
Installation cost
–
Communication cost
–
How expensive is it to link the various sites in the system?
How long does it take to send a message from site A to site B?
Reliability
–
If a link or a site in the system fails, can the remaining sites still
communicate with each other?
The various topologies are depicted as graphs whose nodes correspond to
sites
An edge from node A to node B corresponds to a direct connection
between the two sites
Principles of Computer Operating Systems
11
Network Topology
Principles of Computer Operating Systems
12
Communication Structure
The design of a communication network must address four basic
issues:
Naming and name resolution
How do two processes locate each other to communicate?
Routing strategies
How are messages sent through the network?
Connection strategies
How do two processes send a sequence of messages?
Contention
The network is a shared resource, so how do we resolve
conflicting demands for its use?
Principles of Computer Operating Systems
13
Naming and Name Resolution
Name systems in the network
Address messages with the process-id
Identify processes on remote systems by
<host-name, identifier> pair
Domain name service (DNS)
specifies the naming structure of the hosts, as well as name to
address resolution (Internet)
Principles of Computer Operating Systems
14
Routing Strategies
Fixed routing: A path from A to B is specified in advance
Path changes only if a hardware failure disables it
Since the shortest path is usually chosen, communication costs are
minimized
Fixed routing cannot adapt to load changes
Ensures that messages will be delivered in the order in which they
were sent
Virtual circuit: A path from A to B is fixed for the duration of one session
Different sessions involving messages from A to B may have different
paths
Partial remedy to adapting to load changes
Ensures that messages will be delivered in the order in which they
were sent
Principles of Computer Operating Systems
15
Routing Strategies (Cont.)
Dynamic routing: The path used to send a message form site A to site
B is chosen only when a message is sent
Usually a site sends a message to another site on the link least used
at that particular time
Adapts to load changes by avoiding routing messages on heavily
used path
Messages may arrive out of order
This problem can be remedied by appending a sequence number
to each message
Principles of Computer Operating Systems
16
Connection Strategies
Circuit switching: A permanent physical link is established for the duration
of the communication
i.e., telephone system
Message switching: A temporary link is established for the duration of one
message transfer
i.e., post-office mailing system
Packet switching: Messages of variable length are divided into fixed-
length packets which are sent to the destination
Each packet may take a different path through the network
The packets must be reassembled into messages as they arrive
Circuit switching requires setup time, but incurs less overhead for shipping
each message, and may waste network bandwidth
Message and packet switching require less setup time, but incur more
overhead per message
Principles of Computer Operating Systems
17
Contention
Several sites may want to transmit information over a link
simultaneously. Techniques to avoid repeated collisions include:
CSMA/CD - Carrier sense with multiple access (CSMA) with
collision detection (CD)
A site determines whether another message is currently being
transmitted over that link.
If two or more sites begin transmitting at exactly the same time,
then they will register a CD and will stop transmitting
When the system is very busy, many collisions may occur, and
thus performance may be degraded
CSMA/CD is used successfully in the Ethernet system
the most common network system
Principles of Computer Operating Systems
18
Contention (Cont.)
Token passing: A unique message type, known as a token, continuously
circulates in the system (usually a ring structure)
A site that wants to transmit information must wait until the token
arrives
When the site completes its round of message passing, it retransmits
the token
A token-passing scheme is used by some IBM and HP/Apollo
systems
Message slots: A number of fixed-length message slots continuously
circulate in the system (usually a ring structure)
Since a slot can contain only fixed-sized messages, a single logical
message may have to be broken down into a number of smaller
packets, each of which is sent in a separate slot
This scheme has been adopted in the experimental Cambridge Digital
Communication Ring
Principles of Computer Operating Systems
19
Communication Via ISO Network Model
Principles of Computer Operating Systems
20
Communication Protocol
The communication network is partitioned into the following
multiple layers:
Physical layer: handles the mechanical and electrical details of
the physical transmission of a bit stream
Data-link layer: handles the frames, or fixed-length parts of
packets, including any error detection and recovery that occurred in
the physical layer
Network layer: provides connections and routes packets in the
communication network, including handling the address of outgoing
packets, decoding the address of incoming packets, and
maintaining routing information for proper response to changing
load levels
Principles of Computer Operating Systems
21
Communication Protocol (Cont.)
Transport layer: responsible for low-level network access and for
message transfer between clients, including partitioning messages into
packets, maintaining packet order, controlling flow, and generating
physical addresses
Session layer: implements sessions, or process-to-process
communications protocols
Presentation layer: resolves the differences in formats among the
various sites in the network, including character conversions, and half
duplex/full duplex (echoing)
Application layer: interacts directly with the users’ deals with file
transfer, remote-login protocols and electronic mail, as well as schemas
for distributed databases
Principles of Computer Operating Systems
22
The ISO Protocol Layer
Principles of Computer Operating Systems
23
The TCP/IP Protocol Layers
Principles of Computer Operating Systems
24
Design Issues
Transparency
the distributed system should appear as a conventional, centralized
system to the user
Fault tolerance
the distributed system should continue to function in the face of failure
Scalability
as demands increase, the system should easily accept the addition of
new resources to accommodate the increased demand
Clusters
a collection of semi-autonomous machines that acts as a single
system
Principles of Computer Operating Systems
25
Principles of Computer Operating Systems
26
Chapter 18 Distributed Coordination
Event Ordering
Mutual Exclusion
Atomicity
Concurrency Control
Deadlock Handling
Election Algorithms
Reaching Agreement
Principles of Computer Operating Systems
27
Chapter Objectives
To describe various methods for achieving mutual exclusion in a
distributed system
To explain how atomic transactions can be implemented in a distributed
system
To show how some of the concurrency-control schemes can be
modified for use in a distributed environment
To present schemes for handling deadlock prevention, deadlock
avoidance, and deadlock detection in a distributed system
Principles of Computer Operating Systems
28
Event Ordering
Happened-before relation (denoted by )
If A and B are events in the same process, and A was executed before
B, then A B
If A is the event of sending a message by one process and B is the
event of receiving that message by another process, then A B
If A B and B C then A C
Principles of Computer Operating Systems
29
Implementation of
Associate a timestamp with each system event
Require that for every pair of events A and B, if A B, then the timestamp of
A is less than the timestamp of B
Within each process Pi a logical clock, LCi is associated
The logical clock can be implemented as a simple counter that is
incremented between any two successive events executed within a process
Logical clock is monotonically increasing
A process advances its logical clock when it receives a message whose
timestamp is greater than the current value of its logical clock
If the timestamps of two events A and B are the same, then the events are
concurrent
We may use the process identity numbers to break ties and to create a total
ordering
Principles of Computer Operating Systems
30
Distributed Mutual Exclusion (DME)
Assumptions
The system consists of n processes;
Each process Pi resides at a different processor
Each process has a critical section that requires mutual exclusion
Requirement
If Pi is executing in its critical section, then no other process Pj is
executing in its critical section
We present two algorithms to ensure the mutual exclusion execution of
processes in their critical sections
Principles of Computer Operating Systems
31
DME: Centralized Approach
One of the processes in the system is chosen to coordinate the entry to
the critical section
A process that wants to enter its critical section sends a request
message to the coordinator
The coordinator decides which process can enter the critical section
next, and its sends that process a reply message
When the process receives a reply message from the coordinator,
it enters its critical section
After exiting its critical section,
the process sends a release message to the coordinator and
proceeds with its execution
This scheme requires three messages per critical-section entry:
request
reply
release
Principles of Computer Operating Systems
32
DME: Fully Distributed Approach
When process Pi wants to enter its critical section, it generates a new
timestamp, TS, and sends the message request (Pi, TS) to all other
processes in the system
When process Pj receives a request message, it may reply immediately or it
may defer sending a reply back
When process Pi receives a reply message from all other processes in the
system, it can enter its critical section
After exiting its critical section, the process sends reply messages to all its
deferred requests
Principles of Computer Operating Systems
33
DME: Fully Distributed Approach (Cont)
The decision whether process Pj replies immediately to a request(Pi, TS)
message or defers its reply is based on three factors:
If Pj is in its critical section, then it defers its reply to Pi
If Pj does not want to enter its critical section, then it sends a reply
immediately to Pi
If Pj wants to enter its critical section but has not yet entered it, then it
compares its own request timestamp with the timestamp TS
If its own request timestamp is greater than TS, then it sends a reply
immediately to Pi (Pi asked first)
Otherwise, the reply is deferred
Principles of Computer Operating Systems
34
Desirable Behavior of Fully Distributed Approach
Freedom from Deadlock is ensured
Freedom from starvation is ensured, since entry to the critical section is
scheduled according to the timestamp ordering
The timestamp ordering ensures that processes are served in a firstcome, first served order
The number of messages per critical-section entry is
2 x (n – 1)
This is the minimum number of required messages per critical-section entry
when processes act independently and concurrently
Principles of Computer Operating Systems
35
Three Undesirable Consequences
The processes need to know the identity of all other processes in the
system, which makes the dynamic addition and removal of processes more
complex
If one of the processes fails, then the entire scheme collapses
This can be dealt with by continuously monitoring the state of all the
processes in the system
Processes that have not entered their critical section must pause frequently
to assure other processes that they intend to enter the critical section
This protocol is therefore suited for small, stable sets of cooperating
processes
Principles of Computer Operating Systems
36
Token-Passing Approach
Circulate a token among processes in system
Token is special type of message
Possession of token entitles holder to enter critical section
Processes logically organized in a ring structure
Unidirectional ring guarantees freedom from starvation
Two types of failures
Lost token – election must be called
Failed processes – new logical ring established
Principles of Computer Operating Systems
37
Atomicity
Either all the operations associated with a program unit are executed to
completion, or none are performed
Ensuring atomicity in a distributed system requires a transaction
coordinator, which is responsible for the following:
Starting the execution of the transaction
Breaking the transaction into a number of subtransactions, and
distribution these subtransactions to the appropriate sites for
execution
Coordinating the termination of the transaction, which may result in
the transaction being committed at all sites or aborted at all sites
Principles of Computer Operating Systems
38
Election Algorithms
Determine where a new copy of the coordinator should be restarted
Assume that a unique priority number is associated with each active
process in the system, and assume that the priority number of process
Pi is i
Assume a one-to-one correspondence between processes and sites
The coordinator is always the process with the largest priority number.
When a coordinator fails, the algorithm must elect that active
process with the largest priority number
Two algorithms, the bully algorithm and a ring algorithm, can be used to
elect a new coordinator in case of failures
Principles of Computer Operating Systems
39
Bully Algorithm
Applicable to systems where every process can send a message to every
other process in the system
If process Pi sends a request that is not answered by the coordinator
within a time interval T, assume that the coordinator has failed;
Pi tries to elect itself as the new coordinator
Pi sends an election message to every process with a higher priority
number, Pi then waits for any of these processes to answer within T
If no response within T, assume that all processes with numbers greater
than i have failed; Pi elects itself the new coordinator
If answer is received, Pi begins time interval T´, waiting to receive a
message that a process with a higher priority number has been elected
If no message is sent within T´, assume the process with a higher
number has failed; Pi should restart the algorithm
Principles of Computer Operating Systems
40
Bully Algorithm (Cont)
If Pi is not the coordinator, then, at any time during execution, Pi may
receive one of the following two messages from process Pj
Pj is the new coordinator (j > i). Pi, in turn, records this information
Pj started an election (j > i). Pi, sends a response to Pj and begins its
own election algorithm, provided that Pi has not already initiated such
an election
After a failed process recovers, it immediately begins execution of the
same algorithm
If there are no active processes with higher numbers, the recovered
process forces all processes with lower number to let it become the
coordinator process, even if there is a currently active coordinator with a
lower number
Principles of Computer Operating Systems
41
Ring Algorithm
Applicable to systems organized as a ring (logically or physically)
Assumes that the links are unidirectional, and that processes send
their messages to their right neighbors
Each process maintains an active list, consisting of all the priority
numbers of all active processes in the system when the algorithm
ends
If process Pi detects a coordinator failure, it creates a new active list
that is initially empty.
It then sends a message elect(i) to its right neighbor, and adds
the number i to its active list
Principles of Computer Operating Systems
42
Ring Algorithm (Cont)
If Pi receives a message elect(j) from the process on the left, it must
respond in one of three ways:
1.
If this is the first elect message it has seen or sent, Pi creates a new
active list with the numbers i and j
2.
If i j, then the active list for Pi now contains the numbers of all the
active processes in the system
3.
It then sends the message elect(i), followed by the message
elect(j)
Pi can now determine the largest number in the active list to
identify the new coordinator process
If i = j, then Pi receives the message elect(i)
The active list for Pi contains all the active processes in the system
Pi can now determine the new coordinator process.
Principles of Computer Operating Systems
43
Reaching Agreement
There are applications where a set of processes wish to agree on a
common “value”
Such agreement may not take place due to:
Faulty communication medium
Faulty processes
Processes may send garbled or incorrect messages to other
processes
A subset of the processes may collaborate with each other in an
attempt to defeat the scheme
Principles of Computer Operating Systems
44
Faulty Communications
Process Pi at site A, has sent a message to process Pj at site B;
to proceed, Pi needs to know if Pj has received the message
Detect failures using a time-out scheme
When Pi sends out a message, it also specifies a time interval during
which it is willing to wait for an acknowledgment message form Pj
When Pj receives the message,
If Pi receives the acknowledgment message within the specified time
interval,
it immediately sends an acknowledgment to Pi
it concludes that Pj has received its message
If a time-out occurs, Pj needs to retransmit its message and wait for an
acknowledgment
Principles of Computer Operating Systems
45
Faulty Communications (Cont)
Continue until Pi either receives an acknowledgment, or is notified by the
system that B is down
Suppose that Pj also needs to know that Pi has received its
acknowledgment message, in order to decide on how to proceed
In the presence of failure,
it is not possible to accomplish this task
It is not possible in a distributed environment for processes Pi and Pj to
agree completely on their respective states
Principles of Computer Operating Systems
46
Faulty Processes
(Byzantine Generals Problem)
Communication medium is reliable, but processes can fail in
unpredictable ways
Consider a system of n processes, of which no more than m are faulty
Suppose that each process Pi has some private value of Vi
Devise an algorithm that allows each non-faulty Pi to construct a vector
Xi = (Ai,1, Ai,2, …, Ai,n) such that
If Pj is a nonfaulty process, then Aij = Vj.
If Pi and Pj are both non-faulty processes, then Xi = Xj.
Solutions share the following properties
A correct algorithm can be devised only if n 3 x m + 1
The worst-case delay for reaching agreement is proportionate to
m + 1 message-passing delays
Principles of Computer Operating Systems
47
Faulty Processes (Cont)
An algorithm for the case where m = 1 and n = 4 requires two rounds
of information exchange:
Each process sends its private value to the other 3 processes
Each process sends the information it has obtained in the first
round to all other processes
If a faulty process refuses to send messages,
a non-faulty process can choose an arbitrary value and pretend
that that value was sent by that process
After the two rounds are completed, a non-faulty process Pi can
construct its vector Xi = (Ai,1, Ai,2, Ai,3, Ai,4) as follows:
Ai,j = Vi
For j i, if at least two of the three values reported for process Pj
agree, then the majority value is used to set the value of Aij
Otherwise, a default value (nil) is used
Principles of Computer Operating Systems
48