Distributed Systems Chapter 3
Distributed Systems Chapter 3
((()))
Outline
▪ Threads
• Introduction to Threads
• Thread Implementation
• Threads in Distributed Systems
▪ Clients
• User Interfaces
• Client-Side Software for Distribution Transparency
▪ Servers
• General Organization
• Out-of-Band Communication
• Servers and State
• Server Clusters
▪ Code Migration
• Approaches to Code Migration
• Migration and Local Resources
• Migration in Heterogeneous Systems
Introduction to threads
Processes Threads
Introduction to threads
Basic idea – process
Introduction to threads
Processes Threads
Introduction to threads
Processor vs process vs thread
Processor: A processor is the physical hardware (or virtual processor is
software component) component of a computer system.
It executes machine-level instructions of programs.
It contains hardware components such as: Registers, Caches,
ALU, Control Unit, etc.
Process: A process is a program in execution.
It is a software abstraction created by the operating system.
A process contains (process context): Program code, data,
memory space, resources (files, handles, etc.), one or more threads.
A process provides the execution environment and resources
for running programs.
Thread: A thread is the smallest unit of execution within a process.
Introduction to threads
Processes Threads
Introduction to threads
Basic idea – Threads
Introduction to threads
Processes Threads
Context switching
Observations
1. Threads share the same address space. Thread context switching can be
done entirely independent of the operating system (i.e. user thread).
2. Process switching is generally (somewhat) more expensive as it involves
getting the OS in the loop, i.e., trapping to the kernel.
3. Creating and destroying threads is much cheaper than doing so for
processes. However more prone to errors, because no support from
OS/HW to protect threads using each other’s memory.
Introduction to threads
Processes Threads
Introduction to threads
Processes Threads
Introduction to threads
Basic idea – Thread Types
Threads are generally classified into two main types based on where they are
implemented and managed: User Threads and Kernel Threads.
▪ User threads: are implemented and managed at the user level rather than by
the operating system kernel.
▪ Kernel threads: are directly supported and managed by the operating system
kernel.
Introduction to threads
Processes Threads
User-space solution
• All operations can be completely handled within a single process ⇒
implementations can be extremely efficient.
• All services provided by the kernel are done on behalf of the process in
which a thread resides ⇒ if the kernel decides to block a thread, the
entire process will be blocked.
• Threads are used when there are many external events: threads block on
a per-event basis ⇒ if the kernel can’t distinguish threads, how can it
support signaling events to them?
Introduction to threads
Processes Threads
Conclusion – but
Try to mix user-level and kernel-level threads into a single concept (this
called lightweight process), however, performance gain has not turned out to
generally outweigh the increased complexity.
Introduction to threads
Processes Threads
Introduction to threads
Processes Threads
Introduction to threads
Processes Threads
Better structure
• Most servers have high I/O demands (Reading files, Accessing
databases, Communicating over networks). Using simple, well-
understood blocking calls simplifies the structure.
• Multithreaded programs tend to be smaller and easier to understand due
tosystems
Threads in distributed simplified flow of control.
Processes Threads
Better structure
• Most servers have high I/O demands (Reading files, Accessing
databases, Communicating over networks). These operations often
use blocking calls, meaning the program waits until the operation
finishes.
• So, without threads, blocking calls would stop the entire server.
• With threads, if one thread blocks - other threads continue running,
and the server remains responsive.
• Multithreaded programs tend to be smaller and easier to understand due
to simplified flow of control.
Multithreading simplifies the program flow.
Without threads:
Programs must use, event loops, callbacks, state
This makes programs:
machines. This can make code complex and difficult to
•Shorter
maintain.
•Easier to read
With threads
•Easier to maintain
Each thread can execute sequential logic, like a normal
program: receive, process, and end requestes
Threads in distributed systems
Processes Threads
Overview
Model Characteristics
Multithreading Parallelism, blocking system calls
Single-threaded process No parallelism, blocking system calls
Finite-state machine Parallelism, nonblocking system calls
Virtualization
Virtualization is important: Virtualization is a technique in computer systems where
one system imitates or emulates another system’s interface or environment. This
allows software designed for one platform to run on another platform without
modification.
• Hardware changes faster than software
▪ If software depends directly on specific hardware, every hardware change
may require rewriting the software.
▪ Role of Virtualization: it creates a stable interface between SW and HW.
• Ease of portability and code migration
• Isolation of failing or attacked components
▪ E.g. In a cloud server: VM1 runs a web server VM2 runs a database server
▪ If VM1 crashes or is attacked, VM2 continues working.
Principle of virtualization
Processes Virtualization
Principle of virtualization
Processes Virtualization
Ways of virtualization
(a) Process VM (b) Native VMM (VM Monitor) (c) Hosted VMM
Differences
(a) Process VM → for running one program (lightweight).
(b) Native VMM → best for high performance and servers.
(c) Hosted VMM → best for ease of use on personal computers..
Principle of virtualization
Processes Virtualization
Ways of virtualization
Principle of virtualization
Processes Virtualization
Ways of virtualization
Principle of virtualization
Processes Virtualization
Ways of virtualization
Principle of virtualization
Processes Clients
Application-level protocol - For each remote services, the client machine will
have a separate counterpart that can contact the service over the network.
• Example: an agenda running on a user's PDA that needs to synchronize
with a remote, possibly shared agenda.
• Here the middleware layer is typically thin or even absent.
Middleware-level protocol - Provide direct access to remote services by only
offering a convenient user interface.
• The client machine is used only as a terminal with no need for local storage.
• thin-client approach - everything is processed and stored at the server.
• Example: The X Window System (X)
Networked user interfaces
Processes Clients
Improving X
Practical observations
• Applications control the display using specific commands provided
by the X system.
• These commands are sent over a network and executed by the X
server (kernel) on the display machine.
Issue
• Applications frequently send requests to the X server and wait for responses
before continuing. This creates synchronous communication, which slows
down performance.
• The problem becomes worse over wide-area networks with high latency.
Solution
• Redesign or optimize the X protocol. Like use techniques that reduce
bandwidth, such as compressing X messages.
Client-side software
Role of client-side software in achieving distribution transparency
• Access transparency: client-side stubs for RPCs
• Location/migration transparency: let client-side software keep track of
actual location
• Replication transparency: multiple invocations handled by client stub:
Observation
Concurrent servers are the most commonly used in practice: they can easily
handle multiple requests, notably in the presence of blocking operations, e.g. disks
General design issues
Processes Servers
Key Idea:
• Client only needs the server’s IP address
• The port number is already known: Examples: servers that handle Internet
FTP requests always listen to TCP port 21.
General design issues
Processes Servers
Consequences
• Clients and servers are independent, No issues if connection is lost
• Server reboot does not lose client state, and vice versal.
• State inconsistencies due to client or server crashes are reduced
• Possible loss of performance because, e.g., a server cannot anticipate client
behavior (think of prefetching file blocks).
• Send full file names every time and re-authenticate each request.
Observation
The performance of stateful servers can be extremely high, provided clients
are allowed to keep local copies. Less data sent per request and easier
interaction (client doesn’t repeat info).
Crucial element
The first tier is generally responsible for passing requests to an appropriate
server: request dispatching
Server clusters
Processes Servers
Server clusters
Processes Servers
Request Handling
Observation
Having the first tier handle all communication from/to the cluster may lead to a
bottleneck. Dispatching Server
Application
Servers (many)
In a traditional three-tier setup, the first tier typically acts as a reverse proxy:
• It accepts client connections, terminates the TCP connection, then opens a
new connection to a backend server.
• Every request and every response passes through the dispatcher.
Server clusters
Processes Servers
Request Handling
A solution: TCP handoff (connection handoff or direct server return)
• When the switch receives a TCP connection request, it identifies the best
server for handling that request, and forwards the request packet to that server.
• The server, will send an acknowledgment back to the requesting client, but
inserting the switch's IP address as the source field of the header of the IP
packet carrying the TCP segment.
• Note that this spoofing (the creation of TCP/IP packets using another IP
address) is necessary for the client to continue executing the TCP protocol: it is
expecting an answer back from the switch, not from some arbitrary server it is
has never heard of before.
Server clusters
Processes Code migration
Code migration
Three Segments of a Process
• Code segment – contains the actual program instructions.
• Resource segment – references to external resources the process needs
(e.g., files, printers, devices, other processes).
• Execution segment – the current execution state: private data, stack,
program counter (i.e., the runtime context)..
Motivation Explanation
Move computation from overloaded nodes to
Load balancing
underutilized ones.
Weak Mobility
Strong Mobility
Initiation
• Sender-initiated: The source node decides to push the code.
• Receiver-initiated: The destination node pulls the code.
Two issues:
• How does the resource segment refer to resources? Process-to-resource binding
• How does the resource relate with the hosting machine?, how easy it is to move
the resource? Resource-to-machine binding
• Because, when code migrates, the system must decide what to do with each
resource reference.
• The combination of how the code refers to the resource (binding type) and how
movable the resource is (machine binding) determines the best strategy—for
example, move the resource, copy it, keep it accessible remotely.
Models for code migration
Processes Code migration
Actions to be taken with respect to the references to local resources when migrating
code to another machine. Resource-to-Machine Binding
Process Binding Unattached Fastened Fixed
GR, MVGR preferred
Process-to-Resource Binding
Only solution:
Make use of an abstract machine that is implemented on different platforms
• Interpreted languages running on a virtual machine
▪ E.g., Java/JVM, scripting languages
• Virtual machine monitors allowing migration of complete OS + apps.