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)
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
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?
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
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
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
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
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
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
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
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
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
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
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
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
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 16
Example: Hello World Server (1/3)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 17
Example: Hello World Server (2/3)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 18
Example: Hello World Server (3/3)
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 19
Example: Hello World Client
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 20
Example: Hello World Client
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
UUNIVERSITY OF NIVERSITY OF MMASSACHUSETTSASSACHUSETTS, A, AMHERST • MHERST • Department of Computer Science Department of Computer Science 22
Next Time
Distributed File Systems