1/1/2023
Distributed Processes
Module A3
Distributed & Cloud Computing
Sheheryar Malik, Ph.D.
Distributed & Cloud Computing
System Layers
Applications, services
Middleware
OS1 OS2
OS: kernel,
Processes, threads, Processes, threads,
libraries &
communication, ... communication, ...
servers
Platform
Computer & Computer &
network hardware network hardware
Node 1 Node 2
Distributed Processes Sheheryar Malik, Ph.D. 2
1
1/1/2023
Distributed & Cloud Computing
Core OS Functionality
Process manager
Communication
manager
Thread manager Memory manager
Supervisor
Distributed Processes Sheheryar Malik, Ph.D. 3
Distributed & Cloud Computing
Process vs Thread
• Process
o is the part of program in execution
o in whose context one or more threads may be executed
• Thread
o A minimal part of a process in whose context a series of instructions can be
executed
Distributed Processes Sheheryar Malik, Ph.D. 4
2
1/1/2023
Distributed & Cloud Computing
Context Switch
• Context switching is the switching between two processes / thread
• Process context
o The minimal collection of values stored in registers and memory, used for the
execution of a series of instructions
o Saving a process context implies stopping the current execution of process
and saving all the data needed to continue the execution at a later stage
• Thread context
o The minimal collection of values stored in registers and memory, used for the
execution of a thread
o Saving a thread context implies stopping the current execution of thread and
saving all the data needed to continue the execution at a later stage
Distributed Processes Sheheryar Malik, Ph.D. 5
Distributed & Cloud Computing
Context Switch
• Threads share the same address space
o Thread context switching can be done entirely independent of the operating
system
• Process switching is generally more expensive
o it involves getting the OS in the loop, i.e., trapping to the kernel
• Creating and destroying threads is much cheaper than doing so for
processes
Distributed Processes Sheheryar Malik, Ph.D. 6
3
1/1/2023
Distributed & Cloud Computing
Thread Usage in Non-distributed Systems
Context switching as the result of IPC
Distributed Processes Sheheryar Malik, Ph.D. 7
Distributed & Cloud Computing
Threads and Operating Systems
User-space Solution
• All operations can be completely handled within a single process
o implementations can be extremely efficient
• All services provided by the kernel are done on behalf of the process
in which a thread resides
o if the kernel decides to block a thread, the entire process will be blocked
• Threads are used when there are lots of external events: threads
block on a per-event basis
Distributed Processes Sheheryar Malik, Ph.D. 8
4
1/1/2023
Distributed & Cloud Computing
Threads and Operating Systems
Kernel Solution
• The whole idea is to have the kernel contain the implementation of a
thread package
o This means that all operations return as system calls
• Operations that block a thread are no longer a problem
o the kernel schedules another available thread within the same process
• Handling external events is simple
o the kernel (which catches all events) schedules the thread associated with the
event
• The big problem is the loss of efficiency due to the fact that each
thread operation requires a trap to the kernel
Distributed Processes Sheheryar Malik, Ph.D. 9
Distributed & Cloud Computing
Threads and Operating Systems
Combining kernel-level lightweight processes and user-level threads in Solaris
Distributed Processes Sheheryar Malik, Ph.D. 10
10
5
1/1/2023
Distributed & Cloud Computing
Threads in Distributed Systems
A multithreaded server organized in a dispatcher/worker model
Distributed Processes Sheheryar Malik, Ph.D. 11
11
Distributed & Cloud Computing
Threads in Distributed Systems
• Multithreaded Web client
o Hides network latencies
o Web browser scans an incoming HTML page, and finds that more files need to
be fetched
o Each file is fetched by a separate thread, each doing a (blocking) HTTP request
o As files come in, the browser displays them
• Multiple request-response calls to other machines (RPC)
o A client does several calls at the same time, each one by a different thread
o It then waits until all results have been returned
o Note: if calls are to different servers, we may have a linear speed-up
Distributed Processes Sheheryar Malik, Ph.D. 12
12
6
1/1/2023
Distributed & Cloud Computing
Threads in Distributed Systems
• Improve performance
o Starting a thread is much cheaper than starting a new process
o Having a single-threaded server prohibits simple scale-up to a multiprocessor
system
o As with clients: hide network latency by reacting to next request while
previous one is being replied
• Better structure
o Most servers have high I/O demands
▪ Using simple, well-understood blocking calls simplifies the overall structure
o Multithreaded programs tend to be smaller and easier to understand due to
simplified flow of control
Distributed Processes Sheheryar Malik, Ph.D. 13
13
Distributed & Cloud Computing
Multithreaded Servers
Model Characteristics
Threads Parallelism, blocking system calls
Single-threaded process No parallelism, blocking system calls
Finite-state machine Parallelism, non-blocking system calls
Three ways to construct a server
Distributed Processes Sheheryar Malik, Ph.D. 14
14
7
1/1/2023
Distributed & Cloud Computing
Java Thread Management Methods
• Thread(ThreadGroup group, Runnable target, String name)
o creates a new thread in the SUSPENDED state, which will belong to group and be identified as
name; the thread will execute the run() method of target
• setPriority(int newPriority), getPriority()
o set and return the thread’s priority
• run()
o a thread executes the run() method of its target object, if it has one, and otherwise its own run()
method (Thread implements Runnable)
• start()
o change the state of the thread from SUSPENDED to RUNNABLE
• sleep(int millisecs)
o cause the thread to enter the SUSPENDED state for the specified time
• yield()
o enter the READY state and invoke the scheduler
• destroy()
o destroy the thread
Distributed Processes Sheheryar Malik, Ph.D. 15
15
Distributed & Cloud Computing
Java Thread Synchronization Calls
• [Link](int millisecs)
o blocks the calling thread for up to the specified time until thread has
terminated
• [Link]()
o interrupts thread: causes it to return from a blocking method call such as
sleep()
• [Link](long millisecs, int nanosecs)
o blocks the calling thread until a call made to notify() or notifyAll() on object
wakes the thread, or the thread is interrupted, or the specified time has
elapsed
• [Link](), [Link]()
o wakes, respectively, one or all of any threads that have called wait() on object
Distributed Processes Sheheryar Malik, Ph.D. 16
16
8
1/1/2023
Distributed & Cloud Computing
Client-Side Software for 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
• Failure transparency: can often be placed only at client (we’re trying to mask
server and communication failures)
Distributed Processes Sheheryar Malik, Ph.D. 17
17
Distributed & Cloud Computing
Client-Side Software for Distribution Transparency
A possible approach to transparent replication of a remote object using a client-side solution
Distributed Processes Sheheryar Malik, Ph.D. 18
18
9
1/1/2023
Distributed & Cloud Computing
Server: General Organization
• A server is a process that waits for incoming service requests at a specific
transport address
• In practice, there is a one-to-one mapping between a port and a service
• Some Famous Ports
o ftp-data 20 File Transfer [Default Data]
o ftp 21 File Transfer [Control]
o telnet 23 Telnet
o smtp 25 Simple Mail Transfer
o login 49 Login Host Protocol
o sunrpc 111 SUN RPC (portmapper)
o courier 530 Xerox RPC
Distributed Processes Sheheryar Malik, Ph.D. 19
19
Distributed & Cloud Computing
Server: General Organization
• Iterative servers
o The server itself handles the request and, if necessary, returns a response to
the requesting client
o Iterative servers can handle only one client at a time, in contrast to
concurrent servers
• Concurrent servers
o The server does not handle the request itself
o It passes the request to a separate thread or another process, after which it
immediately waits for the next incoming request
o E.g. in UNIX, when a service request comes in, they start a subprocess to
handle the request (UNIX inetd)
Distributed Processes Sheheryar Malik, Ph.D. 20
20
10
1/1/2023
Distributed & Cloud Computing
Server: General Design Issues
Client-to-server binding using
a daemon as in DCE
3.7
Client-to-server binding using a
superserver as in UNIX
Distributed Processes Sheheryar Malik, Ph.D. 21
21
Distributed & Cloud Computing
Server Cluster: Tier Organization
Distributed Processes Sheheryar Malik, Ph.D. 22
22
11
1/1/2023
Distributed & Cloud Computing
Stateless Server
• Never keep accurate information about handled a request
• Don’t record whether a file has been access
• Don’t keep track of your clients
• Don’t promise to invalidate a client’s
• Clients and servers are completely independent
• 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)
Distributed Processes Sheheryar Malik, Ph.D. 23
23
Distributed & Cloud Computing
Stateful Server
• Keeps track of the status of its clients
• Record that a file has been opened, so that prefetching can be done
• Knows which data a client has cached, and allows clients to keep local
copies of shared data
• The performance of stateful servers can be extremely high, provided
clients are allowed to keep local copies
o As it turns out, reliability is not a major problem
Distributed Processes Sheheryar Malik, Ph.D. 24
24
12
1/1/2023
Distributed & Cloud Computing
Object Adapter
Organization of an object server supporting different activation policies
Distributed Processes Sheheryar Malik, Ph.D. 25
25
Distributed & Cloud Computing
Code Migration
• It is the transfer of code / process from one machine to another
• Traditionally, code migration in distributed systems took place in the
form of process migration
o in which an entire process is moved from one machine to another
• Moving a running process to a different machine is a costly and
complex task
• More difficult in heterogeneous systems
• Performance can be improved if processes are moved from heavily-
loaded to lightly-loaded machines
Distributed Processes Sheheryar Malik, Ph.D. 26
26
13
1/1/2023
Distributed & Cloud Computing
Code Migration
The principle of dynamically configuring a client to communicate to a server
The client first fetches the necessary software, and then invokes the server
Distributed Processes Sheheryar Malik, Ph.D. 27
27
Distributed & Cloud Computing
Models for Code Migration
• Fuggetta et al. presented a code migration framework
• In the framework, a process consist of three segments
o Code segment
▪ is the part that contains the set of instructions that make up the program that is being
execute
o Resource segment
▪ contains references to external resources needed by the process, such as files, printers,
devices, other processes, and so on
o Execution segment
▪ is used to store the current execution state of a process, consisting of private data, the
stack, and, of course, the program counter
Distributed Processes Sheheryar Malik, Ph.D. 28
28
14
1/1/2023
Distributed & Cloud Computing
Models for Code Migration
Alternatives for code migration
Distributed Processes Sheheryar Malik, Ph.D. 29
29
Distributed & Cloud Computing
Models for Code Migration
Weak vs Strong Mobility
Weak mobility Strong mobility
• Move only code segment (with • Move component, including
initialization data) and reboot execution state
execution • Migration
• Relatively simple, especially if code is o move entire object from one machine to
portable the other
• Distinguish code shipping (push) from • Cloning
code fetching (pull) o start a clone, and set it in the same
execution state
Strong mobility is more harder to implement than weak mobility
Distributed Processes Sheheryar Malik, Ph.D. 30
30
15
1/1/2023
Distributed & Cloud Computing
Models for Code Migration
Sender vs Receiver Initiated Mobility
Sender Initiated Mobility Receiver Initiated Mobility
• Migration is initiated at the machine • The initiative for code migration is
where the code resides or is being taken by the target machine
executed • Java applets are an example of this
• Typically, sender-initiated migration is approach
done when uploading programs to a
compute server
• Another example is sending a search
program across the Internet to a Web
database server to perform the
queries at that server
Receiver-initiated migration is simpler than sender-initiated migration
Distributed Processes Sheheryar Malik, Ph.D. 31
31
Distributed & Cloud Computing
Migration and Local Resources
Process to Resource Binding
• by Identifier
o is the strongest binding
o is in which a process refers to a resource by its identifier
o The process requires precisely the referenced resource
o Example is when a process uses a URL to refer to a specific Web site
• by Value
o is a weaker form of process-to-resource binding
o is when only the value of a resource is needed
o the execution of the process would not be affected if another resource would provide that same
value
o Example is when a program relies on standard libraries
▪ E.g. those for programming in C or Java
▪ such libraries should always be locally available, but their exact location in the local file system may differ
between sites
• by Type
o is the weakest form of binding is when a process indicates it needs only a resource of a specific
type
o Example is references to local devices, such as monitors, printers, and so on
Distributed Processes Sheheryar Malik, Ph.D. 32
32
16
1/1/2023
Distributed & Cloud Computing
Migration and Local Resources
Resource to Machine Binding
• Unattached resources
o can be easily moved between different machines,
o Examples are data files associated only with the program that is to be
migrated
• Fastened resources
o can be possibly moved or copied, but only at relatively high costs
o Examples local databases and complete Web sites
• Fixed resources
o are intimately bound to a specific machine or environment and cannot be
moved
o Examples are often local devices or a local communication end point
Distributed Processes Sheheryar Malik, Ph.D. 33
33
Distributed & Cloud Computing
Migration and Local Resources
Process to Resource Binding
Resource-to Machine binding
Unattached Fastened Fixed
Process-to- By identifier MV (or GR) GR (or MV) GR
resource By value CP ( or MV, GR) GR (or CP) GR
binding By type RB (or GR, CP) RB (or GR, CP) RB (or GR)
❑ GR: Establish a global system wide reference
❑ MV: Move the resource
❑ CP: Copy the value of the resource
❑ RB: Rebind process to locally available resource
Actions to be taken with respect to the references to local resources when migrating
code to another machine
Distributed Processes Sheheryar Malik, Ph.D. 34
34
17
1/1/2023
Distributed & Cloud Computing
Migration in Heterogeneous Systems
3-15
The principle of maintaining a migration stack to support migration of an execution segment in a heterogeneous environment
Distributed Processes Sheheryar Malik, Ph.D. 35
35
18