580 likes | 854 Views
ITEC801 Distributed Systems. Inter-process Communication Coulouris Sections 4.1-3, 4.6 Liu Chapter 2. Important Things. All distributed systems depend on some form of IPC Basic form of IPC is messaging Understanding of IPC concepts
E N D
ITEC801Distributed Systems Inter-process Communication Coulouris Sections 4.1-3, 4.6 Liu Chapter 2
Important Things • All distributed systems depend on some form of IPC • Basic form of IPC is messaging • Understanding of IPC concepts • Protocols, connection-oriented, connectionless, synchronous, asynchronous, data representation (encoding), data marshalling Inter-process Communication
Inter-process Communications • Inter-process communications (IPC) facilities for single systems include • message queues • semaphores • shared memory • Distributed computing systems make use of these facilities to provide application programming interface which allows IPC to be programmed at a higher level of abstraction. • Distributed computing requires information to be exchanged among independent processes. Inter-process Communication
IPC – unicast and multicast • When communication is from one process to a single other process, the IPC is said to be a unicast • When communication is from one process to a group of processes, the IPC is said to be a multicast Inter-process Communication
IPC paradigms and implementations Paradigms of IPC of different levels of abstraction have evolved, with corresponding implementations. Inter-process Communication
IPC API • An abstraction of details and intricacies of system level facilities • For programmer to concentrate on application logic. Inter-process Communication
Protocols • two or more processes engage in IPC in a protocol agreed upon by the processes • A process may be a sender at some points during a protocol, a receiver at other points. Inter-process Communication
Protocol • In a distributed application, two processes perform IPC in a mutually agreed upon protocol. • The specification of a protocol should include • the sequence of data exchange, which can be described using a time event diagram. • the specification of the format of the data exchanged at each step. Inter-process Communication
HTTP: A sample protocol • The Hypertext Transfer Protocol is a protocol for a process (the browser) to obtain a document from a web server process. • Data form • It is a request/response protocol: a browser sends a request to a web server process, which replies with a response. • Stateless Inter-process Communication
Event diagram Distributed Computing, M. L. Liu
Event Diagram for a HTTP session Distributed Computing, M. L. Liu
Sequence Diagram Distributed Computing, M. L. Liu
sequence diagram for a HTTP session Distributed Computing, M. L. Liu
A sample HTTP session Inter-process Communication
IPC in Distributed Computing P1 P2 data sender receiver Inter-process Communication
Unicast vs. Multicast … P2 P2 P2 P2 m m m m P1 P1 unicast multicast Inter-process Communication
Archetypal IPC API • Send ( [receiver], message) • Receive ( [sender], message storage object) • Connect (sender address, receiver address) • for connection-oriented communication. • Disconnect (connection identifier) • for connection-oriented communication. Inter-process Communication
IPC in basic HTTP Web Browser Web Server C1 S1 C2 S2 C3 S3 C4 S4 C1: make connection C2: send request C3: receive response C4: disconnect S1: accept connection S2: receive request S3: send response S4: disconnect Inter-process Communication
Connection-oriented Protocols • Sender and receiver establish a connection • Possibly negotiate protocols and/or communication parameters • Then exchange data • When done connections is released Inter-process Communication
Connectionless Protocols • No setup required • Sender transmits data • No information about connection retained Inter-process Communication
Event Synchronisation • IPC requires that the two processes synchronise their operations: • one side sends • the other receives • until all data has been sent and received. • Ideally, the send operation starts before the receive operation commences. • In practice, the synchronisation requires system support. Inter-process Communication
Synchronous vs. Asynchronous • Easy way to synchronise is to use blocking operations • When a process issues a blocking operation the process blocks • When the operation completes the process unblocks Inter-process Communication
Synchronous vs. Asynchronous • IPC operations may be asynchronous or nonblocking • An asynchronous operation issued by a process will not block further processing of the process • the process is free to proceed with its processing • may optionally be notified by the system when the operation is fulfilled. Inter-process Communication
Synchronous Send & Receive A sends message and then waits for response A Request is received Response B B is not running Process request B blocks waiting for next request time Inter-process Communication
Asynchronous send & receive A sends message and continues A Request is received Response B B is running Process request B continues time Inter-process Communication
Synchronous send and Async. Receive - Distributed Computing, M. L. Liu
Synchronous send and Async. Receive - Distributed Computing, M. L. Liu
Synchronous send and Async. Receive - Distributed Computing, M. L. Liu
Asynchronous send and Asynchronous receive Distributed Computing, M. L. Liu
Event diagram Distributed Computing, M. L. Liu
Deadlock and Timeouts • Blocking operations issued in the wrong sequence can cause deadlocks • Deadlocks should be avoided • Alternatively, timeout can be used to detect deadlocks Inter-process Communication
Deadlock and Timeouts Receive from Process B issued Process A blocked pending data from process B A B Receive from Process A issued Process B blocked pending data from process A time Inter-process Communication
Using threads for asynchronous IPC • When using an IPC programming interface, it is important to note whether the operations are synchronous or asynchronous. • If only blocking operation is provided for send and/or receive, then it is the programmer’s responsibility to using child processes or threads if asynchronous operations are desired. • We may have time to discuss threads in more detail Inter-process Communication
Using threads for asynchronous IPC A spawns thread to send message A thread Thread blocks awaiting response Request is received Response B B is running Process request B continues time Inter-process Communication
Data Representation • Data transmitted on the network is a binary stream. • An IPC system may provide the capability to allow data representation to be imposed on the raw data • We have already seen this with RPC/RMI Inter-process Communication
Data Representation • Because different computers may have different internal storage format for the same data type, an external representation of data may be necessary. • Data marshalling is the process of • flattening a data structure • converting the data to an external representation Inter-process Communication
Data Representation • Some well known external data representation schemes are: • Sun XDR • ASN.1 (Abstract Syntax Notation) • XML (Extensible Markup Language) Inter-process Communication
Data Encoding Protocols Inter-process Communication
Tag-Length-Value (TLV) Encoding • The data encoding structure has three values • Tag/Type (T) • Length (L) • Value (V) • Known as TLV. • Basic Encoding Rules (BER) defines order and structure • Guarantees that both ends interpret communication channels consistently.
TLV Encoding Length Value Tag Format (1 bit) Number 5 bits Class 2 Bits
TLV Encoding TAG : • Comes first, alerts destination of structure that follows. • Defines the type of data • Composed of three subfields: • Class (two bits). • Format (one bit). • Number (Five bits). • Class: defines scope of data. Four classes defined: • Universal (00) • Application-wide (01). • Context-Specific (10). • Private (11).
TLV Encoding Class • Universal: data types taken from ASN.1. • Include • Integer • String • ObjectIdentifier. • Application-wide: Include • IPAddress/Counter • Gauge/TimeTicks.
TLV Encoding • Format (P/C: Primitive/Constructed) : Indicates if data is Primitive [simple (0)] or constructed [structured (1).] • Primitive encoding means contents octets represent the value directly. • Constructor encoding means that contents octets encode one or more additional data values such as SEQUENCE.
TLV Encoding • Number: Divides simple or structured data into subgroups. • Example: In Universal class, with simple format, Integer has a value 2. Inter-process Communication
TLV Encoding Length • Follows Type field. • Determines the number of octets value field will contain. • Either short definite or long definite form. • Another form indefinite is not used. • Definite: length of encoding known before transmission. • Indefinite indicate otherwise. • Short Definite: 0 to 127 octets in the value field. • Long definite: 128 or more. • Uses multiple octets to represent total length.
TLV Encoding 0 0 0 0 0 0 1 0 A. Shaded part defines the length 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 B. Shaded two bytes define the length of the length (2 bytes); the colored bytes define the length (260 bytes)
TLV Encoding Length (Contd.) • Single octet representation: Most significant byte zero, other seven bytes define length of data. • Multiple octet representation: Most significant bit of first byte 1, other seven bits define no. of bytes to define length. • Following octets take up rest of length. Value • Codes the value of data according to BER.
Encoding Examples 00000010 00000100 00000000 00000000 00000000 00001110 Tag Length Value Integer 14 00000100 00000010 01001000 01001001 IP address: 131.21.14.8
Data Marshalling Inter-process Communication
XML • http://java.sun.com/xml/docs/tutorial/overview/1_xml.html#intro • XML is a text-based markup language that is fast becoming the standard for data interchange on the Web. • XML has a syntax analogous to HTML. • Unlike HTML, XML tags tell you what the data means, rather than how to display it. Inter-process Communication