chapter 3 · and then resume execution where it left off more powerful, but harder to implement(!)...

28
Chapter 3 1

Upload: others

Post on 07-Jun-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

Chapter 3

1

Page 2: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Communication takes place between processes(!)

� ProcessProcessProcessProcess – a program in execution (from an operating-system perspective)

� Important issues in distributed systems:Important issues in distributed systems:◦ Multithreading◦ Typical organization of clients and servers◦ Design issues for servers◦ General-purpose object servers◦ Code migration◦ Software agents

2

Page 3: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Having a finer granularity in the form of multiple multiple multiple multiple threads threads threads threads of control per process per process per process per process makes it much easier to build distributed applications and to attain better performance

� To execute a program, an operating system creates a number of virtual processors, each one for running a different programdifferent program

� Process tableProcess tableProcess tableProcess table – contains entries to store CPU register values, memory maps, open files, privileges, etc.

� Switching the CPU between processes is expensive(!) – the operating system has to:◦ Save CPU context (register values, program counter, stack

pointer)◦ Modify registers of memory management unit (MMU)◦ Invalidate address translation caches (i.e. TLB)◦ Swap processes between main memory and disk

3

Page 4: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� ThreadThreadThreadThread – it can be seen as the execution of a (part of a) program on a virtual processor

� Thread contextThread contextThread contextThread context – consists of nothing more than the CPU context ◦ NOTE: Protecting data against inappropriate access by threads

within a single process is left entirely to application developers

� Benefits:◦ In a single-threaded process, whenever a blocking call is

executed, the process as a whole is blocked (e.g. update of executed, the process as a whole is blocked (e.g. update of dependent cells in a spreadsheet program)

◦ In a multiprocessor system each thread can be assigned to a different CPU◦ Instead of using processes (IPC requires kernel intervention), an

application can be constructed such that different parts are executed by separate threads� Communication is entirely dealt with by using shared data

◦ Software engineering reason – easier to structure an application as a collection of cooperating threads� Example: word processor – user input, spelling and grammar checking,

document layout, index generation, etc.

4

Page 5: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Context switching as the result of IPC

5

Page 6: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� UserUserUserUser----level threads level threads level threads level threads ◦ Cheap to create and destroy threads – all the

administration is kept in the user’s address space◦ Switching thread context can be done in just a few

instructions� Only values of CPU registers need to be stored and � Only values of CPU registers need to be stored and

subsequently reloaded

◦ Major drawback: invocation of a blocking system call will immediately block the entire process to which the thread belongs(!)

� Solution: lightweight processes (LWP)lightweight processes (LWP)lightweight processes (LWP)lightweight processes (LWP) – hybrid form of user-level and kernel-level threads

6

Page 7: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Combining kernel-level lightweight processes and user-level threads.

7

Page 8: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Creating a LWP is done by means of a system call

� LWP is given its own stack, and is instructed to execute a scheduling routine in search of a thread to execute

� When an LWP finds a runnable thread, it switches context to that threadcontext to that thread

� If a thread does a blocking system call, execution changes from user to kernel mode, but still continues in the context of the current LWP

� If the LWP can no longer continue, the OS may decide to switch context to another LWP, and then back to user mode

8

Page 9: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Typical example: developing a WEB browser as a multithreaded application◦ As soon as the main HTML code has been fetched,

separate threads can be activated to take care of fetching the other parts

◦ Each thread sets up a different TCP/IP connection to the server and pulls the data

◦ Connections may be set up to different replicas of a Web server, allowing data to be transferred in parallel

9

Page 10: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� A multithreaded server organized in a dispatcher/worker model.

10

Page 11: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

Model Characteristics

Threads Parallelism, blocking system calls

Single-threaded process No parallelism, blocking system calls

Finite-state machine Parallelism, nonblocking system calls

� Three ways to construct a server� Finite-state machine model:◦ When a request comes in, the one and only thread examines it,

and sends a message to the disk◦ Instead of blocking, the server records the state of the current

request in a table and than goes and gets the next message� If it is a new work, that work is started� If it is a reply from the disk, the relevant information is fetched from

the table and the reply is sent to the client

11

Page 12: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Iterative ServerIterative ServerIterative ServerIterative Server◦ The server itself handles a request and, if necessary,

returns a response to the requesting client

� Concurrent ServerConcurrent ServerConcurrent ServerConcurrent Server◦ The server passes the request to a separate thread or

another process, after which it immediately waits for the next incoming request (e.g. multithreaded server)

Where do clients contact a server?� Where do clients contact a server?◦ Each server listens to a specific endpoint (port)endpoint (port)endpoint (port)endpoint (port)◦ Endpoints for well-known services can be globally assigned

� Many servers do not require a pre-assigned endpoint◦ A) a special daemondaemondaemondaemon keeps track of the current endpoint of

each service implemented by a collocated server◦ B) a ““““superserversuperserversuperserversuperserver”””” listens to each endpoint associated with

a specific service and forks a process to take care of the request

12

Page 13: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

3.7

a) Client-to-server binding using a daemon as in DCE

b) Client-to-server binding using a superserver as in UNIX

13

Page 14: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Stateless serverStateless serverStateless serverStateless server◦ Does not keep information on the state of its clients, and

can change its state without having to inform any client ◦ Example: a Web server – responds to an incoming request,

and forgets the client completely

� StatefulStatefulStatefulStateful serverserverserverserver◦ Does maintain information on its clients(!)◦ Example: a file server – maintains a table containing (client, ◦ Does maintain information on its clients(!)◦ Example: a file server – maintains a table containing (client,

file) entries, which allows the server to keep track of which client currently has the update permission on which file

� A server may want to keep a record on a client’s behavior so that it can more effectively respond to its requests◦ CookieCookieCookieCookie – a small piece of data containing client-specific

information that is of interest to the server, and is transparently stored by the client’s browser

14

Page 15: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Object serverObject serverObject serverObject server – a server tailored to support distributed objects◦ Object server by itself does not

provide specific services – they are implemented by the objects that reside in the server

� Activation policyActivation policyActivation policyActivation policy - decision on how to invoke an objecthow to invoke an object

� Object adapter (object wrapper) Object adapter (object wrapper) Object adapter (object wrapper) Object adapter (object wrapper) – a mechanism to group objects per policy, i.e. a software implementing a specific activation policy

� Adapters are genericgenericgenericgeneric – they hand the invocation requests to a server-side stub of an object

15

Page 16: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Process migration – entire process is moved from one machine to another◦ Costly and intricate task◦ The basic idea is that overall system performance can be

improved if processes are moved from heavily-loaded to lightly-loaded machines

� In modern distributed systems, it is more important to minimize communicationminimize communication◦ Example: if a client application needs to do 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◦ Example: clients need to fill in forms that are subsequently

translated in a series of database operations – processing the form at the client side, and sending only the completed form to the server eliminates the large number of small messages that need to cross the network

� If code can move between different machines, it becomes possible to dynamically configure distributed systems

16

Page 17: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� The principle of dynamically configuring a client to communicate to a server. The client first fetches the necessary software, and then invokes the server.

17

Page 18: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� A process consists of three segments:◦ Code segment – the 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 (e.g. files, printers, devices, other processes, etc.)

◦ Execution segment – used to store the current execution state of a process (private data, the stack, program counter)

� Weak mobility� Weak mobility◦ Transfer only the code segment(!) – a transferred program is

always started from its initial state (e.g. Java applets)◦ Requires only that the target machine can execute that code

(portable code)

� Strong mobility◦ The execution segment can be transferred as well◦ A running process can be stopped, moved to another machine,

and then resume execution where it left off◦ More powerful, but harder to implement(!)◦ Can be supported by remote cloning

18

Page 19: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Sender-initiated migration◦ Migration is initiated at the machine where the code

currently resides or is being executed (e.g. uploading programs to a compute server)

� Receiver-initiated migrationReceiver-initiated migration◦ The initiative for code migration is taken by the

target machine (e.g. Java applets)

19

Page 20: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Alternatives for code migration.

20

Page 21: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Three types of process-to-resource binding:◦ Binding by identifier – a process uses a URL to refer to a

specific Web site, or an FTP server by means of that server’s Internet address◦ Binding by value – a program relies on standard libraries, and

such libraries should always be locally available◦ Binding by type – a process indicates it needs only a resource

of a specific type (references to local devices, such as of a specific type (references to local devices, such as monitors, printers, etc.)

� Unattached resources – can be easily moved between machines (e.g. files associated only with the program that is to be migrated)

� Fastened resources (e.g. local databases, complete Web sites)

� Fixed resources – bound to a specific machine or environment and cannot be moved

21

Page 22: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

Unattached Fastened Fixed

By identifier

By value

MV (or GR)

CP ( or MV, GR)

GR (or MV)

GR (or CP)

GR

GR

Resource-to machine binding

Process-to-resource

� 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

◦ MV – move the resource

◦ CP – copy the value of the resource

◦ RB – Rebind process to a locally available resource

By value

By type

CP ( or MV, GR)

RB (or GR, CP)

GR (or CP)

RB (or GR, CP)

GR

RB (or GR)

resource binding

22

Page 23: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

3-15

� The principle of maintaining a migration stack (machine-independent) to support migration of an execution segment (strong mobility) in a heterogeneous environment

� The execution segment is highly dependent on the platform on which the process is being executed – migration can take place only when a next subroutine is called

23

Page 24: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Software agent Software agent Software agent Software agent – an autonomous process capable of reacting to, and initiating changes in, its environment, possibly in collaboration with users and other agents

� Some important properties by which different types of agents can be distinguished:

PropertyCommon to all agents?

Description

Autonomous Yes Can act on its own

Reactive Yes Responds timely to changes in its environment

Proactive Yes Initiates actions that affects its environment

Communicative YesCan exchange information with users and other

agents

Continuous No Has a relatively long lifespan

Mobile No Can migrate from one site to another

Adaptive No Capable of learning

24

Page 25: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� The general model of an agent platform (Foundation for Intelligent Physical Agents – FIPA)◦ Agents are registered at, and operate under the regime of

an agent platform, which provides the basic services needed for any multi-agent system� Management component – provides facilities for creating and

deleting agents, but also for looking up the current endpoint for deleting agents, but also for looking up the current endpoint for a specific agent (a naming service by which a globally unique identifier is mapped to a local communication endpoint)

� Local directory service – agents can look up what other agents on the platform have to offer� Agent provides descriptions of its services in terms of attribute

names, along with the value specific to that agent (“yellow pages”)

� Agent communication channel (ACC) – takes care of all communication between different agent platforms (exchanging messages)

25

Page 26: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� The general model of an agent platform (Foundation for Intelligent Physical Agents – FIPA)

26

Page 27: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

� Agents communicate by means of application-level communication protocol – agent communication language (ACL)agent communication language (ACL)agent communication language (ACL)agent communication language (ACL)

� Examples of different message types in the FIPA ACL

Message purpose Description Message Content

INFORM Inform that a given proposition is true Proposition

QUERY-IF Query whether a given proposition is true Proposition

QUERY-REF Query for a give object Expression

CFP Ask for a proposal Proposal specifics

PROPOSE Provide a proposal Proposal

ACCEPT-PROPOSAL Tell that a given proposal is accepted Proposal ID

REJECT-PROPOSAL Tell that a given proposal is rejected Proposal ID

REQUEST Request that an action be performed Action specification

SUBSCRIBE Subscribe to an information source Reference to source

27

Page 28: Chapter 3 · and then resume execution where it left off More powerful, but harder to implement(!) Can be supported by remote cloning 18. Sender-initiated migration Migration is initiated

Field Value

Purpose INFORM

Sender max@http://fanclub-beatrix.royalty-spotters.nl:7239

Receiver elke@iiop://royalty-watcher.uk:5623

� A simple example of a FIPA ACL message sent between two agents using Prolog to express genealogy information.

Language Prolog

Ontology genealogy

Content female(beatrix),parent(beatrix,juliana,bernhard)

28