ch03 Processes
ch03 Processes
Introduction to threads
Distributed Systems
Basic idea
(3rd Edition)
We build virtual processors in software, on top of physical processors:
Processor: Provides a set of instructions along with the capability of
automatically executing a series of those instructions.
Maarten van Steen Andrew S. Tanenbaum
Thread: A minimal software processor in whose context a series of
instructions can be executed. Saving a thread context implies
stopping the current execution and saving all the data needed to
Chapter 03: Processes continue the execution at a later stage.
Process: A software processor in whose context one or more threads may
Edited by: Hicham G. Elmongui be executed. Executing a thread, means executing a series of
instructions in the context of that thread.
2 / 36
Contexts
Processor context: The minimal collection of values stored in the registers Observations
of a processor used for the execution of a series of instructions (e.g., 1 Threads share the same address space. Thread context switching can be
stack pointer, addressing registers, program counter). done entirely independent of the operating system.
Thread context: The minimal collection of values stored in registers and 2 Process switching is generally (somewhat) more expensive as it involves
memory, used for the execution of a series of instructions (i.e., processor getting the OS in the loop, i.e., trapping to the kernel.
context, state).
3 Creating and destroying threads is much cheaper than doing so for
Process context: The minimal collection of values stored in registers and processes.
memory, used for the execution of a thread (i.e., thread context, but now
also at least MMU register values).
3 / 36 4 / 36
Process A Process B
Processes: Threads Threads in distributed systems Processes: Threads Threads in distributed systems
Using threads at the client side Using threads at the server side
Interface A
Overview
Program Implementation of
Model Characteristics mimicking A on B
Single-threaded process No parallelism, blocking system calls Hardware/software system A Hardware/software system B
Finite-state machine Parallelism, nonblocking system calls
Multithreaded servers 11 / 36 12 / 36
Processes: Virtualization Principle of virtualization Processes: Virtualization Principle of virtualization
Four types of interfaces at three different levels Application/Libraries Application/Libraries Operating system
1 Instruction set architecture: the set of machine instructions, with two Runtime system Operating system Virtual machine monitor
subsets:
Privileged instructions: allowed to be executed only by the operating Operating system Virtual machine monitor Operating system
system.
General instructions: can be executed by any program. Hardware Hardware Hardware
Differences
(a) Separate set of instructions, an interpreter/emulator, running atop an OS.
(b) Low-level instructions, along with bare-bones minimal operating system
(c) Low-level instructions, but delegating most work to a full-fledged OS.
Application/Libraries
For any conventional computer, a virtual machine monitor may be constructed
if the set of sensitive instructions for that computer is a subset of the set of
Guest operating system Privileged instruction: if and only if privileged instructions.
executed in user mode, it causes
Virtual machine monitor
a trap to the operating system Problem: condition is not always satisfied
There may be sensitive instructions that are executed in user mode without
Privileged Host operating system Nonpriviliged
General instruction: the rest
instructions instructions causing a trap to the operating system.
Hardware
Solutions
Special instructions Emulate all instructions
Control-sensitive instruction: may affect configuration of a machine (e.g., Wrap nonprivileged sensitive instructions to divert control to VMM
one affecting relocation register or interrupt table).
Paravirtualization: modify guest OS, either by preventing nonprivileged
Behavior-sensitive instruction: effect is partially determined by context sensitive instructions, or making them nonsensitive (i.e., changing the
(e.g., POPF sets an interrupt-enabled flag, but only in system mode). context).
Types of virtualization 15 / 36 Types of virtualization 16 / 36
Processes: Virtualization Application of virtual machines to distributed systems Processes: Clients Networked user interfaces
17 / 36 18 / 36
Processes: Clients Networked user interfaces Processes: Clients Networked user interfaces
Basic organization
Application server Application server User's terminal Practical observations
Window Application Xlib interface There is often no clear separation between application logic and
manager user-interface commands
Xlib Xlib Applications tend to operate in a tightly synchronous manner with an X
Local OS Local OS
kernel
X protocol
Processes: Clients Client-side software for distribution transparency Processes: Servers General design issues
21 / 36 22 / 36
Processes: Servers General design issues Processes: Servers General design issues
Common organization
Logical switch Application/compute servers Distributed
Stateful servers (possibly multiple) file/database
Keeps track of the status of its clients: system
Record that a file has been opened, so that prefetching can be done Dispatched
Knows which data a client has cached, and allows clients to keep local Client requests
request
Observation
The performance of stateful servers can be extremely high, provided clients
First tier Second tier Third tier
are allowed to keep local copies. As it turns out, reliability is often not a major
problem.
Crucial element
The first tier is generally responsible for passing requests to an appropriate
server: request dispatching
When servers are spread across the Internet Reasons to migrate code
Observation Load distribution
Spreading servers across the Internet may introduce administrative problems. Ensuring that servers in a data center are sufficiently loaded (e.g., to
These can be largely circumvented by using data centers from a single cloud prevent waste of energy)
provider.
Minimizing communication by ensuring that computations are close to
where the data is (think of mobile computing).
Request dispatching: if locality is important
Common approach: use DNS: Flexibility: moving code to a client when needed
1 Client looks up specific service through DNS - client’s IP address is part 2. Client and server
communicate
of request Client Server
2 DNS server keeps track of replica servers for the requested service, and
returns address of most local server.
Client transparency
1. Client fetches code
To keep client unaware of distribution, let DNS resolver act on behalf of client. Service-specific
client-side code
Problem is that the resolver may actually be far from local to the actual client. Code repository
Wide-area clusters 31 / 36 32 / 36
Avoids pre-installing software and increases dynamic configuration.
Processes: Code migration Reasons for migrating code Processes: Code migration Reasons for migrating code
CS: Client-Server REV: Remote evaluation CoD: Code-on-demand MA: Mobile agents
33 / 36 34 / 36
Processes: Code migration Migration in heterogeneous systems Processes: Code migration Migration in heterogeneous systems
35 / 36 36 / 36