36
Processes Chapter 3

Processes Chapter 3. Processes OS provides concurrency transparency of multiple processes (sharing CPU, memory) High price Process creation Context

Embed Size (px)

Citation preview

Page 1: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Processes

Chapter 3

Page 2: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Processes OS provides concurrency transparency of multiple

processes (sharing CPU, memory) High price

Process creation Context switch

Difference between Processes and Threads? Thread context includes only CPU context Using thread, no concurrency transparency anymore! Multithreading improves performance

Page 3: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Thread Usage in Nondistributed Systems

Context switching as the result of IPC

Page 4: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

User-level thread or kernel thread User-level threads

Cheap to create/destroy Thread context switch is efficient, e.g., the values of CPU registers Drawback: block the process to which the thread belongs when

calling a (synchronous) system call Kernel-level threads

Do not have such a drawback Drawback: expensive in thread operations (create, destroy,

synchronization). Context switching is as expensive as process context switching

Solution? Lightweight processes (LWP): hybrid of user-level and kernel-

level threads

Page 5: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Thread Implementation

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

Page 6: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Threads in Distributed Systems Property of threads: allowing blocking system calls without

blocking the entire process in which the thread is running. Multithreaded Clients

Hide communication latencies Example: Web browser ?

Multithreaded Servers Simplify server code Exploit parallelism, high performance

Page 7: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Multithreaded Servers (1)

A multithreaded server organized in a dispatcher/worker model.

Page 8: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Multithreaded Servers (2)

Three ways to construct a server.

Model Characteristics

Threads Parallelism, blocking system calls

Single-threaded process No parallelism, blocking system calls

Finite-state machine Parallelism, nonblocking system calls

Page 9: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Clients

Page 10: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

The X-Window System

The basic organization of the X Window System

Page 11: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Client-Side Software for Distribution Transparency

A possible approach to transparent replication of a remote object using a client-side solution.

Page 12: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Servers: General Design Issues Iterative servers or concurrent servers (fork,

threading)

Page 13: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Servers: General Design Issues

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

3.7

Page 14: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Servers: General Design Issues Stateless servers or stateful servers? Stateless servers

Do not keep info on the state of the clients Do not inform the clients when changing its state Example: Web server

Stateful servers In contrast with stateless servers May better performance But if crash, need to recover the client states, complexity Unscalable Cookie: a solution

Page 15: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Servers Definition: a server to support distributed objects

The server itself does not provide a specific service It provides only the means to invoke local objects that implement

the services

Objects Data represents its state Coding forms the implementation of its methods/services

How to invoke objects Only one way to invoke objects: that provide same interface Different policies to invoke different objects: created on-demand

or precreated objects Each object has a thread v.s. each invocation request corresponds to a

thread? (threading, concurrent access control)

Page 16: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter Definition: A mechanism to group objects by policies, or a

software implementing a specific activation policy Generic components, for each policy

Unaware of the specific interfaces of the objects it wraps

Actions Extracts an object reference from an invocation request Dispatches the request to the referenced objects (via the server-

side stub of the object) Sends back the response message

Page 17: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter (1)

Organization of an object server supporting different activation policies.

Page 18: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter (2)

The header.h file used by the adapter and any program that calls an adapter.

/* Definitions needed by caller of adapter and adapter */#define TRUE 1#define 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 unrigester_object (long object)id); /* unrigester an object */void invoke_adapter (message *request); /* call the adapter */

Page 19: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter (3)

The thread.h file used by the adapter for using threads.

Thread communications by buffers/message queues

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. */

Page 20: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter Implementation Implements a thread-per-object policy Buffers/Message queues as communication between

threads

Page 21: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Object Adapter (4)

The main part of an adapter that implements a thread-per-object policy.

Page 22: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Thinking and reflectionsThe concept of object adapters and buffers/MSG

queues as thread communications can be extended to support concurrent server designFront server: receive requests, put the requests into

corresponding thread’s MSG queues/buffersThread read requests, perform the functions and put the

response message into the front server’s queueFront server/Reply server writes back the message to the

clients

Page 23: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Code Migration Previous applications: move data Now: move code/program Reasons for migrating code

Move computation load, improve performance Reduce bandwidth cost by data transferring Flexibility: dynamically configure distributed system

Examples: Ship client application to the database server to reduce

the amount of data needed to be transferred Client-side downloads codes from server, such as filling

out a form at client-side

Page 24: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Reasons 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.

Page 25: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Implication of Code Migration Not ONLY code

Code segment Resource segment: needed by the process Execution segment: current execution state of the process

Weak mobility strong mobility Weak: only code segment which is portable Strong: a process stops, move to another environments

and resumes its execution. Powerful but hard to implement

Page 26: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Models for Code Migration

Alternatives for code migration.

Page 27: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Migration and Local Resources

Actions to be taken with respect to the references to local resources when migrating code to another machine.

Binding by identifier, by value and by type (rebinding the same type)

Unattached Fastened Fixed

By identifier

By value

By type

MV (or GR)

CP ( or MV, GR)

RB (or GR, CP)

GR (or MV)

GR (or CP)

RB (or GR, CP)

GR

GR

RB (or GR)

Resource-to machine binding

Process-to-resource

binding

Page 28: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Migration in Heterogeneous Systems

The principle of maintaining a migration stack to support migration of an execution segment in a heterogeneous environment. For procedural languages such as C and Java. Code migration is restricted to specific points (e.g., a subroutine is called) in the execution of the program. Migration stack

3-15

Page 29: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Overview of Code Migration in D'Agents (1)

A simple example of a Tel agent in D'Agents submitting a script to a remote machine (adapted from [gray.r95])

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)

Page 30: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Overview of Code Migration in D'Agents (2)

An example of a Tel agent in D'Agents migrating to different machines where it executes the UNIX who command (adapted from [gray.r95])

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)

Page 31: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Implementation Issues (1)

The architecture of the D'Agents system.

Page 32: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Implementation Issues (2)

The parts comprising the state of an agent in D'Agents.

Status Description

Global interpreter variables Variables needed by the interpreter of an agent

Global system variables Return codes, error codes, error strings, etc.

Global program variables User-defined global variables in a program

Procedure definitions Definitions of scripts to be executed by an agent

Stack of commands Stack of commands currently being executed

Stack of call framesStack of activation records, one for each running command

Page 33: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Software Agents in Distributed Systems

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

Page 34: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Agent Technology

The general model of an agent platform (adapted from [fipa98-mgt]).

Page 35: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Agent 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.

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 sourceReference to source

Page 36: Processes Chapter 3. Processes  OS provides concurrency transparency of multiple processes (sharing CPU, memory)  High price  Process creation  Context

Agent Communication Languages (2)

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

Field Value

Purpose INFORM

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

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

Language Prolog

Ontology genealogy

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