CS代考 COMP90015 Distributed Systems

COMP90015 Distributed Systems
Interprocess Communication

School of Computing and Information Systems © The University of Melbourne

Copyright By PowCoder代写 加微信 powcoder

2022 Semester II
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne)
2022 Semester II 1/42

1 Abstract IPC Data Exchange
Mechanisms of IPC
Communication Protocols and Interactions
Data Representation
2 Socket Paradigm
Network Communication Network Address
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne)
2022 Semester II 2/42

Abstract IPC Data Exchange Application/User-level Data Exchange
IPC is the exchange of data between processes.
• Processes arrange data into data structures, often leading to a quite complex and significantly large aggregate structure representing an application’s state.
• Data must be transferred from persistent storage, or files, into memory in order for the process to work on it, and results must be transferred back to the persistent storage if they are to be available outside of the process lifetime.
• Ostensibly, different processes can exchange data by reading/writing to the same files, and this is indeed a simple and ubiquitous approach:
• file locking can be used for concurrency control,
• if a distributed file system is available (discussed in later lectures) then the same file can
be accessible from processes on different machines,
• vastly different applications can exchange data in this way, e.g. a Word Processor can
exchange data with an Email Client,
• OS user interfaces often provide user-level mechanisms for exchange of data between
processes, e.g. cut-and-paste between applications.
However these high-level, somewhat ad-hoc IPC approaches can be grossly inefficient, sometimes ill-defined and downright dangerous to make use of, compared to functionality specifically provided by the OS to undertake IPC.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 3/42

Abstract IPC Data Exchange
Data Format
Whether high-level data is exchanged in ad-hoc ways or using specific IPC mechanisms, the data format and more specifically the data structures and representations used by the application process, as well as the application or user requirements that drive the need for data exchange in the first place, can significantly influence the choice of IPC and the design of the distributed system.
• file transfer – must be reliable and high throughput
• data entry, databases – high iops and throughput
• audio and video streaming – high throughput and high quality
• instant chat, voice and video conferencing – interactive and high quality • collaborative document editing – complex interactions
• remote user interface and control – responsive, light weight
• online games – low latency, responsive
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 4/42

Abstract IPC Mechanisms of IPC
The availabilty of IPC mechanisms is determined by the process locations
di erent machines IPC
same machine
shared memory
network resource
network resource
Network Communication
IPC resource
network resource
network resource
• Unlike threads within a process that share the same address space and can refer to the same data, the address space of processes are initially exclusive and for processes to refer to the same data they must communicate the data to
each other somehow.
• Network-based IPC can take place between processes on different machines and also between processes on the same machine – processes need not know if they are local or remote to each other.
• Shared Memory IPC can only take place between processes on the same machine – it is the fastest form of IPC, much like thread interaction within a process.
• Other forms of IPC resources like Pipes and Memory Mapped IO are also only available between processes on the same machine – they are faster than network-based IPC.
• Shared Memory, Pipes and Memory Mapped IO are usually quite OS specific: we can study them later as an advanced topic.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 5/42

Abstract IPC Mechanisms of IPC Open Systems Interconnection (OSI) model
With respect to Network IPC, we consider distributed systems that are based upon functionality associated with the Transport Layer of the OSI model. The Transport Layer provides mechanisms for host-to-host or point-to-point interprocess communication over a network. At the Session Layer we make use of these mechanisms to implement long-running communication protocols that support the requirements of the Application Layer. In between in the Presentation Layer which provides data representations of Application Layer complex data structures in a form suitable for the Session Layer protocols.
• Application Layer: Fundamental distributed applications like Web Servers and Email, supporting services like the Domain Name Service (DNS) and the Network Time Protocol (NTP), and middleware like message queues and publish/subscribe systems.
• Presentation Layer: Data representations of complex data structures.
• Session Layer: Long-running communication protocols to support application
requirements.
• Transport Layer: Host-to-Host communication services for applications;
primarily TCP and UDP.
• Network Layer: Packet forwarding and routing through the network.
• Data Link Layer: Packet transmission from one device to another.
• Physical Layer: Data transmission over a communication channel.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 6/42

Multi-party Communication
Abstract IPC Mechanisms of IPC
point-to-point
multiple point-to-point
point-to-multipoint multipoint-to-point multipoint-to-multipoint
The point-to-multipoint mechansim is sometimes referred to as
a broadcast mechanism, e.g. like broadcast radio, or a multi-cast mechansim if it allows selecting a subset of possible receivers.
• Usually we consider IPC to be between 2 processes/parties: point-to-point.
• Communication between 3 or more parties is usually considered as multiple,
independent point-to-point communications.
• However multi-party communication mechanisms are sometimes available that
can be more efficient than using multiple point-to-point IPCs:
• UDP provides point-to-multipoint communication, where a process can send a single packet, replicated by the network as required, and delivered to multiple processes. Multiple point-to-point would require the sending process to send the same packet multiple times.
• Multipoint-to-point and multipoint-to-multipoint are less common. In this case the IPC mechanism must provide some kind of aggregation of communication that is more efficient that using multiple point-to-point or point-to-multipoint IPCs.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 7/42

Abstract IPC Mechanisms of IPC
Discussion questions
Question (1): What kind of application functionality do you think would be suitable for multipoint-to-point and/or multipoint-to-multipoint IPC mechanisms? For the functionality that you discussed, without such multipoint IPC mechanisms, how many individual messages would need to be sent using multiple point-to-point communications to achieve the same functionality? What is lacking from the multiple point-to-point solution? Question (2): Wireless broadcast for point-to-multipoint IPC uses something like a wireless basestation or a radio transmitter to transmit a signal that is received (practically) simultaneously by all receivers. Such a wireless broadcast mechanism cannot provide multi-cast in this situation. Why not? In what situations could it be provided if any?
Question (3): Shared memory can be established between more than 2 processes, if those processes are on the same machine, i.e. 3 processes can address the same physical memory location. Is this point-to-multipoint or multipoint-to-point or multipoint-to-multipoint or something else? Justify your answer.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 8/42

Abstract IPC Communication Protocols and Interactions
Communication Protocols
A communication protocol defines a deterministic, potentially unbounded sequence of interactions between a number of communicating parties. The purpose of the protocol is to define how the parties can systematically interact in order to effectively communicate given some existing communication mechanisms; e.g. a communication network.
• A communication protocol differs from a distributed algorithm in that a protocol may not terminate, whereas an algorithm is only valid if it terminates.
• Communication protocols require at least as much computational power as a Finite State Machine (FSM):
• A party engaged in communication is in one of several states defined by the protocol, or is transitioning from one state to another.
• State transitions are triggered by events in the environment or by the actions of the communicating parties, e.g. data is received, data is sent, or other events occur such as timeouts.
• Communication protocols apply to all layers of a distributed system, from the lowest layer (Physical Layer) to the highest layer (Application or User Layer).
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 9/42

Telephone Communication Protocol
Abstract IPC
Communication Protocols and Interactions
say “goodbye”, hangup
NOT LISTENING
finish talking
received “goodbye”
finish listening
NOT TALKING
incoming call
WAITING FOR “hello”
received “goodbye”, hangup
say “goodbye”
denied/timeout
dial number
received “hello”
timeout, say “hello”
give up, hangup
accept, say “hello”
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne)
2022 Semester II

Abstract IPC Communication Protocols and Interactions
Discussion questions
Consider the Telephone Communication Protocol.
Question (4): Explain what happens if an incoming call arises when the person is TALKING.
Question (5): Currently the TALKING state allows both people to talk at the same time. Expand the protocol TALKING state, by replacing it with a number of other states, to ensure that only one person can talk at a time. Question (6): What communication errors are catered for by the protocol? What common telephone communication errors are not handled by the protocol? Expand the protocol, by including new states, to handle one of the communication errors that you discussed.
Question (7): Explain why there are states where the person is either NOT TALKING or NOT LISTENING.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 11/42

Abstract IPC Communication Protocols and Interactions
Interaction Diagrams
https://www.omg.org/spec/UML
It is sometimes helpful to represent sequences of interactions between communicating parties, arising from a communication protocol, using a sequence or interaction diagram, sometimes called an event diagram.
• The interaction diagram shows component interactions arranged in a time sequence.
• Parallel vertical lines on the interaction diagram show the lifetime of threads and other components in the system, and horizontal arrows show method calls and messages.
• A solid arrow head represents a synchronous operation, whereby the caller must wait until the operation completes (returns) before it can continue.
• A Hollow arrow head represents an asynchronous operation, whereby the caller can continue without having to wait for the operation’s outcome.
• Activation boxes on the timelines show activity being undertaken.
In this subject we make use of UML when its convenient and useful to do so, however we are not concerned with a rigorous treatment of UML techniques – that would be of interest in Software Engineering.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 12/42

Abstract IPC Communication Protocols and Interactions
An interaction arising from the Telephone Communication Protocol
dial number
incoming call accept
TALKING state
talking talking
“goodbye” “goodbye”
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 13/42

Abstract IPC Communication Protocols and Interactions Caller/Callee ⇒ Client/Server roles
Two communicating parties take on roles depending on who initiates the communication.
A process, acting as a client, initiates IPC to an endpoint of the server.
IPC endpoint IPC resource
initiate IPC
A process, acting as a server, creates one or more IPC endpoints and waits for a client to initiate communication via one of these endpoints.
IPC endpoint
accept IPC
• IPC endpoints are resources provided by the OS.
• IPC requires a process to act as a server, which waits for another process,
acting as a client, to initiate IPC.
• The server’s endpoint must be known a priori to the client.
• A process that acts only as a client does not allow other processes to initiate IPC to it and we typically call it a client process or client.
• A process that acts only as a server never initiates IPC to other processes and we typically call it a server process or server.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 14/42

Abstract IPC Communication Protocols and Interactions A process can be both a client and server
some endpoints can accept and initiate IPC
threads for both initiating and accepting IPC
a process can maintain multiple IPC endpoints
A process may act as both a client and a server, allowing processes to initiate IPC to it, and also initiating IPC to other processes:
• A server in a multi-server achitecture may receive connections from clients but also make/receive connections to/from other servers.
• A peer, in a file sharing system may act as a client and make connections to the file index servers, but may also act as a server and allow other peers to connect to it.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 15/42

Abstract IPC Communication Protocols and Interactions
Session Layer
The protocols that allow the communicating parties to initiate communication, provide the rules that they must follow to communicate data, and the rules for terminating the communication, are expressed in the Session Layer:
• A session is a long-running communication, that may involve the exchange of large and varied amounts of information.
• Sessions start with a negotiation or handshake that establishes the rules of the session, e.g. to support different protocols, data formats and algorithms used throughout the session.
• Sessions typically allow an unbounded amount of communication to take place, or as allowed by the negotiated protocols. The session protocol must specify how and when the different kinds of data will be transmitted.
• Sessions have a well defined termination, rather than the communicating parties simply ceasing to communicate.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 16/42

Abstract IPC Data Representation
Presentation Layer
Whatever the high level format of data to be communicated, IPC will ultimately lead to that data being represented as an array of bytes, either as a fixed (known) size array, e.g. when the source of the data is a file or data structure in memory, or as an unbounded array, e.g. when the source of the data is an audio device, or a keyboard that generates data. Perhaps the only exception to this is shared-memory IPC where the data may be communicated in situ, without the need to organize it into an array. In any case we know that all data is represented in the machine as bytes of information.
The Presentation Layer is concerned with APIs to support the translation of high level data formats to byte arrays, in an external data representation that is agreed upon by the communicating parties, and vice versa, which is sometimes called marshalling and unmarshalling respectively.
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne) 2022 Semester II 17/42

• Primitive data types: integer, float, boolean
• Executable data: machine code
• Image, audio and video: JPEG, MP3, MP4
• Compressed data: GZIP
• Encrypted data: RSA, AES
(School of Computing and InformaCtiOonMSPy9s0te0m15s ©DistTrihbeutUednivSeyrsstietymosf Melbourne)
2022 Semester II
Abstract IPC Data Representation
Data Encodings
While the data is in its most basic form an array of bytes, how information is encoded into those bytes is called the data encoding, and there are a number of popular choices:
• Text encodings are used to represent textual information:
• ASCII: The American Standard Code for Information Interchange is one of the first global
standards that uses 7 bits to encode numerals, the English alphabet (both upper and lower case), punctuation and control characters such as line feed, carriage return, backspace, etc. Various “Extended ASCII” encodings arose that use the 8th bit to encode a range of symbols useful for representing graphical user interfaces and extended alphabets, punctuation, etc.
• Unicode: The modern standard for representing text written in all of the world’s languages. The Unicode standards inlude Unicode Transformation Formats (UTF): UTF-8, UTF-16, and UTF-32, and several other encodings. UTF-8 has become the standard encoding on the World Wide Web and on many OSes. The first 128 code points of UTF-8 represent ASCII encodings for backwards compatibility, where each ASCII code point is also a UTF-8 code point. Some UTF-8 code ponts use more than 1 byte.
• Binary encodings are used to represent non-textual information:

ASCII CONTROL CODE CHART
b7 0 0 0 0 1 1 1 1
b6 0 0 1 1 0 0 1 1
b5 0 1 0 1 0 1 0 1
Abstract IPC
Data Representation
b4 b3 b2 b1
SYMBOLS NUMBERS
UPPER CASE
LOWER CASE
Q a 121 61
140 70 160 113
141 71 161 114
142 72 162 115
SP ! ” # $
0 1 2 3 4 5 6 7 8 9
144 74 164
143 73 163
NAK % 25 25
SYN & 26 26
F V 106 56
145 75 165
126 66 146 76 166
BEL ETB ’ 717 27 27
BS CAN ( 10 18 30 28
103 119 W g w
127 67 147 77 167 10

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com