0% found this document useful (0 votes)
24 views

Chapter - 3

1) Processes and threads are the basic units of program execution. A process contains the program code, data, and resources while a thread is the smallest unit of processing that can be scheduled by the operating system. 2) Using threads provides benefits over processes such as lower overhead for creation and context switching. This allows applications to avoid performance penalties associated with frequent process switching. 3) Multithreading allows a program to divide work between multiple threads to improve CPU utilization and performance. Each thread can execute concurrently on multiprocessor systems to take advantage of parallel processing capabilities.

Uploaded by

Addisu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Chapter - 3

1) Processes and threads are the basic units of program execution. A process contains the program code, data, and resources while a thread is the smallest unit of processing that can be scheduled by the operating system. 2) Using threads provides benefits over processes such as lower overhead for creation and context switching. This allows applications to avoid performance penalties associated with frequent process switching. 3) Multithreading allows a program to divide work between multiple threads to improve CPU utilization and performance. Each thread can execute concurrently on multiprocessor systems to take advantage of parallel processing capabilities.

Uploaded by

Addisu
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Arba Minch University

Institute of Technology
Faculty of Computing & Software Engineering

Intro to Distributed

Intro to Distributed System


System
(CoSec4038)
Mr. Addisu M. (Asst. Prof) G3 SE - Regular
1
Chapter 3

Processes in DS
2

Intro to Distributed System


Introduction
 Communication takes place between processes
 Traditional OS: concerned with the “local” management
and scheduling of processes.
 Modern DSs: a number of other issues are of equal
importance.

Intro to Distributed System


 From an OS perspective, management and scheduling of
processes are the most important issues to deal with
 primary task of OS is to execute and manage processes
 The concept of a process originates from field of OSs
where it is generally defined as the instance of a computer
program that is being executed instructions Parallelly by
one or many threads 3
Introduction
 What is a program and what is a process?
o Program is a specification, which contains data type definitions,
how data can be accessed, and set of instructions that when
executed accomplishes useful “work”
o One program can be several processes - multiple users executing the
same program
Process & Thread are two basic units of program execution

Intro to Distributed System



 Process - program (set of instructions) that is loaded into
memory, found under executing that are intended to carry out a
specific job
o Can create one or more other processes referred to as child processes
o composed of several threads executing in parallel

4
Introduction
 Process & Thread are two basic units of program execution
 Process components: Code Data
Process Status
 program (code) to be executed Resource

 data on which program will execute


 resources required by the program
 status of the process execution

Intro to Distributed System


Abstract Machine Environment

 Program is passive, while process is active


 Thread: lightweight sub-process, smallest unit of processing
 requires less resources to create and exists in the process
 independent - if there occurs exception in one thread, it doesn't
affect other threads
 shares process resources (memory), which is visible to all threads
in a multi-threaded program
 Threads have their own flow of control and execution state 5
Introduction
 Process & Thread are two basic units of program execution
 Thread: lightweight sub-process, smallest unit of processing
 Compared to processes, threads
• are quick to create
• are quick to context switch
• can readily share memory, files and sockets
 Threads are useful where

Intro to Distributed System


• many concurrent computation units are needed
• computation units need to share address space easily
 Process may be made up of multiple threads
 In most traditional OS, each process has an address space, single thread
of control and other processing resources
 To efficiently organize client-server systems, it is often convenient
to make use of multithreading techniques
• necessary to have multiple threads of control sharing the same CPU
and other resources is made transparent but running in parallel
6
Problems with Processes
 Creating and managing processes is generally regarded as an
expensive task
 Making sure all the processes peacefully co-exist on the system
is not easy (as concurrency transparency comes at a price)

Intro to Distributed System


 Threads can be thought of as an “execution of a part of a
program (in user-space)”
 Rather than make the OS responsible for concurrency
transparency, it is left to the individual application to manage
the creation and scheduling of each thread
7
What is Multitasking?
 Multitasking is used to keep all of a computer's resources at work as
much of the time as possible and it is the capability of the OS of
running several applications at the same time
 It is the capability of the OS of running several processes at the same
time by sharing all the necessary resources
 In a multitasking env’t, totality of the computer’s resources (memory,

Intro to Distributed System


files, CPU time) are allocated to d/t applications, and each one of
them gets a share according to specific priority policies
 The processor operates at speeds that make it seem as though all of
the user's tasks are being performed at the same time.
 This is achieved by allowing each task to run for a short while and
then interrupting it, saving its machine registers’ contents, loading
registers with the data for the next task, and continuing processing 8
What is Multitasking?

Intro to Distributed System


What is Multitasking?

Intro to Distributed System


10
What is Thread?
 Threads are quite useful for DS applications and many systems
interact using a client/server model of communication where a
server process listens for client requests, executes them and
returns the results
 If the server was operating as a sequential process and

Intro to Distributed System


attempting to support multiple client requests then two or more
simultaneous requests would have to be executed serially by the
server process
 This would keep a number of buffered unanswered requests
waiting indeterminately until the server finished with earlier
ones and the outstanding requests may timeout giving the client
the impression that the server has fail. 11
Why use Thread?
 Large multiprocessors/multi-core systems need many
computing entities (one per CPU or core )
 Switching between processes incurs high overhead
 With threads, an application can avoid per-process
overheads

Intro to Distributed System


• Thread creation, deletion, switching cheaper than
processes
 have full access to address space (easy sharing)
 can execute in parallel on multiprocessors
12
Benefits of Threads
 Single-thread process
 process as a whole is blocked whenever a blocking system call is
executed
 For example, a spreadsheet program

 Multithreading

Intro to Distributed System


 Becomes possible to exploit parallelism
 Useful in the context of large applications
 One application, several cooperating programs, each to be executed by a
separate process.
 Inter-process communication (IPC) is needed if cooperating programs
are implemented.

13
Important Implications
 Two Important Implications:
1. Threaded applications often run faster than non-threaded
applications (as context-switches between kernel and user-
space are avoided)

Intro to Distributed System


2. Threaded applications are harder to develop (although
simple, clean designs can help here)
 Additionally, the development environment provides a
Threads Library for developers to use (most modern
environments do).
14
Multithreading
 Multithreading – a technique in which a program (process) is
divided into two or more subprograms (subprocesses), each of
which can perform different tasks simultaneously
 Each subprogram of a program is called thread in Java
 E.g., program has 3 threads, one and two (ThreadA & ThreadB) other
 Two threads are created and started from the main thread

Intro to Distributed System


 Once initiated by the main thread, ThreadA and ThreadB run
simultaneously and share the resources together
 When program contains >1 thread, CPU can switch b/n
two threads to execute them at same time
 Switching b/n 2 threads is known as Context Switch
 Switching occurs so fast that it appears to users that
all threads are being executed at the same time
 But in reality, only one thread is executed at a time 15
Multithreading
 Multithreading - improves performance of CPU by
maximum utilization and keeping the idle time of CPU to
minimum
 each thread is assigned a single task to perform and executes
independently

Intro to Distributed System


 If an exception occurs in one thread, it does not affect other
threads during the execution.
 For example,
 One thread - read data,
 Second thread - process it, and
 Third thread - write it
 Thus, improves the overall performance of an application
16
Why Thread in DS?
 An important property of threads is that they can provide a
convenient means of allowing blocking system calls without
blocking the entire process in which the thread is running.
 This makes threads particularly attractive to use in DS as it
makes it much easier to express communication in the form of
maintaining multiple logical connections at the same time

Intro to Distributed System


 Multithreaded In Clients and Servers side

 Attractive to use in DSs


 Multithreaded client
 Multithreaded server
17
Threads in Distributed Systems
Multithreaded Clients
 used to hide delays/latencies in network commns, by initiating
commn & immediately proceeding with something else
 Example: web browsers such as IE are multi-threaded
 browser can display data before entire document is downloaded:

Intro to Distributed System


performs multiple simultaneous tasks
 While it is waiting or getting the content, other threads can do
something else (e.g., display incoming data, allow users to click
links, get different objects etc.) and in parallel
 Each thread sets up a separate connection with the server
 Uses blocking calls
 Allow blocking systems calls without blocking the entire process
 Advantage: connections can be setup to different sources 18
Threads in Distributed Systems
Multithreaded Servers
 server having more than one thread
 When a clients sends the requests, a threads is generated through
which a user can communicate with the server
 We need to generate multiple threads to accept multiple requests
from multiple clients at the same time

Intro to Distributed System


Multithreaded server organized in a dispatcher/worker model 19
Threads in Distributed Systems
Multithreaded Servers
 Three ways to construct a server
 Multi-threaded process: Blocking system calls with parallelism
improves performance
 Single-threaded server retains the ease and simplicity of blocking
system calls, no parallelism

Intro to Distributed System


 Finite-state machine achieves high performance through parallelism,
and uses non-blocking calls, thus is hard to program
Model characteristics
Blocking system call Threads Parallelism, blocking system calls
- blocks process
Single-threaded No parallelism, blocking system calls
execution until the processes
requested operation is
Finite-state machine Parallelism, non-blocking system calls
completed 20
Advantage of Thread
 Useful for Clients: if a client wants a file to be
replicated on multiple servers, it can have one thread
talk to each server.
 Handle Signals: such as interrupts from the keyboard

Intro to Distributed System


and instead of letting the signal interrupt the process,
one thread is dedicated full time to waiting for signals.
 Producer-Consumer Problems: are easier to
implement using threads because threads can share a
common buffer.
21
Advantage of Thread
 It is possible for threads in a single address space to run in
parallel, on different CPUs.
 Virtualization Allows: an application, and possibly also its
complete environment including the operating system, to
run concurrently with other applications, but highly

Intro to Distributed System


independent of the underlying hardware and platforms,
leading to a high degree of portability.
 Moreover, Virtualization: helps in isolating failures caused
by errors or security problems and It is an important concept
for distributed systems, and we pay attention to it in a
separate section 22
Why Do We Need Threads?
 Simplifying the Programming Model: Since many
activities are going on at once more or less independently
 They are Easier to create and destroy than processes:
since they do not have any resources attached to them.
 Performance Improves: By overlapping activities if

Intro to Distributed System


there is too much I/O; i.e., to avoid blocking when
waiting for input or doing calculations, say in a
spreadsheet.
 Real Parallelism: is possible in a multiprocessor system

23
Servers Designing Issue
 Server - a process implementing a specific service on behalf of a
collection of clients
 servers are organized to do one of two things:
 It waits for an incoming request from a client and subsequently
ensures that the request is taken care of, after which it waits for the
next incoming request
… wait … service … wait … service … wait …

Intro to Distributed System


 How to Organize Servers?
 Iterative server: server itself handles the request and, if necessary,
returns a response to the requesting client
 any new client requests must wait for previous request to complete
 Concurrent server: server does not handle the request itself, but
passes it to a separate thread or sub-process & it handles the request and
returns any results to the client;
 server is then free to immediately service the next client (i.e., there’s no
waiting, as service requests are processed in parallel). 24
 E.g. Multithreaded server
Servers Designing Issue
 Server states:
• Stateless server – does not keep information on the current
“connections” to the server, and can change its own state
without having to inform any client, E.g. Web Server
• Stateful server – information is maintained on the current
“connections” to the server, E.g. Advanced file servers, copies

Intro to Distributed System


of a file can be updated “locally”, then applied to the main
server (as it knows the state of things)
 Whether and how a server can be interrupted?
• For instance, a user may want to interrupt a file transfer, may be
it was the wrong file and let the client exit the application, this
will break the connection to the server, the server will tear down
the connection assuming that the client had crashed
25
Servers Designing Issue

 How do clients contact a server?


• Using endpoints/ports at the
machine where the server is

Intro to Distributed System


running
• Each server listens to a specific end
point:
• E.g., An HTTP server for the www
listen to TCP port 80

26
Code Migration
 Code Migration is when programs are moved from one
machine to another, often moving parts of its execution
environment along with it
 often used for load distribution, reducing network bandwidth,
dynamic customization, and mobile agents.

Intro to Distributed System


 increases scalability, improves performance, and provides
flexibility of the system
 Code migration in DSs took place in the form of process
migration in which an entire process was moved from one
machine to another
 overall system performance can be improved if processes are
moved from heavily-loaded to lightly-loaded machines 27
Reason for Code Migration
 To Improve Performance: move processes from heavily-
loaded to lightly-loaded machines (load balancing).
 To Reduce Communication: move a client application that
performs many database operations to a server if the
database resides on the server, then send only results to the

Intro to Distributed System


client.
 To Exploit Parallelism: copies of a mobile program (called
a mobile agent or a crawler as is called in search engines)
moving from site to site searching the Web.
 To have flexibility: by dynamically configuring distributed
28
systems.
Reason for 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

Intro to Distributed System


29
Models for Code Migration
 As in process migration, execution status of a program, pending
signals and other parts of the environment must be moved as
well
 Process consists of three segments according to Fugetta’s
framework:

Intro to Distributed System


• Code segment: part that contains the set of instructions that
make up the program that is being executed.
• Resource segment: contains references to external resources
needed by the process, such as file, printers, devices, other
processes, & so on
• Execution segment: used to store the current execution state of
a process, consisting of private data, the stack, and the program
counter 30
Models for Code Migration
 Weak mobility model: transfer only the code segment
• Feature: a transferred program is always started from its initial
state
• E.g. Java applets
• Comment: Simple implementation, but limited applicability

Intro to Distributed System


 Strong mobility model: code & state being transferred, the
execution segment can be transferred as well.
• Feature: execution restarts from the next statement
• E.g. D’ Agents
• Comment: very powerful, but hard to implement
31
Models for Code Migration
 Even for the upper two models, further distinction can be made
between sender and receiver-initiated migration
o In sender-initiated migration, migration is initiated at the
machine where the code currently resides or is being executed
o In receiver-initiated migration, the initiative for code migration

Intro to Distributed System


is taken by the target machine
o In the case of weak mobility, it also makes a difference if the
migrated code is executed by the target process, or whether a
separate process is started, e.g. Java applets sere executed in the
browser’s address space
o For strong mobility model, instead of moving a running process,
32
it can also be supported by remote cloning
Models for Code Migration

Intro to Distributed System


33
The End!
Questions, Ambiguities,

Intro to Distributed System


Doubts, … ???
34

You might also like