Resource and Process Management

Download as pdf or txt
Download as pdf or txt
You are on page 1of 98

 A resource can be a logical, such as a shared file, or

physical, such as a CPU (a node of the distributed


system).

 One of the functions of a DOS is to assign processes to


the nodes of the DS to optimize
 the resource usage,
 response time,
 network congestion, and
 scheduling overhead.
 There are 3 techniques for scheduling processes of a DS:
1) Task Assignment Approach, in which each submitted
process is viewed as a collection of related tasks and these
tasks are scheduled to suitable nodes to improve
performance.
2) Load-balancing approach, in which all the submitted
processes are distributed among the nodes of the system to
equalize the workload among the nodes.
3) Load-sharing approach, which simply attempts to
conserve the ability of the system to perform work by
assuring that no node is idle while processes wait for being
processed.
 The task assignment approach has limited applicability
to practical situations

 Since it works on the assumption that the characteristics


(e.g. execution time, IPC costs etc) of all the processes to
be scheduled are known in advance.
 No prior knowledge about the processes
 Dynamic in nature
 Quick decision making capability
 Balanced system performance and scheduling overhead
 Stability (Processor thrashing must be prevented [due to
migration, no node should be in idle state])
 Scalability
 Fault tolerance
 Assumptions:

1) A process has already been split up into tasks.

This split occurs along natural boundaries (such as a method),


so that each task will have integrity in itself and data transfers
among the tasks are minimized.

2) The amount of computation required by each task and


the speed of each CPU are known.

3) The cost of processing each task on every node is


known. This is derived from assumption 2.
 Assumptions:
4) The IPC costs between every pair of tasks is known.
 The IPC cost is zero for tasks assigned to the same node.

 This is usually estimated by an analysis of the static program.

 If two tasks communicate n times and the average time for each
inter-task communication is t, them IPC costs for the two tasks
is n * t.

5) Precedence relationships among the tasks are known.


6) Reassignment of tasks is not possible.
 Aim is to assign the tasks of a process to the nodes to achieve
the following goals:
◦ Minimization of IPC costs
◦ Quick turnaround time for the complete process
◦ A high degree of parallelism
◦ Efficient utilization of system resources in general

These goals often conflict.


◦ E.g., while minimizing IPC costs tends to assign all tasks of a process to
a single node, affects the efficient utilization of system resources.
◦ Quick turnaround time and a high degree of parallelism encourage
parallel execution of the tasks, the precedence relationship among the
tasks limits their parallel execution.
Note:

◦ in case of m tasks and q nodes, there are mq possible


assignments of tasks to nodes .

◦ In practice the actual number of possible assignments of


tasks to nodes may be less than mq due to the restriction
that certain tasks cannot be assigned to certain nodes
due to their specific requirements (e.g. need a certain
amount of memory or a certain data file).
 There are two nodes, {p1, p2} and six tasks {t1, t2, t3, t4, t5, t6}. There are
two task assignment parameters – the task execution cost (xtn the cost of
executing task t on node n) and the inter-task communication cost (cij the
inter-task communication cost between tasks i and j).
Inter-task communication cost Execution costs
t1 t2 t3 t4 t5 t6 Nodes
t1 0 6 4 0 0 12 p1 p2
t2 6 0 8 12 3 0 t1 5 10
t3 4 8 0 0 11 0 t2 2 
t4 0 12 0 0 5 0 t3 4 4
t5 0 3 11 5 0 0 t4 6 3
t6 12 0 0 0 0 0 t5 5 2
t6  4
Task t6 cannot be executed on node p1 and task t2 cannot be executed on
node p2 since the resources they need are not available on these nodes.
1) Arbitrary assignment, where tasks t1, t2, t3 are assigned to node p1 and
tasks t4, t5, t6 are assigned to node p2:
Execution cost, x = x11 + x21 + x31 + x42 + x52 + x62 = 5 + 2 + 4 + 3 + 2 + 4 = 20
Communication cost, c = c14 + c15 + c16 + c24 + c25 + c26 + c34 + c35 + c36
= 0 + 0 + 12 + 12 + 3 + 0 + 0 + 11 + 0 = 38.
Hence total cost = 58.

2) Optimal assignment, where tasks t1, t2, t3, t4, t5 are assigned to node p1
and task t6 is assigned to node p2.
Execution cost, x = x11 + x21 + x31 + x41 + x51 + x62
= 5 + 2 + 4 + 6 + 5 + 4 = 26
Communication cost, c = c16 + c26 + c36 + c46 + c56
= 12 + 0 + 0 + 0 + 0 = 12
Total cost = 38
Optimal assignments are found by first creating a static assignment
graph.
 In the graph, the weights of the edges joining nodes represent
inter-task communication costs.
 Add two nodes n1 and n2, which represent the processors p1 and
p2, respectively.
 For every node other than n1 and n2, add an arc from that node to
each of n1 and n2. The weight of the arc to n1 is the cost of
execution of the module by P2, and the weight of the arc to n2 is
the cost of executing the module on P1.
 Then by using the max-flow min-cut theorem, a minimum cutset
in this graph is determined (possible combinations are nt).
 A cutset is defined to be a set of edges such that when these edges
are removed, the nodes of the graph are partitioned into two
disjoint subsets such that nodes in one subset are reachable from n1
and the nodes in the other are reachable from n2.
 Each task node is reachable from either n1 or n2.
 The weight of a cutset is the sum of the weights of the edges in the
cutset.
 This sums up the execution and communication costs for that
assignment.
 An optimal assignment is found by finding a minimum-weight
cutset. This may be done by the use of network flow algorithms.
Communication Cost Execution Cost
t1 t2 t3 t4 p1 p2
t1 0 35 3 8 t1 31 4
t2 35 0 6 4 t2 1 5
t3 3 6 0 23 t3 2 4
t4 8 4 23 0 t4 3 23

Arbitrary Assignment - 1 Arbitrary Assignment - 2


t f(t) t f(t)
t1 p2 t1 p2
t2 p2 t2 p1
t3 p2 t3 p1
t4 p1 t4 p1

Find the optimal Assignment


 Processors in a system can be identified according to their
present load.
◦ Heavily loaded processors where enough jobs are waiting for
execution;

◦ Lightly loaded processors where less jobs are waiting;

◦ Idle processors which have no job to execute.

 The basic aim is to make every processor equally busy and


to finish the works approximately at the same time
 This can be achieved by the load balancing concept.
 Improves the performance of each node and hence the overall system
performance.

 It reduces the job idle time.

 Small jobs do not suffer from long starvation.

 It makes maximum utilization of resources.

 Response time becomes shorter.

 It gives higher throughput.

 It gives higher reliability.

 It has low cost but high gain.

 It gives extensibility and incremental growth.


Load-balancing algorithms

Static Dynamic

Deterministic Probabilistic Centralized Distributed

Cooperative Non-cooperative

A Taxonomy of Load-Balancing Algorithms


1
9
 Where, the processes are assigned to the processors at the
compile time, depending on the performance of the nodes.
 After the assignment of processes, no change or reassignment is
possible at the runtime.
 The total number of jobs in each node is fixed.
 The information about the node is not collected.
 The assignment job is done to the processing nodes on the basis
of the following factors:
1. Incoming time.
2. Extent of resource needed.
3. Mean execution time.
4. Inter-process communications.
Drawbacks:

 Information about the system and jobs must be known before the
execution.
 It is very difficult to estimate execution times of various parts of a
program accurately
 Communication delay may occur under different circumstances
 The assignment of jobs is done at the runtime and jobs are reassigned
at the runtime, depending upon the situation, that is, the load will be
transferred from heavily loaded nodes to lightly loaded nodes.

 Communication overhead occurs and becomes more when the


number of processors increases.
 Static algorithms use only information about the average
behavior of the system, ignoring the current state of the
system.
◦ simpler because there is no need to maintain state information of
process.
◦ static algorithms is limited by the fact that they do not react to the
current system state.
◦ Low performance compared to dynamic.
 Dynamic algorithms react to the system state that changes
dynamically
◦ Complex because they collect and react to system state information
◦ they do respond to system state and so are better able to avoid
those states with unnecessarily poor performance
◦ provide greater performance benefits
 Deterministic algorithms use the information about the
properties of the nodes and the characteristics of the processes
to be scheduled to allocate processes to nodes.

 The task assignment algorithms belong to this category.

 A probabilistic load-balancing algorithm uses information


regarding static attributes of the system to formulate simple
process placement rules.
◦ number of nodes, the processing capability of each node, the network
topology, and so on,

 The deterministic approach is difficult to optimize and costs


more to implement.

 The probabilistic approach is easier to implement but often


suffers from having poor performance.
 In a centralized algorithm, the responsibility of scheduling resides on
a single node.
◦ In the centralized approach, the system state information is collected at a
single node at which all scheduling decisions are made.

 In a distributed dynamic scheduling algorithm, the work involved in


making process assignment decisions is physically distributed
among the various nodes of the system.
◦ A distributed scheme does not limit the scheduling intelligence to 1 node.

◦ It avoids the bottleneck of collecting state information at a single node


and allows the scheduler to react quickly to dynamic changes in the
system.

◦ A distributed dynamic scheduling algorithm is composed of k physically


distributed entities e1, e2, ... , ek. Each entity is considered a local
controller.
 In non-cooperative algorithms, individual entities act as
autonomous entities and make scheduling decisions
independently of the actions of other entities.

 In cooperative algorithms, the distributed entities cooperate


with each other to make scheduling decisions.

◦ Cooperative algorithms are more complex and involve larger


overhead than non-cooperative ones.

◦ The stability of a cooperative algorithm is better than that of a


non-cooperative algorithm.
 Load estimation policy, which determines how to estimate the
workload of a particular node of the system

 Process transfer policy, which determines whether to execute a


process locally or remotely

 State information exchange policy, which determines how to


exchange the system load information among the nodes

 Location policy, which determines to which node a process


selected for transfer should be sent

 Priority assignment policy, which determines the priority of


execution of local and remote processes at a particular node

 Migration limiting policy, which determines the total number of


times a process can migrate from one node to another
 To decide the method to be used to estimate the workload of a
particular node.
◦ No completely satisfactory solution exists. Can be estimated based on
some measurable parameters.
◦ These parameters could include time dependent and node-dependent
factors such as:
 Total number of processes on the node at the time of load estimation
 Resource demands of these processes
 Instruction mixes of these processes
 Architecture and speed of the node's processor

◦ The true load could vary depending on the remaining service times for
those processes.

◦ For estimating a node's workload is the sum of the remaining service


times of all the processes on that node. (Issue is how to estimate the
remaining service time of the processes)
 No method is suitable for use as load estimation policies in
modern distributed systems since several processes (such as
mail and news daemons, window managers) exist permanently,
even on an idle node.

 Many of these processes wake up periodically, check to see if


there is anything that they have to do, and if not, go back to
sleep.

 The method for use as the load estimation policy in these


systems would be to measure the CPU utilization of the nodes.
 Central processing unit (CPU) utilization is defined as the
number of CPU cycles actually executed per unit of real time.

 The CPU utilization of a node can be measured by setting up a


timer to periodically observe the CPU state.
 Use the threshold policy to make this decision.
 The threshold value of a node is the limiting value of its workload
and is used to decide whether a node is lightly or heavily loaded.
◦ A new process at a node is accepted locally for processing if the
workload of the node is below its threshold value at that time.
◦ Otherwise, an attempt is made to transfer the process to a lightly
loaded node.
 The threshold value of a node may be determined by any of the
following methods:
◦ Static policy: each node has a predefined threshold value depending on
its processing capability.
◦ Dynamic policy: the threshold value of a node (ni) is calculated as a
product of the average workload of all the nodes and a predefined
constant (ci).
 For each node ni, the value of ci depends on the processing capability of that
node, relative to the processing capability of an other nodes.
 To select the destination node for the process's execution the
location policy of a scheduling algorithm is used.
 The main location policies are: Threshold, Shortest, Bidding.
Threshold: a destination node is selected at random and a
check is made to determine whether the transfer of the
process to that node would place it in a state that prohibits
the node to accept remote processes.
◦ If not, the process is transferred to the selected node, which must
execute the process regardless of its state when the process
actually arrives.
◦ On the other hand, another node is selected at random and
probed in the same manner.
◦ This continues until either a suitable destination node is found or
the number of probes exceeds a static probe limit Lp.
 Shortest: In this method, distinct nodes are chosen at
random, and each is polled in turn to determine its load.

◦ The process is transferred to the node having the minimum load


value.

◦ If none of the polled nodes can accept the process, it is executed


at its originating node.

◦ If a destination node is found and the process is transferred there,


the destination node must execute the process.

 Improvement: discontinue probing whenever a node with zero


load is encountered, since that node is guaranteed to be an
acceptable destination.
Bidding: In this method, the system is turned into a distributed
computational economy with buyers and sellers of services.

 Each node in the network is responsible for two roles with respect
to the bidding process: manager and contractor.
◦ The manager represents a node having a process in need of a location
to execute, and

◦ The contractor represents a node that is able to accept remote


processes.

 The manager broadcasts a request-for-bids message to all other


nodes in the system.
 Then the contractor nodes return bids to the manager node.
◦ The bids contain the processing capability, memory size, resource
availability of the contractor nodes.

 After received bids from the contractor nodes, the manager node
chooses the best bid and the process is transferred from the
manager node to the winning contractor node.
 The dynamic policies require frequent exchange of state
information among the nodes of the system.

 The proper selection of the state information exchange policy is


essential.

 The proposed load-balancing algorithms use one of the following


policies for this purpose:
◦ Periodic Broadcast
◦ Broadcast When State Changes
◦ On-Demand Exchange and Exchange by Polling
One of the following priority assignment rules may be used:

1. Selfish. Local processes are given higher priority than remote


processes (worst response time performance)

2. Altruistic. Remote processes are given higher priority than


local processes (best response time performance).

3. Intermediate. The priority of processes depends on the


number of local processes and remote processes at the
concerned node. If the number of local processes >= remote
processes, local processes are given higher priority than
remote processes. Otherwise, remote processes are given
higher priority than local processes (fall between above two).
One of the following two policies may be used:

1. Uncontrolled: In this case, a remote process arriving at a


node is treated just as a process originating at the node.
Therefore, under this policy, a process may be migrated any
number of times. This policy has the unfortunate property of
causing instability.

2. Controlled: To overcome the instability problem most


systems treat remote processes different from local
processes and use a migration count parameter to fix a limit
on the number of times that a process may migrate.
 For the proper utilization of the resources of a
distributed system, it is necessary and sufficient to
prevent the nodes from being idle while some other
nodes have more than two processes.

 Therefore this rectification is often called dynamic


load sharing instead of dynamic load balancing.
 Load Estimation Policies:
◦ To ensure that no node is idle while processes wait for service
at some other node, it is sufficient to know whether a node is
busy or idle.

 Process Transfer Policies


◦ Load-sharing algorithms are normally interested only in the
busy or idle states of a node, most of them employ the all-or-
nothing strategy.
 This strategy uses the single threshold policy with the threshold
value of all the nodes fixed at 1.

 That is, a node becomes a candidate for accepting a remote


process only when it has no process, and a node becomes a
candidate for transferring a process as soon as it has more than
one process.
 Location Policies:
◦ Sender-Initiated Location Policy: in which the sender node
of the process decides where to send the process
◦ Receiver-Initiated Location Policy: in which the receiver
node of the process decides from where to get the process

 State Information Exchange Policies


◦ Broadcast When State Changes: In this method, a node
broadcasts a StatelnformationRequest message when it
becomes either under loaded or overloaded.
◦ Poll When State Changes: In this method, when a node's
state changes, it does not exchange state information with
all other nodes but randomly polls the other nodes one by
one and exchanges state information with the polled nodes.
PROCESS MANAGEMENT

41
 The main goal of process management is to make the
best possible use of the processing resources of the
entire system by sharing them among all processes.

 Three important concepts to achieve this goal:


 Processor Allocation
 Process/Code Migration
 Threads

42
 Processor Allocation deals with the process of
deciding which process should be assigned to which
processor.

 Process Migration deals with the movement of a


process from its current location to the processor to
which it has been assigned.

 Threads deals with fine-grained parallelism for better


utilization of the processing capability of the system.

43
 Process Migration is the relocation of a process from its
current location to another location. This involves the
following steps:
 Selection of a process that should be migrated.
 Selection of the destination node.
 Actual transfer of the selected process to the destination node.

 A process may be migrated either before it starts executing


on its source node (non-preemptive process migration) or
during the execution (preemptive process migration).

 The first two steps are taken care of by the process migration
policy and the third step is taken care of by the process
migration mechanism.

44
Source Node Destination Node
Process P1 in
Time
Execution Execution
suspended

Freezing Transfer of control


time
Execution
resumed
Freezing time: It is the time
period for which the
execution of the process is Process P1 in
stopped for transferring its Execution
information to the
destination node.
Figure : Flow of execution of a migrating process
45
 Transparency:
 Object access level - access to objects (such as files and devices) by process
can be done in location-independent manner.
 System call and interprocess communication level - the communicating
processes should not notice if one of the parties is moved to another node,
system calls should be equivalent.
 Minimal interference (with process execution) - minimize
freezing time
 Minimal residual dependencies - a migrated process should not
continue to depend on its previous node once it has started
executing on its new node. Otherwise,
 The migrated process continues to impose a load on its previous node
 A failure or reboot of the previous node will cause the process to fail.

46
 Efficiency: the following costs should be kept to minimum.
 The time required for migrating a process
 The cost of locating an object (includes the migrated process)
 The cost of supporting remote execution once the process is
migrated
 Robustness
 the failure of a node other than the one on which a process is
currently running should not affect the accessibility or execution of
that process.
 Communication between Co-processes of a Job
 If a single job is distributed over several nodes, then these co-
processes must be able to directly communicate with each other
irrespective of their locations.

47
 The four major sub activities involved in process migration
are as follows:
1. Freezing the process on its source node and restarting on its
destination node

2. Transferring the process’s address space

3. Forwarding messages meant for the migrant process


4. Handling the communication between cooperating processes
that have been separated.

48
 The usual process of migration is to take a “snapshot” of the
process’s state on its source node and reinstate the snapshot on
the destination node.
 For this, at some point during migration,
 the process is frozen on its source node,
 its state information is transferred to its destination node,
 the process is restarted on its destination node using this state
information.

 Freezing the process means, the execution of the process is


suspended and all external interactions with the process are
deferred.

49
 Immediate and Delayed Blocking of the process
 Fast and slow I/O operations: Finish fast I/O
 Information about open Files: pointer
 Reinstating the process on its destination node

50
 Blocks the execution of the migrant process, postponing all
external communication
◦ immediate blocking - when not executing system call

◦ postponed blocking - when executing certain system calls

 Wait for I/O operations:


◦ wait for fast I/O before freezing the process: example disk I/O

◦ arrange to gracefully resume slow I/O operations at destination: terminal I/O,


network communication

 Takes a “snapshot” of the process state


◦ relocatable information - register contents, program counter, etc.

◦ 0pen files information - names, identifiers, access modes, current positions of


file pointers, etc.

 Transfers the process state to the destination

 Restarts the process on destination node


 Reinstating the process on its destination node
 On the destination node, an empty process state is created similar to
that allocated during process creation.

 The newly created copy of the process initially has a process identifier
different from the migrating process.

 This allows both the old and new copies to exist and be accessible at
the same time.

 If the process identifier of the new copy is different from its old copy,
the new copy’s identifier is changed to the original identifier before the
process starts executing on the destination node.

 After all the state of the migrating process has been transferred and
copied into the empty process state, the new copy of the process is
unfrozen and the old copy is deleted.

52
 The migration of a process involves the transfer of the following
information :
 Process’s state (the execution status (contents of registers),
scheduling information, information about main memory being
used by the process (memory tables), I/O states (I/O queue,
contents of I/O buffers, interrupt signals, etc.), a list of objects to
which the process has a right to access, process's identifier,
process's user and group identifiers, information about the files
opened by the process (such as the mode and current position of
the file pointer), and so on
 Process’s address space (code, data, and stack of the program)
 It is necessary to completely stop the execution of the migrant
process while transferring its state information.

53
 The process’s address space can be transferred to
the destination node either before or after the
process starts executing on the destination node
 The address space transfer mechanisms:
 Total freezing
 Pretransferring
 Transfer on Reference

54
 A process's execution is stopped while its address space is being
transferred
 It is simple and easy to implement.
 Its main disadvantage is that if a process is suspended for a long
time during migration, timeouts may occur, and if the process is
interactive, the delay is more.
 The address space is transferred while the process is still running on the
source node.
 Therefore, once the decision has been made to migrate a process, it
continues to run on its source node until its address space has been
transferred to the destination node.
 The remaining modified pages are retransferred after the process is
frozen for transferring its state information.
 In the pretransfer operation,
◦ the first transfer operation moves the entire address space and
takes the longest time, thus providing the longest time for
modifications to the program's address space to occur.
◦ The second transfer moves only those pages of the address space
that were modified during the first transfer, thus taking less
time and presumably allowing fewer modifications to occur
during its execution time.
◦ Then subsequent transfer operations have to move fewer and
fewer pages, finally converging to zero or very few pages, which
are then transferred after the process is frozen.

 The pretransfer operation is executed at a higher priority than


all other programs to prevent the other programs from
interfering with the progress of the pretransfer operation.
 This is based on the assumption that processes tend to use only a
small part of their address spaces while executing.
 The process 's address space is left behind on its source node, and a
page of the migrant process‘s address space is transferred from its
source node to its destination node only when referenced.
 In moving a process, it must be ensured that all pending, en-route,
and future messages arrive at the process's new location.
 The messages to be forwarded to the migrant process's new
location can be classified into the following:
Type 1: Messages received at the source node after the process's
execution has been stopped on its source node and the process's
execution has not yet been started on its destination node
Type 2: Messages received at the source node after the process's
execution has started on its destination node
Type 3: Messages that are to be sent to the migrant process from any
other node after it has started executing on the destination node

59
 Mechanisms used for message forwarding in existing DS are:
 Mechanism of Resending the Message: to handle messages
of all three types.
◦ In this method, messages of types 1 and 2 are returned to the
sender as not deliverable or are simply dropped, with the
assurance that the sender of the message is storing a copy of the
data and is prepared to retransmit it.
◦ Messages of type 3 are sent directly to the process's destination
node

 Origin Site Mechanism:


◦ Messages for a particular process are always first sent to its origin
site by using process identifier information.
◦ The origin site then forwards the message to the process's current
location.
 Link Traversal Mechanism:
◦ To redirect the messages of type 1, a message queue for the
migrant process is created on its source node and all the messages
of this type are placed in this message queue.

◦ After the process is established on the destination node, all


messages in the queue are sent to the destination node.

◦ To redirect the messages of types 2 and 3, a forwarding address


known as link is left at the source node pointing to the destination
node of the migrant process.
 Link Update Mechanism:
◦ During the transfer phase of the migrant process, the source node
sends link-update messages to the kernels controlling all of the
migrant process's communication partners.

◦ These link update messages tell the new address of each link held
by the migrant process.

◦ Messages of types 1 and 2 are forwarded to the destination node


by the source node and messages of type 3 are sent directly to the
process's destination node
 Different mechanisms used for handling co-processes:
 Disallowing separation of Coprocesses
1. By disallowing the migration of processes that wait for one or more
of their children to complete.
2. By ensuring that when a parent process migrates, its children
processes will be migrated along with it.
 Home Node or Origin Site concept
1. All communications between a parent process and its children
processes take place via the home node.
2. The message traffic & the communication cost increase considerably

63
 Reducing average response time of processes
 Speeding up individual jobs
 Gaining higher throughput
 Utilizing resources effectively
 Reducing network traffic
 Improving system reliability
 Improving system security

64
 Passing programs, even while they are being executed,
simplifies the design of a distributed system.
 Code migration in distributed systems took place in the form
of process migration in which an entire process was moved
from one machine to another.
 Moving a running process to a different machine is a costly
task. But it gives better performance.
 Performance can be improved when processes are moved from
heavily-loaded to lightly-loaded nodes.

65
 Eg., A client-server system in which the server manages a
huge database.
 If a client application needs to perform many database operations
involving large quantities of data, it may be better to ship part of
the client application to the server and send only the results across
the network.
 Otherwise, the network maybe swamped with the transfer of data
from the server to the client.
 In this case, code migration is based on the assumption that it
generally makes sense to process data close to where those
data reside.

66
 This same reason can be used for migrating parts of the server
to the client.
 Eg. In many interactive database applications, clients need to fill in
forms that are subsequently translated into a series of database
operations.
 Processing the form at the client side, and sending only the completed
form to the server, can avoid that a relatively large number of small
messages need to cross the network.
 Provides flexibility.
 The traditional approach to building distributed applications is to
partition the application into different parts, and decide in advance
where each part should be executed.
 If code can move between different machines, it becomes possible to
dynamically configure distributed systems. Eg., suppose a server
implements a standardized interface to a file system.

67
 Code migration can also help to improve performance by
exploiting parallelism.
 A typical example is searching for information in the Web.

 Simple to implement a search query in the form of a small


mobile program, called a mobile agent, that moves from site
to site.
 By making several copies of such a program, and sending each off
to different sites a linear speedup is achieved.

68
A process consists of three segments to migrate.
 The code segment is the part that contains the set of
instructions that make up the program that is being executed.
 The resource segment contains references to external resources
needed by the process, such as files, printers, devices, other
processes, and so on.
 An 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.

71
 1) Weak mobility:
 A characteristics feature of weak mobility is that a
transferred program is always started from its
initial state.
 Eg. Java applets
 2) Strong mobility
 A characteristics feature of strong mobility is that a
running process can be stopped, subsequently
moved to another m/c and then resume execution
where it left off.
 Eg. D’ Agents.
 3) Sender initiated migration
 In sender initiated migration, migration is initiated at the m/c
where code currently resides or is being executed.
 Eg. Sending a search program access the internet to a web
database server to perform the queries at that server.
 In contrast to process migration, cloning yields an exact copy
of files original process, but now running on a different m/c.
 The cloned process is executed in parallel to the original
process.
 In UNIX systems, remote cloning takes place by forking off a
child processes and letting that child continue on a remote
m/c.
 The benefit of cloning is that the model closely reassembles
the one that is already used in many applications.
 The only difference is that the closed process is executed on
a different m/c.
 In this sense, migration by cloning is a simple way to improve
distributed transparency.
 The weak mobility is to transfer only the code segment, along
with some initialization data.
 In systems that support strong mobility the execution segment
can be transferred as well.
 The characteristic feature of strong mobility is that a running process
can be stopped, subsequently moved to another machine, and then
resume execution where it left off.

 In sender-initiated migration, migration is initiated at the


machine where the code currently resides or is being executed.
 It is done when uploading programs to a compute server.

 In receiver-initiated migration, the initiative for code migration


is taken by the target machine.
75
 Code migration occurs between a client and a server, where the
client takes the initiative for migration.
 Securely uploading code to a server, as is done in sender-
initiated migration, often requires that the client has previously
been registered and authenticated at that server.
 Downloading code as in the receiver-initiated case, to the client
is done only for improving client-side performance.

76
 Weak mobility, also makes a difference if the migrated code is
executed by the target process, or whether a separate process is
started.
 Eg., Java applets are simply downloaded by a Web browser and are
executed in the browser's address space.
 The benefit of this approach is that there is no need to start a separate
process, thereby avoiding communication at the target machine.

 Strong mobility can be supported by remote cloning.


 Cloning yields an exact copy of the original process, but now running
on a different machine.
 The cloned process is executed in parallel to the original process.

77
 A finer granularity in the form of multiple threads of control per
process makes it much easier to build distributed applications and
to attain better performance.
 What is a process ? How are processes and threads related?
 In traditional operating systems the basic unit of CPU utilization is
a process. Each process has its own program counter, its own
register states, its own stack, and its own address space.
 Threads are a popular way to improve application performance
through parallelism.

78
 In operating systems with threads facility, the basic unit of CPU
utilization is a thread.
 In these operating systems, a process consists of an address
space and one or more threads of control

(a) Single-threaded process (b) multithreaded process.

A single threaded process corresponds to a process of a traditional OS


 Each thread of a process has its own program counter, its own
register states, and its own stack.
 But all the threads of a process share
◦ the same address space.
◦ the same global variables.
◦ the same set of operating system resources, such as open files, child
processes, signals, accounting information, and so on.

 Threads share a CPU in the same way as processes do. ie,


◦ on a uniprocessor, threads run in quasi-parallel (time sharing),
◦ on a shared-memory multiprocessor, as many threads can run simultaneously
as there are processors.

 Like traditional processes, threads can create child threads, can


block waiting for system calls to complete, and can change states
during their course of execution.
 At a particular instance of time, a thread can be in anyone of
several states: running, blocked, ready, or terminated.
 Due to these similarities, threads are often viewed as mini
processes.
 Threads are often referred to as lightweight processes and
traditional processes are referred to as heavyweight processes.
1. The overheads involved in creating a new process are considerably
greater than those of creating a new thread within a process.

2. Switching between threads sharing the same address space is


cheaper than switching between processes that have their own
address spaces.

3. Threads allow parallelism to be combined with sequential execution


and blocking system calls.

4. Resource sharing can be achieved more efficiently and naturally


between threads of a process than between processes because all
threads of a process share the same address space.
 Threads are provided in the form of a thread package.
 Package contains operations to create and destroy threads as well as
operations on synchronization variables such as mutexes and
condition variables.
 There are basically two approaches to implement a thread package.
1. To construct a thread library that is executed entirely in user mode.
2. To have the kernel be aware of threads and schedule them.

83
 Advantages of a user-level thread library
 Cheap to create and destroy threads, because all thread
administration is kept in the user's address space.
 Destroying a thread mainly involves freeing memory for the
stack, which is no longer used.
 Drawback of user-level threads
 The invocation of a blocking system call will immediately block
the entire process to which the thread belongs, and thus also all
the other threads in that process.
 These problems can be avoided by implementing threads in the
operating system's kernel.

84
 Kernel level implementation is costly since every thread operation
have to be carried out by the kernel, requiring a system call.

 Switching thread contexts may become as expensive as switching


process contexts.

 A solution lies in a hybrid form of user-level and kernel-level


threads, generally referred to as lightweight processes (LWP).

 An LWP runs in the context of a single (heavy-weight) process,


and there can be several LWPs per process.

 In addition to having LWPs, a system also offers a user-level


thread package offering the usual operations for creating and
destroying threads.
85
 The package provides facilities for thread synchronization, such as
mutexes (locked or unlocked) and condition variables (Wait and signal).
 The thread package is implemented entirely in user space i.e, all
operations on threads are carried out without intervention of the kernel.
Combining kernel-level lightweight processes and user-level threads.

86
 The thread package can be shared by multiple LWPs.
 Each LWP can be running its own (user-level) thread.
 Multithreaded applications are constructed by creating threads, and
subsequently assigning each thread to an LWP.
 The combination of (user-level) threads and LWPs works as follows:
 The thread package has a single routine to schedule the next thread.
 When creating an LWP (which is done by means of a system call), the
LWP is given its own stack, and is instructed to execute the scheduling
routine in search of a thread to execute.
 If there are several LWPs, then each of them executes the scheduler.

87
 The thread table, which is used to keep track of the current set of
threads, is shared by the LWPs.
 Protecting this table to guarantee mutually exclusive access is done
by means of mutexes that are implemented entirely in user space.
 Synchronization between LWPs does not require any kernel support.
 When an LWP finds a runnable thread, it switches context to that thread.
 Meanwhile, other LWPs may be looking for other runnable threads as
well.
 If a thread needs to block on a mutex or condition variable, it does the
necessary administration and eventually calls the scheduling routine

88
 When a thread does a blocking system call, execution changes from
user mode to kernel mode but still continues in the context of the
current LWP.

 At the point where the current LWP can no longer continue, the
operating system may decide to switch context to another LWP, which
also implies that a context switch is made back to user mode.

 The selected LWP will simply continue where it had previously left
off.

89
Advantages of LWPs in combination with user-level thread package
 Creating, destroying, and synchronizing threads is relatively cheap
and involves no kernel intervention at all.
 Provided that a process has enough LWPs, a blocking system call will
not suspend the entire process.
 There is no need for an application to know about the LWPs. All it
sees are user-level threads.
 LWPs can be easily used in multiprocessing environments, by
executing different LWPs on different CPUs.
Drawback: Need to create and destroy LWPs, which is just as
expensive as with kernel-level threads.

90
 For high degree of distribution transparency, distributed systems
that operate in wide-area networks need to conceal long
interprocess message propagation times.
 The round-trip delay in a wide-area network can easily be in the
order of hundreds of milliseconds or sometimes even seconds.
 The usual way to hide communication latencies is to initiate
communication and immediately proceed with something else.
 Eg.,Web browsers.

91
 Multithreading simplifies server code, and makes it much easier to
develop servers that exploit parallelism to attain high performance.
 Benefits of threads for writing server code: The organization of a file
server that occasionally has to block waiting for the disk.
 The file server normally waits for an incoming request for a file
operation, subsequently carries out the request, and then sends back
the reply.
 The dispatcher, reads incoming requests for a file operation. The
requests are sent by clients to a well-known end point for this server.
After examining the request, the server chooses an idle (i.e.,blocked)
worker thread and hands it the request.

92
A multithreaded server organized in a dispatcher/worker model.
 Threads and processes can be seen as a way to do more things at
the same time.
 They allow us to build (pieces of) programs that appear to be
executed simultaneously.
 On a single-processor computer, there is only a single CPU, only an
instruction from a single thread or process will be executed at a
time by rapidly switching between threads and processes, the
illusion of parallelism is created.
 The separation between having a single CPU and being able to
pretend there are more can be extended to other resources as well,
leading to what is known as resource virtualization

99
 Every (distributed) computer system offers a programming
interface to higher level software.
 There are many different types of interfaces, ranging from the
basic instruction set as offered by a CPU to the vast collection of
application programming interfaces that are shipped with many
current middleware systems.
 Virtualization deals with extending or replacing an existing
interface so as to mimic the behavior of another system.
 Virtualization can help a lot:
 the diversity of platforms and machines can be reduced by essentially letting
each application run on its own virtual machine.
 Provides a high degree of portability and flexibility.

10
0
(a) General organization between a program, interface, and system.
(b) General organization of virtualizing system A on top of system B.
 Computer systems generally offer four different types of
interfaces, at four different levels:
1. An interface between the hardware and software, consisting of
machine instructions that can be invoked by any program.
2. An interface between the hardware and software, consisting of
machine instructions that can be invoked only by privileged
programs, such as an operating system
3. An interface consisting of system calls as offered by an
operating system.
4. An interface consisting of library calls, generally forming what
is known as an application programming interface (API).

10
2
Virtualization can take place in two different ways.
1. Can build a runtime system that essentially provides an abstract
instruction set that is to be used for executing applications.
 Instructions can be interpreted ,but could also be emulated as is done for
running Windows applications on UNIX platforms.
 This typeof virtualization leads to call a process virtual machine,
i.e.,virtualization is done essentially only for a single process
2. To provide a system that is essentially implemented as a layer
completely shielding the original hardware, but offering the
complete instruction set of that same (or other hardware) as an
interface.
 It is possible to have multiple, and different operating systems run
independently and concurrently on the same platform.
 The layer is generally referred to as a virtual machine monitor (VMM).

10
3
Various interfaces offered by computer systems.
A process virtual machine, with multiple instances of (application, runtime)
combinations.
A virtual machine monitor, with multiple instances of (applications, operating
system) combinations.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy