kyung hee university 1/57 communication chapter 3

59
1/57 Kyung Hee University Communication Chapter 3

Upload: hester-jones

Post on 12-Jan-2016

233 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Kyung Hee University 1/57 Communication Chapter 3

1/57

Kyung Hee University

Communication

Chapter 3

Page 2: Kyung Hee University 1/57 Communication Chapter 3

2/57

Kyung Hee University

Agenda

1-Threads (N.Q.Hung)

2-Clients (L.X.Hung)

3-Servers (L.X.Hung)

4-Code Migration (N.Q.Hung)

5-Software Agent (L.X.Hung)

Page 3: Kyung Hee University 1/57 Communication Chapter 3

3/57

Kyung Hee University

Chapter 3 Process

Part 1 THREAD

Page 4: Kyung Hee University 1/57 Communication Chapter 3

4/57

Kyung Hee University

Process at a glance

Page 5: Kyung Hee University 1/57 Communication Chapter 3

5/57

Kyung Hee University

Process

Process Control Block (PCB)

Page 6: Kyung Hee University 1/57 Communication Chapter 3

6/57

Kyung Hee University

Page 7: Kyung Hee University 1/57 Communication Chapter 3

7/57

Kyung Hee University

Thread

Page 8: Kyung Hee University 1/57 Communication Chapter 3

8/57

Kyung Hee University

Page 9: Kyung Hee University 1/57 Communication Chapter 3

9/57

Kyung Hee University

Page 10: Kyung Hee University 1/57 Communication Chapter 3

10/57

Kyung Hee University

Kernel-Level Threads

• Kernel is aware of and schedules threads

• A blocking system call, will not block all peer threads

• Expensive to manage threads

• Expensive context switch

• Kernel Intervention

• Maybe as expensive as using processes!!

Page 11: Kyung Hee University 1/57 Communication Chapter 3

11/57

Kyung Hee University

Light-Weight Processes (LWP)

• Support for hybrid (user-level and Kernel) threads

• A process contains several LWPs

• Developer: creates multi-threaded applications

• System: Maps threads to LWPs for execution

Page 12: Kyung Hee University 1/57 Communication Chapter 3

12/57

Kyung Hee University

Thread Implementation-LWP (1)

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

Page 13: Kyung Hee University 1/57 Communication Chapter 3

13/57

Kyung Hee University

Thread Implementation - LWP (2)

• Each LWP offers a virtual CPU

• LWPs are created by system calls

• They all run the scheduler, to schedule a thread

• Thread table is kept in user space

• Thread table is shard by all LWPs

• LWPs switch context between threads

Page 14: Kyung Hee University 1/57 Communication Chapter 3

14/57

Kyung Hee University

Thread Implementation - LWP (3)• When a thread blocks, LWP schedules another

ready thread

• Thread context switch is completely done in user-address space

• When a thread blocks on a system call,execution mode changes from user to kernel but continues in the context of the current LWP

• When current LWP can no longer execute, context is switched to another LWP

Page 15: Kyung Hee University 1/57 Communication Chapter 3

15/57

Kyung Hee University

LWP Advantages

• Cheap thread management

• A blocking system call may not suspend the whole process

• LWPs are transparent to the application

• LWPs can be easily mapped to different CPUs

• Managing LWPs is expensive (like kernel threads)

Page 16: Kyung Hee University 1/57 Communication Chapter 3

16/57

Kyung Hee University

Threads and Distributed Systems

• Important property of thread: a blocking system call will not block the entire process

• Very attractive to maintain multiple logical connections between many clients and a server

Page 17: Kyung Hee University 1/57 Communication Chapter 3

17/57

Kyung Hee University

Multi-Threaded Clients

• High propagation delay in big networks• WAN: a round trip delay ~ seconds• To hide this delay, use threads• Initiate communication by a separate thread• Example: Web browsers• Separate connection for each page

component (HTML file, image, audio…)• Better: if server is horizontally distributed,

data will be transferred in parallel

Page 18: Kyung Hee University 1/57 Communication Chapter 3

18/57

Kyung Hee University

Multi-Threaded Servers (1)

• Much more Important than multi-threaded clients

• Not only simplifies server code, but also boosts server performance (exploit parallelism)

• It is common to have multiple-CPU (Multiprocessor) server machines

• Example: File Server (fig)

Page 19: Kyung Hee University 1/57 Communication Chapter 3

19/57

Kyung Hee University

Multithreaded Servers (2)

A multithreaded server organized in a dispatcher/worker model.

Page 20: Kyung Hee University 1/57 Communication Chapter 3

20/57

Kyung Hee University

Multithreaded Servers (3)

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

Back to Agenda

Page 21: Kyung Hee University 1/57 Communication Chapter 3

21/57

Kyung Hee University

Clients and Servers

Page 22: Kyung Hee University 1/57 Communication Chapter 3

22/57

Kyung Hee University

Clients

Main role of clients is: to interact with human user and remote server

-User Interface (UI):

-Client-side software: UI + components for achieving transparent

Page 23: Kyung Hee University 1/57 Communication Chapter 3

23/57

Kyung Hee University

User InterfaceThe X-Window SystemGoalGenerally is used to control bit-mapped terminals (include a monitor, keyboard,

mouse) (or a part of OS that controls the terminal)

X-kernel: -Contains all terminal-specific devices

-Offer relative low-level interface for controlling the screen

-Capturing evens from the keyboard and mouse

Comprise 4 major components: -X Servers: Managing the screen, mouse and keyboard -> interact with the user

-X Clients: The application (where the real work gets done )

-X Protocol: Client/server communication

-X Library: The Programming interface

Page 24: Kyung Hee University 1/57 Communication Chapter 3

24/57

Kyung Hee University

User Interface

The basic organization of the X Window System

The X-Window System

Page 25: Kyung Hee University 1/57 Communication Chapter 3

25/57

Kyung Hee University

Client-Side Software for Distribution Transparency

-UI is a small part of the client-side S/W

-Client S/W includes:

+Local processing

+Communication facilities: distribution transparency

+Replication transparency (next slide)

+Access transparency: client stub

+Location, migration, relocation transparency: naming

+Failure transparency

Page 26: Kyung Hee University 1/57 Communication Chapter 3

26/57

Kyung Hee University

Client-Side Software for Distribution Transparency

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

Common interface

to Service

Client orServer side

Page 27: Kyung Hee University 1/57 Communication Chapter 3

27/57

Kyung Hee University

Servers

Page 28: Kyung Hee University 1/57 Communication Chapter 3

28/57

Kyung Hee University

Servers: General Design Issues

1-Organize of server?

2-How client contacts with server?

3-Whether and how a server can be interrupt?

4-Stateful or Stateless server?

Page 29: Kyung Hee University 1/57 Communication Chapter 3

29/57

Kyung Hee University

Servers: General Design Issues1-Organize of server?

-Iterative server (sequential server): itself handle the request and return a response to the request.

-Concurrent server: does not handle the request but passes it into threads (Ex multithreads server)

Page 30: Kyung Hee University 1/57 Communication Chapter 3

30/57

Kyung Hee University

Servers: General Design Issues2-How client contacts with server?

Way: Clients send the request to the endpoint (port) of the server

•Approach 1: Endpoint is assigned with the well-know service (Ex: FPT request listen to port 21, HTTP: port 80)

•Approach 2: Not preassigned endpoint (next slice)

•Solution 1: Each server has a special daemon to keep tracks of the current endpoint of each service (Ex: DCE)

•Solution 2:Using a single SuperServer (inetd in UNIX)

Page 31: Kyung Hee University 1/57 Communication Chapter 3

31/57

Kyung Hee University

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 32: Kyung Hee University 1/57 Communication Chapter 3

32/57

Kyung Hee University

Servers: General Design Issues3- Whether and how a server can be interrupt? • Approach 1:

Client suddenly exits the application and restarts it immediately     server thinks the client had crashed and will tear down the connection.

• Approach 2 (better):Send out-of-band data (which is process by the server before any other client data)-Solution 1: Out-of-band data is listened by separated endpoint.-Solution 2: Out-of-band data is sent across the same connection with urgent

Page 33: Kyung Hee University 1/57 Communication Chapter 3

33/57

Kyung Hee University

Servers: General Design Issues4- Stateful or Stateless server?

Stateless server:-Does not keep information on the state of its clients.-Can change it own state without having to inform any client.Ex: Web server

Stateful server: -Does maintain information on its clients.Ex: File server

Page 34: Kyung Hee University 1/57 Communication Chapter 3

34/57

Kyung Hee University

Object Servers-Tailored for distributed objects support

-Provides environment for objects-Not a service by itself (government)

-Services are provided by objects

-Easy to add services (by adding Objects)

Object

Data Code (methods)

Object server

Object Object

Object

Page 35: Kyung Hee University 1/57 Communication Chapter 3

35/57

Kyung Hee University

Invoking Objects

The Object Server is needed to know:-Which code is execute?

-On which data is should operate?

Page 36: Kyung Hee University 1/57 Communication Chapter 3

36/57

Kyung Hee University

Invoking ObjectsActivation Policies• Decisions on how to invoke objects• All objects are alike

– Inflexible

• Objects differ and require different policies– Object type– Memory allocation– Threading

Page 37: Kyung Hee University 1/57 Communication Chapter 3

37/57

Kyung Hee University

• Create at the first invocation request and destroy when clients are no longer bound to it

• Create all transient objects when server is initialized

• Server resources?

• Invocation time?

Transient Objects

Page 38: Kyung Hee University 1/57 Communication Chapter 3

38/57

Kyung Hee University

• Each object has its own memory segment

• Objects can share memory segments

• Security?

• Memory resources?

Memory Allocation

Page 39: Kyung Hee University 1/57 Communication Chapter 3

39/57

Kyung Hee University

• One thread in the server

• Several threads in the server

• Separate thread for each object

• Separate thread for each request

• Concurrent access?

Threads

Page 40: Kyung Hee University 1/57 Communication Chapter 3

40/57

Kyung Hee University

• A S/W implementation of an activation policy

• Generic to support developers

• Group objects per policy

• Several objects under an adapter

• Several adapters under a server

Object Adapters (Wrappers)

Page 41: Kyung Hee University 1/57 Communication Chapter 3

41/57

Kyung Hee University

Organization of an object server supporting different activation policies.

Object Adapters (Wrappers)

Back to agenda

Page 42: Kyung Hee University 1/57 Communication Chapter 3

42/57

Kyung Hee University

Chapter 3 Process

Part 4. Code migration

Page 43: Kyung Hee University 1/57 Communication Chapter 3

43/57

Kyung Hee University

Code Migration

• Code Migration = moving processes between machines

• Process = 3 segmentsText segment (the code)Resource segment (refs to external resources {files,

printers, devices, other processes, etc})Execution segment (state of a process {stack,

program counter, registers, private data…)

Page 44: Kyung Hee University 1/57 Communication Chapter 3

44/57

Kyung Hee University

Why migrate code? (1)

Main Reason: Better performance of

overall system

Page 45: Kyung Hee University 1/57 Communication Chapter 3

45/57

Kyung Hee University

Why migrate code? (2)Load-Balancing (for multiprocessors)

Move process from over-utilized to under-utilized CPU

Minimizing Communication CostsExploiting parallelism

Examples: • client application needs to do many database operations

involving large quantities of data => ship part of the client application to the server

• Interactive database applications: client needs to fill in forms => ship part of the server application to the client

• Searching information in the Web by a small mobile prog. => send some copies of such a prog. off to different sites

Page 46: Kyung Hee University 1/57 Communication Chapter 3

46/57

Kyung Hee University

Why migrate code? (3)Besides improving performance: Flexibility

Clients need not have all the S/W pre-installed: download on demand, then dispose.

Remote object stub in Java

Java applets

Security: Can you trust any code? (both client & server)

Need a standardized protocol for downloading & initializing code

Guarantee that downloaded code can be executed

Page 47: Kyung Hee University 1/57 Communication Chapter 3

47/57

Kyung Hee University

Scenario of 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 48: Kyung Hee University 1/57 Communication Chapter 3

48/57

Kyung Hee University

Models for Code Migration

Alternatives for code migration.

Transfer only the code segment => simplicity

Execution segment can be transferred as well (running process can be stopped & moved to another machine to resume execution)

anonymous

Require registration & authentication at the serverEg: search prog., uploading

programs to a compute server•Process = 3 segments

Text segment (the code)

Resource segment (refs to external resources {files, printers, devices, other processes, etc})

Execution segment (state of a process {stack, program counter, registers, private data…)

Page 49: Kyung Hee University 1/57 Communication Chapter 3

49/57

Kyung Hee University

GR: Establish a global systemwide reference

MV: Move the Resource

CP: Copy the value of the resource

RB: Rebind process to locally available resource

Migration and Local Resources

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

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

Binding by identifier: e.g, uses a URL for Website or IP address for FTP server.

Binding by value: e.g, C or Java standard librariesBinding by type: local devices such as monitors, printers, …

Unattached resources: can easily moved between different machines, typically (data) files associated only with the program that is to be migrated. Fastened resources: eg, local databases, complete Websites (moveable but high costs)Fixed resources: local devices

Page 50: Kyung Hee University 1/57 Communication Chapter 3

50/57

Kyung Hee University

Migration in Heterogeneous SystemsRequirements:

Platform supported: code segment may be recompiled to be executed in new platform

Ensure the execution segment can be represented at each platform properly.

Solutions: Weak mobility: no runtime information needs to be transferred => just

recompile the source code Strong mobility: segment is highly dependent on the plaform => migration

stack: a copy of the program stack in a machine-independent way.(C, Java)

Scenario: Migration can take place only when a next subroutine is called. When subroutine is called: marshalled data are pushed onto the migration stack

along with identifier for the called subroutine & the return label Then all global program-specific data are also marshalled (current stack &

machine-specific data are ignored)

Page 51: Kyung Hee University 1/57 Communication Chapter 3

51/57

Kyung Hee University

Migration in Heterogeneous Systems

The principle of maintaining a migration stack to support migration of an execution segment in a heterogeneous environment

3-15

end

Page 52: Kyung Hee University 1/57 Communication Chapter 3

52/57

Kyung Hee University

Software Agents

Page 53: Kyung Hee University 1/57 Communication Chapter 3

53/57

Kyung Hee University

Software Agents

Definition:Is as an autonomous process capable of reacting to, and changes in, its environment, possibly in collaboration with users and other agents

Page 54: Kyung Hee University 1/57 Communication Chapter 3

54/57

Kyung Hee University

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 55: Kyung Hee University 1/57 Communication Chapter 3

55/57

Kyung Hee University

Agent Technology

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

Page 56: Kyung Hee University 1/57 Communication Chapter 3

56/57

Kyung Hee University

Agent Communication Languages (1)

 Components of a message

Page 57: Kyung Hee University 1/57 Communication Chapter 3

57/57

Kyung Hee University

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 58: Kyung Hee University 1/57 Communication Chapter 3

58/57

Kyung Hee University

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)

Page 59: Kyung Hee University 1/57 Communication Chapter 3

59/57

Kyung Hee University

End of chapter 3

Thank you for joining us!