Title: Processes
1Processes
2Major topics in this chapter
- Communication takes place among processes.
- The concept of a process originates from the
field of operating systems where it is generally
defined as a program in execution. - Clients and servers are important processes in
distributed systems. - Multithreading is an important technique for
constructing client and server processes. - General-purpose object servers form the basic
means for implementing distributed objects. - Process migration -- moving processes between
different machines -- can help in achieving
scalability and in dynamically configuring
clients and servers. - A software agent is yet another type of process.
Multiagent systems consist of a collection of
equally-important software agents that
collectively attempt to reach a common goal.
3Threads
- The granularity of processes as provided by the
operating systems is too coarse to the
construction of efficient distributed
applications. - Operating systems use processes to achieve
concurrency transparency multiple independent
processes share the same CPU and other system
resources without inadvertently affecting the
correctness of each others behavior. - This concurrency transparency comes at a high
price - Process creation is expensive. The OS must
allocate a complete independent address space and
initialise memory segments by - zeroing a data segment,
- copying the associated program into a text
segment, and - setting up a stack segment for temporary data.
- Switching the CPU between processes is expensive
as well - saving CPU context (register values, program
counter, stack pointer, etc) - modifying registers for MMU and invalidating
address translation caches and - swapping processes between RAM and disk.
4Threads
- 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. - A thread is similar to a process in the sense it
can also be seen as the execution of a (part of
a) program. - In contrast to processes, a thread context often
consists of the CPU context, and no attempt is
made to achieve a high degree of concurrency
transparency concurrency control among multiple
threads in the same process is left entirely to
programmers. - Implications of the multithreading approach
- Potential performance gain.
- Development of multithreaded applications require
additional intellectual effort
5Thread Usage in Nondistributed Systems
In a single-threaded process, whenever a
blocking system call is executed, the process as
a whole is blocked.
- Context switching as the result of IPC
6Advantages of multithreading
- Blocking one thread does not block the whole
process, thus improving system efficiency. - It becomes possible to exploit parallelism when
executing the multithreaded program on a
multiprocessor system. - Inter-thread communication can be significantly
cheaper than IPC since there is no context switch
between user mode and kernel mode (which is very
expensive). - Many applications are simply easier to structure
as a collection of cooperating threads. - E.g., for a word processor, separate threads can
be used for handling user input, spelling and
grammar checking, document layout, index
generation, etc.
7Approaches of implementing threads
- A thread package contains operations to
- create and destroy threads, as well as
operations on - synchronisation variables, e.g. mutexes and
condition variables. - A user-level thread library has the advantage of
being cheap to create and destroy threads, to
switch thread context. A major disadvantage is
that invocation of a blocking system call will
block the entire process to which the thread
belongs (tricks exist to overcome those problems
but none of them are satisfactory) - OS kernel supported threads do not have these
troubles but there is a high price to pay
threads creation, deletion, synch., and context
switching will have to be carried out by the
kernel.
8Thread Implementation
- Combining kernel-level lightweight processes and
user-level threads.
9Multithreaded clients
- Threads have the property of allowing blocking
system calls without blocking the entire process.
This property makes threads particularly
attractive to distributed systems since its
property of makes it much easier to express
communication in the form of maintaining multiple
logical connections at the same time. - Developing a web browser as a multithreaded
client makes it easy to support the browsers
multiple concurrent activities - e.g., local display and multiple simultaneous
connections to the server. - If the server is replicated, downloading data via
multiple connections can be carried out in
parallel, thus improving performance.
10Multithreaded Servers (1)
Multithreading not only simplifies server
code but also makes it much easier to explore
parallelism to attain high performance.
- A multithreaded server organized in a
dispatcher/worker model.
11Multithreaded Servers (2)
- Three ways to construct a server.
12The X-Window System
A major task of most clients is to interact
with a human user and a remote server.
- The basic organization of the X Window System
13Client-Side Software for Distribution Transparency
- A possible approach to transparent replication of
a remote object using a client-side solution.
14Servers General Design Issues
3.7
- Client-to-server binding using a daemon as in DCE
- Client-to-server binding using a superserver as
in UNIX
15Other Design Issues
- Interrupting a Server
- Abruptly exit the client application, which will
automatically break the connection to the server,
which will eventually tear down the old
connection. - Use a separate server control endpoint to which
the client sends out-of-band data. - Send the out-of-band data using the same
connection through which the client is sending
the ordinary data. E.g., TCP. - Stateless servers do not keep information on the
state of its client. - A Web server is stateless.
- Stateful servers does maintain information on its
clients. - E.g., a file server may allow a client to keep a
local copy of a file (even for update). Such a
server needs to keep track of the relationship
between files and clients . This approach can
improve the performance of read and write
operations as perceived by clients.
16Object Servers
- An object server acts as a place where objects
live. - An object server does not provide a specific
service. - Specific services are provided by the objects
managed by the server. - Objects may share neither code nor data.
- Good for security and for different
implementations. - Objects of the same class may share code.
- More efficient.
- Policies of threading
- One thread one server
- One thread one object
- One thread per method invocation
- requires concurrency control inside objects
17Object Adapter (1)
- Organisation of an object server supporting
different activation policies.
18Object Adapter (2)
/ Definitions needed by caller of adapter and
adapter /define TRUEdefine MAX_DATA 65536 /
Definition of general message format /struct
message long source / senders identity
/ long object_id / identifier for the
requested object / long method_id /
identifier for the requested method /
unsigned size / total bytes in list of
parameters / char data / parameters as
sequence of bytes / / General definition of
operation to be called at skeleton of object
/typedef void (METHOD_CALL)(unsigned, char
unsigned, char) long register_object
(METHOD_CALL call) / register an object
/void unregister_object (long object)id) /
unregister an object /void invoke_adapter
(message request) / call the adapter /
- The header.h file used by the adapter and any
program that calls an adapter.
19Object Adapter (3)
typedef struct thread THREAD / hidden
definition of a thread / thread CREATE_THREAD
(void (body)(long tid), long thread_id)/
Create a thread by giving a pointer to a function
that defines the actual // behavior of the
thread, along with a thread identifier / void
get_msg (unsigned size, char data)void
put_msg(THREAD receiver, unsigned size, char
data)/ Calling get_msg blocks the thread
until of a message has been put into its //
associated buffer. Putting a message in a
thread's buffer is a nonblocking // operation.
/
- The thread.h file used by the adapter for using
threads.
20Object Adapter (4)
- The main part of an adapter that implements a
thread-per-object policy.
21Reasons for Migrating Code
- The principle of dynamically configuring a client
to communicate to a server. The client first
fetches the necessary software, and then invokes
the server.
22Models for Code Migration
- Alternatives for code migration.
23Migration and Local Resources
Resource-to machine binding
Process-to-resource binding
GR Establish system wide, global reference.
MV move resource CP copy the value of the
resource. RB rebind process to local resource
- Actions to be taken with respect to the
references to local resources when migrating code
to another machine.
24Migration in Heterogeneous Systems
3-15
- The principle of maintaining a migration stack to
support migration of an execution segment (strong
mobility) in a heterogeneous environment
25Overview of Code Migration in D'Agents (1)
proc factorial n if (n ? 1) return 1
fac(1) 1 expr n factorial expr n
1 fac(n) n fac(n 1) set number
tells which factorial to compute set machine
identify the target machine agent_submit
machine procs factorial vars number script
factorial number agent_receive receive
the results (left unspecified for simplicity)
- A simple example of a Tel agent in D'Agents
submitting a script to a remote machine (adapted
from gray.r95)
26Overview of Code Migration in D'Agents (2)
all_users machines proc all_users machines
set list "" Create an initially empty list
foreach m machines Consider all hosts in
the set of given machines agent_jump
m Jump to each host set users exec
who Execute the who command append
list users Append the results to the list
return list Return the complete list
when done set machines Initialize the set
of machines to jump toset this_machine Set to
the host that starts the agent Create a
migrating agent by submitting the script to this
machine, from where it will jump to all the
others in machines. agent_submit this_machine
procs all_users -vars machines -script
all_users machines agent_receive receive
the results (left unspecified for simplicity)
- An example of a Tcl agent in D'Agents migrating
to different machines where it executes the UNIX
who command (adapted from gray.r95)
27Implementation Issues (1)
- The architecture of the D'Agents system.
28Implementation Issues (2)
- The parts comprising the state of an agent in
D'Agents.
29Software Agents in Distributed Systems
- Some important properties by which different
types of agents can be distinguished.
30Agent Technology
- The general model of an agent platform (adapted
from fipa98-mgt).
31Agent Communication Languages (1)
- Examples of different message types in the FIPA
ACL fipa98-acl, giving the purpose of a
message, along with the description of the actual
message content.
32Agent Communication Languages (2)
- A simple example of a FIPA ACL message sent
between two agents using Prolog to express
genealogy information.