Final Notes For DS
Final Notes For DS
Processes
Introduction
Communication takes place between processes.
Process = Program in execution.
Process management and scheduling are crucial from OS perspective.
Other important issues arise in distributed systems.
• Cheap thread creation and destruction: Allocate and free memory only.
• Efficient context switching: Store and reload CPU register values with few instructions.
• Disadvantage: Blocking system calls can block the entire process and all its threads.
b. Implement them in the OS’s Kernel
Anatomy of Clients
There are two issues here.
A. User Interfaces
• Creating a user-server interaction environment for devices like mobile phones with
simple displays and keys.
• Graphical User Interfaces (GUIs) are commonly used.
• The X Window System (X) is a widely used system.
o X has the X kernel responsible for controlling the terminal (monitor, keyboard,
pointing device) and is hardware dependent.
o The X system includes terminal-specific device drivers accessed through the xlib
library.
B. Client-Side Software for Distribution Transparency
• Client-server applications involve processing and data execution at the client side,
along with the user interface.
• Examples include embedded client software used in ATMs, cash registers, etc.
• Client software can also include components to achieve distribution transparency.
• E.g. Replication transparency
• In a distributed system with replicated servers, the client proxy can send requests
to multiple replicas.
• Client-side software can collect all the responses transparently and pass a single
return value back to the client application.
Client-side software can be used to achieve access transparency and failure transparency in a
system.
• Approach 1: The client can exit the client application, which will break the connection to
the server. The server, assuming that the client crashed, will then tear down the
connection.
• Approach 2: The client can send out-of-band data, which is processed by the server
before any other data from the client. The server may listen on a separate control
endpoint or receive it on the same connection as urgent data in TCP.
D. Whether or not the server is stateless
• Stateless server: Does not retain information about the state of its clients. For example,
a web server.
• Soft state: A server guarantees to maintain its state for a limited time. For instance, it
may keep a client informed about updates. After the specified time expires, the client
needs to poll for updates.
• Stateful server: Maintains information about its clients. For example, a file server that
allows clients to keep a local copy of a file and perform update operations.
Server Clusters
• It is a group of machines connected via a network, typically a LAN with high bandwidth
and low latency. Each machine runs one or more servers.
• The server cluster is logically divided into three tiers or layers.
✓ First Tier = Logical Switch (possibly multiple)
✓ Second Tier = Application/compute servers
✓ Third Tier = Distributed file/database system
Distributed Servers
• Problem with server clusters: If the logical switch or single access point fails, the entire
cluster becomes unavailable.
• Solution: Multiple access points can be provided to ensure availability, where publicly
available addresses lead to a distributed server setup.
• Example: DNS (Domain Name System) can return multiple addresses for the same host
name, allowing clients to connect to different servers.
Code Migration
• Code migration involves transferring programs, even while they are running, across
heterogeneous systems.
• Communication previously focused on passing data, but now programs themselves can
be transferred.
• Code migration also includes moving associated data. When a program migrates while
running, its status, pending signals, and other environment variables such as the stack
and program counter need to be moved as well.
Weak Mobility
• It involves transferring only the code segment and possibly some initialization data.
• In this case, a program always starts from its initial stage.
• Examples include Java Applets, where execution can occur either by the target process in
its own address space or by a separate process.
Strong Mobility
• It involves transferring both the code and execution segments of a process.
• Enables the migration of a process during execution.
• Can be supported by remote cloning, where an exact copy of the original process runs
on a different machine and executes in parallel.
• UNIX achieves this through forking a child process, creating a clone of the original
process.
Migration can occur in two ways:
- Sender-initiated migration: Initiated by the machine where the code resides or is
currently running.
o Examples include uploading programs to a server, which may require
authentication or verification that the client is registered.
- Receiver-initiated migration: Initiated by the target machine.
o Examples include Java Applets, which facilitate easier implementation of
migration from the server to the client machine.
Chapter Four
Naming
Introduction
• Names play a crucial role in:
o Sharing resources.
o Uniquely identifying entities.
o Referring to locations.
• Resolving a name to its corresponding entity is an important issue.
• To resolve names, a naming system needs to be implemented.
• In a distributed system, the implementation of a naming system is often distributed,
unlike in non-distributed systems.
• Efficiency and scalability of the naming system are the primary concerns.
1. Naming Entities
Names, Identifiers, and Addresses
• In a distributed system, a name is a string of bits or characters used to refer to an entity.
• An entity can be anything, such as hosts, printers, disks, files, objects, processes, or
users.
• Entities can be operated on and offer interfaces with operations specific to them. For
example, a printer entity may offer operations for printing documents or requesting job
status.
• To interact with an entity, it is necessary to access it through its access point, which is
also an entity, typically a special one.
Access Point
• The name of an access point is known as an address, such as an IP address and port
number used by the transport layer.
• The address of an access point is also considered the address of the entity it belongs to.
• An entity can have multiple access points, similar to accessing an individual through
different telephone numbers.
• An entity may change its access point over time, for example, a mobile computer
obtaining a new IP address as it moves.
Address
• An address is a special kind of name.
• It refers to at most one entity.
• Each entity is referred to by at most one address, even in cases of replication, such as
with web pages.
• An entity may change its access point, or an access point may be reassigned to a
different entity, similar to how telephone numbers can be reassigned in offices.
• Separating the name of an entity from its address provides easier and more flexible
management. Such a name is known as location independent.
Identifier
• There are other types of names that uniquely identify an entity.
• An identifier is a name with the following properties:
o It refers to at most one entity.
o Each entity is referred to by at most one identifier.
o It always refers to the same entity and is never reused.
• Identifiers allow unambiguous reference to an entity.
• Examples of identifiers include
o the name of an FTP server,
o the URL of the FTP server,
o the address of the FTP server (IP number and port number), etc.
o The address of an FTP server may change over time.
Resolution
• Name resolution refers to the process of looking up a stored name in a node by
following the given path name, ultimately finding the associated address.
Chapter Five
Clock Synchronization
Introduction
• Apart from communication, processes cooperate and synchronize through various
mechanisms.
• Naming plays a role in facilitating cooperation by allowing processes to share resources
or entities.
• Synchronization is concerned with ensuring that processes do not simultaneously access
a shared resource and that events occur in a defined order, such as when two processes
exchange messages.
What is Synchronization?
• Synchronization refers to the process of coordinating or aligning two or more items to
work together or have the same state.
• An example of synchronization is adjusting two watches to display the same time,
ensuring they are in sync.
• In the context of computers, synchronization involves transferring data between two or
more devices to ensure they have the same information or state.
• It is common to synchronize data between computers or devices to maintain consistency
when running programs or sharing information.
1. Clock Synchronization
• In centralized systems, time can be reliably determined through a system call.
• For example, if process A retrieves the time at time t1 and obtains tA, and process B
retrieves the time at time t2 (where t1 < t2) and obtains tB, it is guaranteed that tA will
always be less than tB.
• Achieving agreement on time in distributed systems is challenging due to factors like
network latency and clock drift.
• For instance, consider the "make" program on a UNIX machine, which only compiles
source files if their last update time is later than that of the corresponding object file.
Physical Clocks
• It is not possible to synchronize all clocks in a distributed system.
• Clock skew occurs as the crystals in different computers run at different frequencies,
causing clocks to drift out of sync over time.
Measurement of Time
• Historically, time was measured astronomically based on the Earth's rotation around the
Sun.
• One solar second is equivalent to 1/86400th of a solar day (24 * 3600 = 86400).
• It was discovered that the Earth's rotation period is not constant, as factors like tidal
friction and atmospheric drag affect its speed.
• Astronomical timekeeping was replaced by counting transitions of the cesium 133 atom,
leading to International Atomic Time (TAI).
• TAI lags behind a solar day by 3 milliseconds due to the increasing length of the day.
• UTC was created to address this issue, introducing leap seconds when the discrepancy
between TAI and solar time reaches 800 milliseconds.
• UTC replaced GMT as the standard time reference.
• UTC is broadcasted in some countries via shortwave radio and satellites, but users must
consider propagation delay when compensating for precise time synchronization.
2. Logical Clocks
• Logical clocks are used in applications where the internal consistency of clocks is more
important than being synchronized with real time.
• The concept of logical clocks focuses on internal consistency rather than real-time
accuracy.
Lamport Timestamps
• It is a logical clock algorithm proposed by Lamport.
• Lamport introduced the "happens before" relation, denoted as a -> b, which signifies
that event a occurs before event b.
• The "happens before" relation holds true when events a and b occur in the same process
and a precedes b, or when a message is sent by one process and received by another
process.
• The "happens before" relation is transitive, meaning if A -> B, and B -> C, then A -> C.
• If two events, X and Y, occur in different processes that do not exchange messages, then
both X -> Y and Y -> X are not true. These events are considered concurrent, and their
order cannot be determined.
• Each event can be assigned a time value C(a) that all processes agree upon. If A -> B,
then C(a) < C(b).
• Lamport proposed an algorithm for assigning times to processes.
• The algorithm considers three processes running on different machines, each with its
own clock.
• The solution is based on the happens before relation.
• Each message carries the sending time, and if the receiver's clock shows a value prior to
the time the message was sent, the receiver fast forwards its clock to be one more than
the sending time.
Additional requirements
• Between two events, the clock must tick at least once. If a process sends or receives two
messages in succession, its clock must advance by one tick.
• No two events must occur at exactly the same time. If this happens, the number of the
process is attached to differentiate them. For example, events happening in processes 1
and 2 at time 40 would be represented as 40.1 and 40.2.
• Assigning time to events in a distributed system is subject to the following conditions:
1. If a -> b in the same process, then C(a) < C(b).
2. If a represents the sending of a message and b represents the receiving of that message,
then C(a) < C(b).
3. For all distinct events a and b, C(a) ≠ C(b).
• Example: Totally-Ordered Multicasting
• Consider a bank database replicated across multiple cities for performance reasons.
Queries are forwarded to the nearest copy.
• Let's assume a customer in city A with $1000 in her account wants to add $100 to her
account (update 1) while a bank employee in city B initiates an update of increasing all
accounts by 1% interest (update 2).
• Both updates need to be carried out at all copies of the database.
• Due to communication delays, if the updates are performed in a different order at
different locations, the database will become inconsistent (e.g., city A = $1111, city B =
$1110).
• Situations like these require Totally-Ordered Multicast, where all messages are delivered
in the same order to each receiver.
• Lamport timestamps can be used to implement totally-ordered multicasts.
• Each message is timestamped.
• During multicasting, a message is also sent to the sender.
• Messages from the same sender are received in the order they are sent, assuming no
message is lost. All messages are put in a local queue ordered by timestamp.
• Each receiver multicasts an acknowledgement.
• Eventually, all processes will have the same copy of the local queue.
• A process can deliver a queued message to the application it is running only when that
message is at the top of the queue and has been acknowledged by each other process.
Vector Timestamps
Vector timestamps enable capturing both the total ordering and causality of events in
distributed systems.
With Lamport timestamps a → b does not necessarily mean a happens before b; only that all
processes agree; but they ensure total ordering
Unlike Lamport timestamps, which only ensure total ordering agreed upon by all processes,
vector timestamps provide information about the causal relationships between events.
Mutual Exclusion
• In distributed systems, mutual exclusion is used to ensure that only one process can
access shared data or resources at a time.
• In single-processor systems, mutual exclusion is achieved using constructs like
semaphores and monitors.
• In distributed systems, different algorithms are used to implement mutual exclusion and
protect critical regions.
• Three commonly used algorithms for achieving mutual exclusion in distributed systems
are centralized, distributed, and token ring.
Centralized Algorithm
• The centralized algorithm involves appointing a coordinator responsible for granting
permissions to access critical regions.
• Three messages are required: request, grant, release
a) Process 1 requests permission from the coordinator to enter a critical region and
receives the grant.
b) Process 2 requests permission to enter the same critical region but does not receive an
immediate response. It is blocked and queued by the coordinator.
c) When Process 1 exits the critical region, it notifies the coordinator, who then responds
to Process 2, granting it permission to enter the critical region.
• The algorithm
o guarantees mutual exclusion.
o It ensures fairness by following a first-come, first-served approach.
o There is no starvation in this algorithm.
o Implementation is easy, requiring only three messages: request, grant, release.
• Shortcoming: A failure of the coordinator can crash the system, especially if processes
block after sending a request. It also becomes a performance bottleneck.
A Distributed Algorithm
• It assumes a total ordering of events in the system, such as using Lamport timestamps.
• When a process wants to enter a critical region, it sends a message to everyone
containing the critical region's name, its process number, and the current time to all
processes, including itself.
• Message sending is assumed to be reliable, and every message is acknowledged.
• When a process receives a request message:
1. If the receiver is not in a critical region and does not want to enter it, it sends back an OK
message to the sender.
2. If the receiver is already in the critical region, it queues the request without replying.
3. If the receiver wants to enter the critical region but has not yet done so, it compares the
timestamp of the incoming message with its own. The lowest timestamp wins. If the
incoming message has a lower timestamp, it sends an OK message; otherwise, it queues
the incoming message and doesn’t do anything.
• When the sender receives replies from all processes, it can enter the critical region.
• When the sender finishes, it sends an OK message to all processes in its queue.
• It is not possible for two processes to enter the critical region at the same time if they
initiate a message at the same time.
• Mutual exclusion is guaranteed.
• The total number of messages required to enter a critical region increases to 2(n-1),
where n is the number of processes.
• There is no single point of failure, but there are n points of failure.
• The algorithm introduces n bottlenecks.
• It is slower, more complicated, more expensive, and less robust than the previous
algorithm, but it demonstrates the possibility of a distributed algorithm.
A Token Ring Algorithm
• It assumes a bus network (e.g., Ethernet) where no physical ordering of processes is
required, but a logical ring is constructed by software.
4. Election Algorithms
• There are situations where one process must act as a coordinator, initiator, or perform a
special task.
• Assume that
o Each process has a unique number.
o Every process knows the process number of every other process, but not their
current state (running or down).
• Election algorithms are used to locate the process with the highest process number.
• Two algorithms commonly used for this purpose are the Bully algorithm and the Ring
algorithm.
PROCESSES
INTRODUCTION
THREADS AND THEIR IMPLEMENTATION
THREADS IN NON-DISTRIBUTED SYSTEMS
Why do we need threads?
Thread Implementation
THREADS IN DISTRIBUTED SYSTEMS
Multithreaded Clients
Multithreaded Servers
A. Single-Threaded Process
B. Threads
C. Finite-State Machine
Summary
ANATOMY OF CLIENTS
A. USER INTERFACES
B. CLIENT-SIDE SOFTWARE FOR DISTRIBUTION TRANSPARENCY
3.3 SERVERS AND DESIGN ISSUES
GENERAL DESIGN ISSUES
A. How to Organize Servers?
Iterative Server
Concurrent Server
B. Where do clients contact a server?
The client can know the endpoint using two approaches.
C. Whether and how a server can be interrupted?
D. Whether or not the server is stateless
SERVER CLUSTERS
DISTRIBUTED SERVERS
CODE MIGRATION
REASONS FOR MIGRATING CODE
MODES FOR CODE MIGRATION
WEAK MOBILITY
STRONG MOBILITY
CHAPTER FOUR
NAMING
INTRODUCTION
1. NAMING ENTITIES
NAMES, IDENTIFIERS, AND ADDRESSES
ACCESS POINT
ADDRESS
IDENTIFIER
2. NAME SPACES AND NAME RESOLUTION
RESOLUTION
LINKING AND MOUNTING
1. Mounting
2. Add a new root node and make the existing root nodes its children
THE IMPLEMENTATION OF A NAMESPACE
NAME SPACE DISTRIBUTION
Global Layer
Administrational Layer
Managerial Layer
IMPLEMENTATION OF NAME RESOLUTION
A. Iterative Name Resolution
B. Recursive Name Resolution
Advantages and Drawbacks
Summary
CHAPTER FIVE
CLOCK SYNCHRONIZATION
INTRODUCTION
WHAT IS SYNCHRONIZATION?
1. CLOCK SYNCHRONIZATION
PHYSICAL CLOCKS
Measurement of Time
CLOCK SYNCHRONIZATION ALGORITHMS
Cristian's Algorithm
Berkley’s Algorithm
2. LOGICAL CLOCKS
LAMPORT TIMESTAMPS
Additional requirements
Vector Timestamps
MUTUAL EXCLUSION
Centralized Algorithm
A Distributed Algorithm
A Token Ring Algorithm
4. ELECTION ALGORITHMS
THE BULLY ALGORITHM (THE BIGGEST PERSON WINS)