Chapter 3-Processes

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

Chapter 3 - Processes

Introduction
ƒ communication takes place between processes
ƒ a process is a program in execution
ƒ from OS perspective, management and scheduling of
processes is important
ƒ other important issues arise in distributed systems
ƒ multithreading to enhance performance by overlapping
communication and local processing
ƒ how are clients and servers organized and server design
issues
ƒ process or code migration for enhancing performance,
reducing communication, to exploit parallelism, and to
dynamically configure clients and servers
ƒ software agents that perform a task through cooperation
and agent technology

2
3.1 Threads and their Implementation
ƒ how are processes and threads related?
ƒ process tables or PCBs are used to keep track of processes
ƒ there are usually many processes executing concurrently
ƒ processes should not interfere with each other; sharing
resources by processes is transparent
ƒ this concurrency transparency has a high price; allocating
resources for a new process and context switching take time
ƒ a thread also executes independently from other threads;
but no need of a high degree of concurrency transparency
thereby resulting in better performance

3
ƒ threads can be used in both distributed and nondistributed
systems
ƒ Threads in Nondistributed Systems
ƒ a process has an address space (containing program text
and data) and a single thread of control, as well as other
resources such as open files, child processes, accounting
information, etc.
Process 1 Process 2 Process 3

three processes each with one thread one process with three threads

4
ƒ each thread has its own program counter, registers, stack,
and state; but all threads of a process share address space,
global variables and other resources such as open files, etc.

5
ƒ Threads take turns in running
ƒ Threads allow multiple executions to take place in the same
process environment, called multithreading
ƒ Thread Usage – Why do we need threads?
ƒ e.g., a wordprocessor has different parts for
ƒ interacting with the user
ƒ formatting the page as soon as changes are made
ƒ timed savings (for auto recovery)
ƒ spelling and grammar checking, etc.
1. Simplifying the programming model: since many
activities are going on at once more or less independently
2. They are easier to create and destroy than processes
since they do not have any resources attached to them
3. Performance improves by overlapping activities if there is
too much I/O; i.e., to avoid blocking when waiting for
input or doing calculations, say in a spreadsheet
4. Real parallelism is possible in a multiprocessor system
6
ƒ having finer granularity in terms of multiple threads per
process rather than processes provides better performance
and makes it easier to build distributed applications
ƒ in nondistributed systems, threads can be used with shared
data instead of processes to avoid context switching
overhead in interprocess communication (IPC)

context switching as the result of IPC


7
ƒ Thread Implementation
ƒ threads are usually provided in the form of a thread
package
ƒ the package contains operations to create and destroy a
thread, operations on synchronization variables such as
mutexes and condition variables
ƒ two approaches of constructing a thread package
a. construct a thread library that is executed entirely in user
mode (the OS is not aware of threads)
ƒ cheap to create and destroy threads; just allocate and
free memory
ƒ context switching can be done using few instructions;
store and reload only CPU register values
ƒ disadvantage: invocation of a blocking system call will
block the entire process to which the thread belongs
and all other threads in that process
b. implement them in the OS’s kernel
ƒ let the kernel be aware of threads and schedule them
ƒ expensive for thread operations such as creation and
deletion since each requires a system call 8
ƒ solution: use a hybrid form of user-level and kernel-level
threads, called lightweight process (LWP)
ƒ a LWP runs in the context of a single (heavy-weight) process,
and there can be several LWPs per process
ƒ the system also offers a user-level thread package for some
operations such as creating and destroying threads, for
thread synchronization (mutexes and condition variables)
ƒ the thread package can be shared by multiple LWPs

combining kernel-level lightweight processes and user-level threads 9


ƒ Threads in Distributed Systems
ƒ threads allow blocking system calls without blocking the
entire process; this means multiple logical connections
(communications) can be established at the same time
ƒ Multithreaded Clients
ƒ consider a Web browser; fetching different parts of a page
can be implemented as a separate thread, each opening its
own TCP connection to the server
ƒ each can display the results as it gets its part of the page
ƒ parallelism can also be achieved for replicated servers
since each thread request can be forwarded to separate
replicas
ƒ Multithreaded Servers
ƒ servers can be constructed in three ways
a. single-threaded process
ƒ it gets a request, examines it, carries it out to completion
before getting the next request
ƒ the server is idle while waiting for disk read, i.e., system
calls are blocking; other requests cannot be handled 10
b. threads
ƒ threads are more important for implementing servers
ƒ e.g., a file server
ƒ the dispatcher thread reads incoming requests for a file
operation from clients and passes it to an idle worker
thread
ƒ the worker thread performs a blocking disk read; in
which case another thread may continue, say the
dispatcher or another worker thread

a multithreaded server organized in a dispatcher/worker model 11


c. finite-state machine
ƒ if threads are not available
ƒ it gets a request, examines it, tries to fulfill the request
from cache, else sends a request to the file system; but
instead of blocking it records the state of the current
request and proceeds to the next request
ƒ but hard to program
ƒ Summary
Model Characteristics
Single-threaded process No parallelism, blocking system calls
Parallelism, blocking system calls
Threads
(thread only)
Finite-state machine Parallelism, nonblocking system calls
three ways to construct a server
ƒ read about virtualization (the illusion of having more
resources than we actually have): pages 79 - 82 12
3.2 Anatomy of Clients
ƒ Two issues: user interfaces and client-side software for
distribution transparency
a. User Interfaces
ƒ to create a convenient environment for the interaction of a
human user and a remote server; e.g. mobile phones with
simple displays and a set of keys
ƒ GUIs are most commonly used
ƒ The X Window System (or simply X) as an example
ƒ it has the X kernel: the part of the OS that controls the
terminal (monitor, keyboard, pointing device like a
mouse) and is hardware dependent
ƒ contains all terminal-specific device drivers through the
library called xlib

13
the basic organization of the X Window System
ƒ the window manager is a special application and is in charge
of the “look and feel” of the screen that is presented to users
ƒ for controlling the client remotely, compression may be
important to reduce bandwidth and latency; but
decompression by the client is required

14
b. Client-Side Software for Distribution Transparency
ƒ in addition to the user interface, parts of the processing
and data level in a client-server application are executed at
the client side
ƒ an example is embedded client software for ATMs, cash
registers, etc.
ƒ moreover, client software can also include components to
achieve distribution transparency
ƒ e.g., replication transparency
ƒ assume a distributed system with replicated servers; the
client proxy can send requests to each replica and a
client side software can transparently collect all
responses and passes a single return value to the client
application

15
transparent replication of a server using a client-side solution

ƒ location, migration, and relocation transparency can also be


handled using naming (see Chapter 5) and client
cooperation; e.g., when a server changes location, the client
software can be informed without the user knowing
ƒ access transparency and failure transparency in
communication (keep on trying) can also be achieved using
client-side software
16
3.3 Servers and Design Issues
3.3.1 General Design Issues
ƒ How to organize servers?
ƒ Where do clients contact a server?
ƒ Whether and how a server can be interrupted
ƒ Whether or not the server is stateless
a. How to organize servers?
ƒ Iterative server
ƒ the server itself handles the request and returns the
result
ƒ Concurrent server
ƒ it passes a request to a separate process or thread and
waits for the next incoming request; e.g., a
multithreaded server; or by forking a new process as
is done in Unix
17
b. Where do clients contact a server?
ƒ using endpoints or ports at the machine where the server
is running where each server listens to a specific
endpoint
ƒ how do clients know the endpoint of a service?
ƒ globally assign endpoints for well-known services; e.g.
FTP is on TCP port 21, HTTP is on TCP port 80
ƒ for services that do not require preassigned endpoints,
it can be dynamically assigned by the local OS
ƒ IANA (Internet Assigned Numbers Authority) Ranges
ƒ IANA divided the port numbers into three ranges

ƒ Well-known ports: assigned and controlled by IANA


for standard services, e.g., DNS uses port 53
18
ƒ Registered ports: are not assigned and controlled by IANA;
can only be registered with IANA to prevent duplication e.g.,
MySQL uses port 3306
ƒ Dynamic ports or ephemeral ports : neither controlled nor
registered by IANA
ƒ how can the client know endpoints that are not well-known?
two approaches
i. have a daemon running and listening to a well-known
endpoint; it keeps track of all endpoints of services on the
collocated server
ƒ the client will first contact the daemon which provides it
with the endpoint, and then the client contacts the
specific server

19
Client-to-server binding using a daemon
ii. use a superserver (as in UNIX) that listens to all endpoints
and then forks a process to take care of the request; this is
instead of having a lot of servers running simultaneously and
most of them idle

Client-to-Server binding using a superserver 20


c. 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
ƒ let the client exit the client application; this will break the
connection to the server; the server will tear down the
connection assuming that the client had crashed
or
ƒ let the client send out-of-bound data, data to be
processed by the server before any other data from the
client; the server may listen on a separate control
endpoint; or send it on the same connection as urgent
data as is in TCP
d. Whether or not the server is stateless
ƒ a stateless server does not keep information on the state
of its clients; for instance a Web server
ƒ soft state: a server promises to maintain state for a
limited time; e.g., to keep a client informed about
updates; after the time expires, the client has to poll
21
ƒ a stateful server maintains information about its clients;
for instance a file server that allows a client to keep a
local copy of a file and can make update operations
ƒ this may improve performance but requires a recovery
procedure in case of a server crash which is not the case
for a stateless server
3.3.2 Server Clusters
ƒ a server cluster is a collection of machines connected
through a network (normally a LAN with high bandwidth and
low latency) where each machine runs one or more servers
ƒ it is logically organized into three tiers

22
the general organization of a three-tiered server cluster

23
ƒ Distributed Servers
ƒ the problem with a server cluster is when the logical switch
(single access point) fails making the cluster unavailable
ƒ hence, several access points can be provided where the
addresses are publicly available leading to a distributed
server
ƒ e.g., the DNS can return several addresses for the same host
name

24
3.4 Code Migration
ƒ so far, communication was concerned on passing data
ƒ we may pass programs, even while running and in
heterogeneous systems
ƒ code migration also involves moving data as well: when a
program migrates while running, its status, pending signals,
and other environment variables such as the stack and the
program counter also have to be moved

25
ƒ Reasons for Migrating Code
ƒ 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
client
ƒ to exploit parallelism (for nonparallel programs): e.g., 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

26
ƒ to have flexibility by dynamically configuring distributed
systems: instead of having a multitiered client-server
application deciding in advance which parts of a program
are to be run where

the principle of dynamically configuring a client to communicate to a server;


the client first fetches the necessary software, and then invokes the
server 27
ƒ Models for Code Migration
ƒ code migration doesn’t only mean moving code; in some
cases, it also means moving the execution status of a
program, pending signals, and other parts of the execution
environment
ƒ a process consists of three segments: code segment (set of
instructions), resource segment (references to external
resources such as files, printers, ...), and execution segment
(to store the current execution state of a process such as
private data, the stack, the program counter)
ƒ alternatives for code migration
ƒ weak versus strong mobility
ƒ is it sender- or receiver-initiated
ƒ is it executed at the target process or in a separate
process (for weak mobility); migrate or clone process (for
strong mobility)

28
ƒ Weak Mobility
ƒ transfer only the code segment and may be some
initialization data; in this case a program always starts
from its initial stage, e.g. Java Applets
ƒ execution can be by
ƒ the target process (in its own address space like in
Java Applets) but the target process and local
resources must be protected (security) or
ƒ by a separate process; still local resources must be
protected (security)
ƒ in addition to security, the other issue is portability in
heterogeneous systems

29
ƒ Strong Mobility (or process migration)
ƒ transfer code and execution segments; helps to migrate a
process in execution; stop execution, move it, and then
resume execution from where it is stopped
ƒ can also be supported by remote cloning; having an
exact copy of the original process and running on a
different machine; executed in parallel to the original
process; UNIX does this by forking a child process
ƒ migration can be
ƒ sender-initiated: the machine where the code resides or
is currently running; e.g., uploading programs to a
server; may need authentication or that the client is a
registered one; e.g., crawlers to index Web pages
ƒ receiver-initiated: by the target machine; e.g., Java
Applets; easier to implement
ƒ in a client-server model, receiver-initiated (by the server)
is easier to implement since security issues are
minimized; if clients are allowed to send code (sender-
initiated), the server must know them since they may
access resources such as disk on the server; 30
ƒ Summary of models of code migration

alternatives for code migration

31
ƒ Migration and Local Resources
ƒ how to migrate the resource segment
ƒ not always possible to move a resource; e.g., a reference to
TCP port held by a process to communicate with other
processes; it should get a new port at the destination
ƒ Types of Process-to-Resource Bindings
ƒ Binding by identifier (the strongest): a resource is referred
by its identifier; the process requires that resource; e.g., a
URL to refer to a Web page or an FTP server referred by its
Internet (IP) address
ƒ Binding by value (weaker): when only the value of a
resource is needed; in this case another resource can
provide the same value; e.g., standard libraries of
programming languages such as C or Java which are
normally locally available, but their location in the file
system may vary from site to site
ƒ Binding by type (weakest): a process needs a resource of a
specific type; reference to local devices, such as monitors,
printers, ... 32
ƒ in migrating code, the above bindings cannot change, but the
references to resources can
ƒ how can a reference be changed? depends on whether the
resource can be moved along with the code, i.e., resource-to-
machine binding
ƒ Types of Resource-to-Machine Bindings
ƒ Unattached Resources: can be easily moved with the
migrating program (such as data files associated with the
program)
ƒ Fastened Resources: such as local databases and complete
Web sites; moving or copying may be possible, but very
costly
ƒ Fixed Resources: intimately bound to a specific machine or
environment such as local devices and cannot be moved
 we have nine combinations to consider

33
Resource-to machine binding
Unattached Fastened Fixed
By identifier MV (or GR) GR (or MV) GR
Process-to-
resource binding By value CP (or MV, GR) GR (or CP) GR
By type RB (or GR, CP) RB (or GR, CP) RB (or GR)

actions to be taken with respect to the references to local resources


when migrating code to another machine

ƒ GR: Establish a global system wide reference usually using a


URL; may sometimes be difficult, e.g., an image being edited
ƒ MV: Move the resource; if not shared by another process
ƒ CP: Copy the value of the resource
ƒ RB: Rebind process to a locally available resource

ƒ Exercise: for each of the nine combinations, give example


resources
34
ƒ Migration in Heterogeneous Systems
ƒ distributed systems are constructed on a heterogeneous
collection of platforms, each with its own OS and machine
architecture
ƒ heterogeneity problems are similar to those of portability
ƒ easier in some languages
ƒ for scripting languages the source code is interpreted
ƒ for Java an intermediary code is generated by the
compiler for a virtual machine
ƒ in weak mobility
ƒ since there is no runtime information, compile the source
code for each potential platform
ƒ in strong mobility
ƒ difficult to transfer the execution segment since there
may be platform-dependent information such as register
values; there are some suggested solutions

35
3.5 Software Agents and Agent Technology
ƒ a software agent is an autonomous unit (process) capable of
performing a task in collaboration (i.e., it communicates)
with other, possibly remote, agents
ƒ it is capable of reacting to, and initiating changes (proactive)
in its environment, possibly with users and other agents
ƒ a collaborative agent is an agent that forms part of a
multiagent system, in which agents seek to achieve some
common goal through collaboration; e.g., in arranging
meetings
ƒ a mobile agent is an agent having the capability to move
between different machines; e.g., to retrieve information
distributed across a large heterogeneous network such as
the Internet
ƒ an interface agent is an agent that assists an end user in the
use of one or more applications and has learning
capabilities (it is adaptive); e.g., those that bring buyers and
sellers together
36
ƒ an information agent is an agent that manages information
from different sources such as ordering and filtering; e.g. an
e-mail agent filtering unwanted mail from its owner’s
mailbox, or automatically distributing incoming mail into
appropriate subject-specific mailboxes
Common to
Property Description
all agents?
Autonomous Yes Can act on its own
Responds timely to changes in its
Reactive Yes
environment
Proactive Yes Initiates actions that affects its environment
Can exchange information with users and
Communicative Yes
other agents
Continuous No Has a relatively long lifespan
Mobile No Can migrate from one site to another
Adaptive No Capable of learning

some important properties by which different types of agents can be


distinguished 37
ƒ Agent Technology
ƒ we need support to develop agent systems; for instance a
middleware consisting of generally-used components of
agents in distributed systems
ƒ FIPA - Foundation for Intelligent Physical Agents - develops
a general model for software agents
ƒ agent platform: where agents are registered at, and operate;
provides basic services such as creating and deleting
agents, locating agents, interagent communication, ...; it
may include the following
ƒ agent management: keep track of the agents for the
associated platform; provides facilities for creating and
deleting agents, looking for the current endpoint for a
specific agent by providing a naming service to globally
and uniquely identify an endpoint
ƒ local directory service: where agents can look up what
other agents on the platform have to offer
ƒ agent communication channel (ACC): for agents to
communicate by exchanging messages in multiagent
38
systems
the general model of an agent platform

ƒ please visit http://www.fipa.org/ for more information on the


activities of FIPA

39
ƒ Agent Communication Languages (ACL)
ƒ ACL: an application-level protocol where communication
between agents takes place
ƒ a message has a purpose and content
ƒ purpose
ƒ to request a specific service
ƒ to respond to a request
ƒ to inform about an event
ƒ to propose during negotiation

40
Message purpose Description Message Content
INFORM Inform that a given proposition is true Proposition
Query whether a given proposition is
QUERY-IF Proposition
true
QUERY-REF Query for a given object Expression
CFP Ask for a proposal Proposal specifics
PROPOSE Provide a proposal Proposal
ACCEPT-
Tell that a given proposal is accepted Proposal ID
PROPOSAL
REJECT-
Tell that a given proposal is rejected Proposal ID
PROPOSAL
Action
REQUEST Request that an action be performed
specification
Reference to
SUBSCRIBE Subscribe to an information source
source

examples of different message types in the FIPA ACL, giving the purpose
of a message, along with the description of the actual message content
41
ƒ ACL messages consist of a header and the actual content
ƒ the header has different fields:
ƒ a field to identify the purpose of the message,
ƒ fields to identify the sender and the receiver,
ƒ a field to identify the language or encoding scheme for
the content (since an ACL does not prescribe the format
or language in which the message content is expressed),
ƒ a field to identify a standardized mapping of symbols to
their meaning called ontology (if no common
understanding of interpreting data)

42
ƒ e.g., to inform an agent about Dutch royalty relationships

Field Value
Purpose INFORM
Sender max@http://fanclub-beatrix.royalty-spotters.nl:7239
Header

Receiver elke@iiop://royalty-watcher.uk:5623
Language Prolog
Ontology genealogy
Content female(beatrix), parent(beatrix, juliana, bernhard)

simple example of a FIPA ACL message sent between two agents


using Prolog to express genealogy information

43

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