U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of...

22
UNIVERSITY OF NIVERSITY OF MASSACHUSETTS ASSACHUSETTS, A , AMHERST MHERST Department of Computer Science Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture 20: Distributed Systems (RPC)

Transcript of U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of...

Page 1: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science

Emery BergerUniversity of Massachusetts Amherst

Operating SystemsCMPSCI 377

Lecture 20: Distributed Systems (RPC)

Page 2: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 2

Today

Key challenges to distribution in operating systems Resource sharing Timing (synchronization) Critical sections Deadlock detection & recovery Failure recovery

Page 3: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 3

Computation vs. Communication

Communication fast & cheap )can utilize all resources in distributed environment

Communication slow & expensive )do most processing locally

Reality: somewhere in the middle Where are the tradeoffs?

Page 4: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 4

Resource Sharing

Data migration:move data

Computation migration:move computation to data

Job migration:move job (computation & data)

Fundamental tradeoff: speed vs. cost

Page 5: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 5

Data Migration: Copying

Process at site A accesses file at site B =copy file B to process A Costly if file is large Data format conversion Multiple copies ) consistency

problems All subsequent accesses at A are

local

Page 6: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 6

Data Migration: Remote Access

Keep file at B, access remotely from A Saves file transfer cost Converting may be difficult in

pieces Single copy of file = no consistency

problems Performance bottleneck

Page 7: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 7

Computation Migration

More efficient to transfer computation than data Example: database query

Motivates remote procedure calls (RPC) A sends message to process at B Process performs requested action Sends result back to A

Page 8: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 8

Job Migration

May be required: Job needs hardware somewhere in

system Job requires licensed software

Can improve performance: Load balancing:

Even workload across distributed system Computational speedup:

Concurrent (parallel) execution of parts of job

Page 9: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 9

Client/Server Model

Common structure for distributed computation

Server: process/processes providing service Name servers, file servers, database server May exist on more than one node

Client uses service Binds to server

locates on network, establishes connection Request-response interaction May use RPC

Page 10: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 10

Remote Procedure Call

Servers export procedures for clients to call

Client does procedure call to use server

OS manages communication

Page 11: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 11

RPC Implementation Issues

For each procedure for which we want to support RPC: RPC mechanism uses procedure signature(number & type of args & return value)

Generates client stub: bundles RPC arguments, sends to server

Generates server stub: unpacks message, invokes procedure call

Page 12: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 12

RPC: Implementation Issues

client stub:build messagesend messageawait responseunpack replyreturn result

server stub:create threadsloop await command unpack message call proc. w/thread build reply send reply

Page 13: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 13

RPC Binding How does client know right port?

Binding may be static (fixed at compile-time)

Or dynamic (fixed at run-time) Most RPC systems: dynamic binding

via name service Server exports interface, identifies

itself to net Client asks name service for location of

server, establishes connection

Page 14: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 14

Example: Java RMI

public static void bind(String name, Remote obj) Binds server to name

public static Remote lookup(String name) Returns server object corresponding to name

UnicastRemoteObject supports references to non-replicated objects using TCP

Exports interface automatically when server object is constructed

Tools: rmiregistry server-side name server rmic: given server interface, generates client &

server stubs that create & interpret packets

Page 15: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 15

Example: Server in Java Server

Defines interface listing method signatures Implements each method in interface Main:

Creates one or more server objects (subclasses of RemoteObject)

Registers objects with remote object registry

Client Looks up server in remote object registry Uses normal method call syntax for remote

methods Handles RemoteException

Page 16: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 16

Example: Hello World Server (1/3)

Page 17: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 17

Example: Hello World Server (2/3)

Page 18: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 18

Example: Hello World Server (3/3)

Page 19: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 19

Example: Hello World Client

Page 20: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 20

Example: Hello World Client

Page 21: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 21

Summary

Data, computation, job migration Client-server model Mechanism: RPC

Common model for communication in distributed apps

Effectively: language support for distribution

Relies on stub compiler Used even on single nodes for

communication across address spaces

Page 22: U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts Amherst Operating Systems CMPSCI 377 Lecture.

UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 22

Next Time

Distributed File Systems