Sie sind auf Seite 1von 3

Communication Primitives Message passing

§ Communication primitives
• send(destination-process, message)
• receive(source-process, message)
§ blocking vs. non-blocking primitives
§ message passing model • a message is copied at least three times:
• communication primitives sender (user buffer -1-> kernel buffer) -2->
o blocking vs. non-blocking receiver(kernel buffer -3-> user buffer)
o synchronous vs. asynchronous • non-blocking - faster, harder to code, riskier, requires additional
o direct vs. indirect OS support
§ remote procedure calls o send - return as soon as message copied to kernel buffer

• motivation o receive - provide a (user) buffer for message to be copied to

• overview and return


• binding • blocking - safer, easier to think about, slower
• parameter and result passing o unreliable - block until message is sent/received

• stub generation o reliable - receipt is confirmed by acknowledgement, block until

• execution semantics ack is sent/received

Direct vs. indirect communication


Message passing (cont.)
§ Direct communication — explicitly name the process you’re
communicating with
o send(destination-process, message)
§ synchronous vs. asynchronous primitives
• synchronous (also called randezvous) – o receive(source-process, message)

send blocks until receive executes on • Link is associated with exactly two processes
receiving computer - safer, easier, less
o Between any two processes, there exists at most one link
concurrent
o The link may be unidirectional, but is usually bidirectional
• asynchronous -multiple sends can be
executed before receives (messages
buffered) - more dangerous (what to do with § Indirect communication — communicate using mailboxes (ports)
messages to crashed receiver?), complex, (usually) owned by receiver
concurrent o send(mailbox, message)

o receive(mailbox, message)

• Link is associated with two or more processes that share a


mailbox
o Between any two processes, there may be a number of links

o The link may be either unidirectional or bidirectional

Why is message-passing not ideal? Remote Procedure Call (RPC)


§ Disadvantages of client-server communication via message § RPC mechanism:
passing:
• Hides message-passing I/O from the programmer
• Message passing is I/O oriented, rather than request/result
• Looks (almost) like a procedure call — but client invokes a
oriented
procedure on a server
• Programmer has to explicitly code all synchronization
§ RPC invocation (high-level view):
• Programmer may have to code format conversion, flow
control, and error control • Calling process (client) is suspended
• Parameters of procedure are passed across network to
§ Goal — heterogeneity — support different machines, different
called process (server)
OSs
• Server executes procedure
• Portability — applications should be trivially portable to
machines of other vendors • Return parameters are sent back across network
• Interoperability — clients will always get same service, • Calling process resumes
regardless of how vendor has implemented that service
§ Invented by Birrell & Nelson at Xerox PARC, described in
• OS should handle data conversion between different types
February 1984 ACM Transactions on Computer Systems
of machines
Remote Procedure Call (RPC) I/O protection
pack unpack § To prevent illegal I/O, or simultaneous I/O requests from
§ Each RPC invo- call parameters parameters call
multiple processes, the OS typically performs all I/O via
cation by a client client client server privileged instructions
process calls a stub stub server
• User programs must make a system call to the OS to
client stub, which return unpack pack return perform I/O
builds a message results results
and sends it to
kernel kernel § When user process makes a system call:
a server stub
• A trap (software-generated interrupt) occurs, which causes:
§ The server stub
o The appropriate trap handler to be invoked using the
uses the
message network trap vector
to generate a o Kernel mode to be set

local procedure call to the server • The trap handler:


§ If the local procedure call returns a value, the server stub builds a o Saves process state
message and sends it to the client stub, which receives it and returns o Performs requested I/O (if appropriate)
the result(s) to the client
o Restores state, sets user mode, and returns to calling
program

RPC Invocation (more detailed) Binding


§ Binding = determining the server and remote procedure to call
1. Client app. procedure calls the client stub
§ Static binding — addresses of servers are hardwired (e.g., Ethernet
2. Client stub packs parameters into message and traps to the kernel
number)
3. Kernel sends message(s) to remote kernel
• Inflexible if a server changes location
4. Remote kernel passes message(s) to server stub
• Poor if there are multiple copies of a server
5. Server stub unpacks parameters and calls server app. procedure
6. Server app. executes procedure and returns results to server stub § Dynamic binding — dynamically assign server names
7. Server stub packs result(s) in message(s) and traps to kernel • Broadcast a “where is the server?” message, wait for response
8. Remote kernel sends message(s) to local kernel from server

9. Local kernel passes message(s) to client stub • Use a binding server (binder)
o Servers register / deregister their services with the binding
10. Client stub unpacks result(s) and returns them to client app.
server
o When a client calls a remote procedure for the first time, it
queries the binding server for a registered server to call

Parameter and result passing Parameter passing (cont.)


int query (int key, int number, § Handle different internal representations
nr_hits = query(key, 10, result); tuple values) • ASCII vs. EBCDIC vs. …
{
… • 1’s comp. vs. 2’s comp. vs. floating-point
return (num_hits); • Little endian vs. big endian
}
• Establish a canonical (standard) form?
marshal unmarshal
§ What types of passing are supported?
• Remote procedure can’t access global variables must pass all
network necessary data
int query (int key, int number, • Call-by-value (procedure gets a copy of data) — pass
tuple values) parameters in message
nr_hits = query(key, 10, result); { • Call-by-reference (procedure gets a pointer to data)

return (num_hits); o Can’t do call-by-reference

} o Do call-by-copy / restore instead

unmarshal marshal – Instead of pointer, pass item pointed to


– Procedure modifies it, then pass it back
o Inconsistency if client doesn’t block
network
Generating stubs Error handling, semantics
§ C and C++ may not be descriptive enough to allow stubs to be
generated automatically § RPC call may fail due to computer or communications failure
typedef struct { char add(int key, tuple value); § what to do if RPC call fails?
double item1; char remove(int key, tuple value); § three execution semantics
int item2; int query(int key, int number, tuple values[ ]);
• “at least once”
char *annotation;
} tuple; o if call succeeds – at least one execution of remote procedure
happened
• Which are in, in-out, and out parameters? o if fails – none, partial, multiple executions

• Exactly what size are parameters (e.g., integers, • “exactly once”

arrays)? o if succeeds – exactly once

o if fails – none, partial, one


• What does it mean to pass a pointer?
• “at most once”-
§ inerface
Using db OSF’s DCE Interface boolean
Definition long query
add ( Language (IDL) (
to specify
{ [in] long key, [in] long key, o if succeeds – exactly once
procedure
typedef struct signatures
{ for stub
[in] generation:
tuple value [in] long number,
double item1; ); [out, size_is(number)] o if fails - none
long item2; tuple values[ ]
[string, ptr] boolean remove ( );
ISO_LATIN_1 [in] long key,
*annotation; [in] tuple value
} tuple; );

Stateful vs. stateless server


§ Stateful server — server maintains state information for each client
for each file
• Connection-oriented (open file, read / write file, close file)
• Enables server optimizations like read-ahead (prefetching) and
file locking
• Difficult to recover state after a crash

§ Stateless server — server does not maintain state information for


each client
• Each request is self-contained (file, position, access)
o Connectionless (open and close are implied)

• If server crashes, client can simply keep retransmitting requests


until it recovers
• No server optimizations like above
• File operations must be idempotent

Das könnte Ihnen auch gefallen