We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
21v2re4, 420 PM
CoMPoSING PReGRAMS.
‘cnaper 4
42.0 Pyhen Steam
‘ueres
{£7219 mpbretaion
“4p aratel computing
46 Distributed Computing
TEXT PROJECTS TUTOR ABOUT
46 Distributed Computing
Large-scale data processing applications often coordinate effort among muftiple computers, A
distributed computing application is one in which multiple interconnected but independent computers
coordinate to perform a joint computation,
Different computers are independent in the sense that they do not directly share memory. Instead,
they communicate with each other using messages, information transferred from one computer to
another over a network.
4.6.1. Messages
Messages sent between computers are sequences of bytes. The purpose of a message varies,
messages can request data, send data, or instruct another computer to evaluate a procedure cal. In
all cases, the sending computer must encode information in a way that the receiving computer ean
decode and correctly interpret. To do $0, computers adopt a message protocol that endows meaning
to sequences of bytes,
A message protocols a set of rules for encoding and interpreting massages. Both the sending and
receiving computers must agree on the semantics of # message to enable successful communication.
Many message protocols specify that a message conform toa partcular format in which certain bits
al fixed positions incicate fixed conditions. Others use special bytes or byte sequences to delimit
parts of the message, much as punctuation delimits sub-expressions in the syntax of a programming
language.
Message protocols are not particular programs or software libraries. Instead, they are rues that can
be applied by a variety of programs, even written in different programming languages. As a resull,
computers with vastly diferent software systems can participate in the same distributed system,
simply by conforming to the message protocols that govern the system.
‘The TCPIP Protocols. On the Internet, messages are transferred from one machine to another
Using the Internet Protocol (IP), which specifies how to transfer packets of data among diferent
networks to allow global Intemet communication. IP was designed under the assumption that
networks are inherently unreliable at any point and dynamic in structure. Moreover, it does not
assume that any central tracking or monitoring of communication exists. Each packet contains a
header containing the destination IP address, slong with other information. All packets are forwarded
‘throughout the network toward the destination using simple routing rules on a best-effort basi.
‘This design imposes constraints on communication. Packets transferred using modem IP
implementations (IPv4 and IPv6) have a maximum size of 85,535 bytes. Larger data values must be
split among multiple packets. The IP does nat guarantee that packets will be received inthe same
order thal they were sent, Some packets may be lost, and some packets may be transmitted multiple
times.
‘The Transmission Control Protocol is an abstraction defined in terms ofthe IP that provides reliable,
ordered transmission of arbitrary large byte streams. The protacol provides this guarantee by
correctly ordering packets transferred by the IP, emaving duplicates, and requesting retransmission
of lost packets, This improved reliability comes atthe expense of latency, the time required to send a
‘message from one point to another.
‘The TCP breaks a stream of data into TCP segments, each of which includes a portion of the data
preceded by a header that contains sequence and state information to suppor reliable, ordered
transmission of data. Some TCP segments do not include data at all, but instead establish or
‘terminate a connection between two computers
Establ'shing a connection between two computers a and 6 proceeds in three steps:
1. sends a request to a port of sto establish a TCP connection, providing a port number to
Which lo send the response.
2. esends a response tothe port specified by a and walts for ts response to be acknowledged.
3. asends an acknowledgment response, ver'ying that data can be transferred in both directions.
‘Afr this three-step "handshake", the TCP connection is established, and and s can send data to
teach other. Terminating a TCP connection proceeds as a sequence of steps in which both the client
and server request and acknowledge the end of the connection
46.2 Client/Server Architecture
‘The clientserver architecture is a way to dispense a service from a central source. A server provides
2 service and multiple clients communicate withthe server to consume that service. In this,
nipsilmsew.composingprograms.com/pages/48-distriouted-computing.him| wa21v2re4, 420 PM
eT Message Pesing
“48. Syremontaton Pals
46 Distributed Computing
architecture, clients and servers have different roles, The servers role is to respond to service
requests from clients, while a cients roe isto Issue requests and make use of the server's response
in order to perform some task, The diagram below illustrates the architecture,
‘The most influential use of the model is the modem World Wide Web. When a web browser displays
the contents of a web page, several programs running on independent computers interact using the
clientiserver architecture. This section describes the process of requesting a web page in order to
ilustrate central ideas in clentserver distributed systems.
Roles. Tne web browser application on a Web user's computer has the role ofthe client when
requesting a web page. When requesting the content from a domain name on the Internet, such as
‘wurrylimes.com, it must communicate with at least lwo different servers
‘The client frst requests the Internet Protocol (IP) address of the computer located at that name from
a Domain Name Server (ONS). A DNS provides the service of mapping domain names to IP
addresses, which are numerical identifiers of machines on the Intemet. Python can make such a
request direcly using the sacket module.
25> fron socket mport gethosthynane
>>> gathostoynane( iw. nytines. com’)
370.149.172.138"
‘The client then requests the contents of the web page from the web server located at that IP adress.
‘The response inthis case is an HTML document that contains headlines and article excerpts of the
day's news, as well as expressions that indicate how the web browser client should lay out that
contents on the user's sereen. Python can make the two requests required to retrieve this content
Using the uritib.request module.
>>> fron urllib.nequest dnport urlopen
>>> response = urTopentttp:/Ptae.nyt ines. con") read)
353 response 15]
b'abocT¥PEntnd>*
Upon receiving this response, the browser issues additional requests for images, videos, and other
‘auxiliary components ofthe page. These requests are initiated because the original HTML document
contains addresses of additional content and a description of how they embed into the page.
‘An HTTP Request. The Hypertext Transfer Protocol (HTTP) isa protocol implemented using TCP
that governs communication for the World Wide Web (WWW). It assumes a client/server architecture
betwen a web browser and a web server. HTTP species the format af messages exchanged
between browsers and servers. All web browsers use the HTTP format to request pages from a web
server, and all web servers use the HTTP format to send back their responses,
HTTP requests have several types, the most common of which is a ger request fora specific web
page. Acer request specifies a location. For instance, typing the address
hetp:/enowikipedta.org/wiki/UC Serkeley inlo a web browser issues an HTTP cer request fo port 80 of
the web server at en.wikipedia.org for the contents at location /wiki/Uc_serkeley.
“Tho sorver sends back an HTTP response:
Server: Apsene/1.3:3.7 (Unix) (Red-Het/Limx)
Content-Type: text/her; charset=UTF-8
(On the firstline, the text 260 ox indicates that there were no errors in responding to the request, The
subsequent lines of the header give information about the server, the date, and the type of content
being sent back,
nipsilmsew.composingprograms.com/pages/48-distriouted-computing.him| 2421v2re4, 420 PM
46 Distributed Computing
Ifyou have typed in @ wrong web address, or clicked on a broken link, you may have seen a message
such as this eror
Itmeans that the server sent back an HTTP header that started:
HITP/2.2 408 Wot Found
‘The numbers 200 and 404 are HTTP response codes. A fixed set of response codes is a common
feature of a message protocol. Designers of protocols attempt to anticipate common messages that
will be sent via the protocol and assign fixed codes to reduce transmission size and establish @
common message semantics. In the HTTP protocol, the 200 response code indicates success, while
404 indicates an error that a resource was not found. A varely of other response codes exist in the
HTTP 1.1 standard as well
Modularity. The concepts of client and server are powerful abstractions. A server provides a service,
Possibly to multiple cients simultaneously, and a client consumes thal service, The clients do not
need to know the details of how the service is provided, or how the data they are receiving is stored
or calculated, and the server does net need to know haw its responses are going to be used.
(nthe web, we think of clients and servers as being on different machines, but even systems on a
single machine can have clientserver architectures. For example, signals from input devices on a
‘computer need to be generally available to programs running on the computer. The programs are
Clients, consuming mouse and keyboard input data. The operating system's device crivers are the
servers, taking in physical signals and serving them up as usable input. In addition, the central
processing unit (CPU) and the specialized graphical processing unit (GPU) often participate in a
Clentserver architecture with the CPU as the client and the GPU as a server of images,
[A drawback of client/server systems is thatthe server isa single point of failure. It's the only
component withthe abiliy to dispense the service. There can be any number of clients, which are
interchangeable and can come and go as necessary.
‘Another drawback of client-server systoms is that computing resources become scarce ifthere are
too many clients. Clients increase the demand on the system without contributing any computing
48.3 Peer-to-Peer Systems
“The clientserver model is appropriate for service-oriented situations. However, there are other
‘computational goals for which a more equal division of labor is a better choice. The term peer-to-peer
is used to describe distributed systems in which labor is divided among all the components of the
system, All the computers send and receive data, and they all contribute some processing power and
rmomary. AS a distriouted system increases in size, its capacity of computational resources increases.
Ina peer-to-peer system, all components of the system contribute some processing power and
memory to a distributed computation.
Division of labor among all participants isthe identilying characteristic of a peer-to-peer system. This
‘means that peers need to be able to communicate with each other reliably. In order to make sure that
messages reach thair intended destinations, pacr-to-peor systems need to have an organized
‘network structure. The components in these systems cooperate to maintain enough information about
the locations of ather components to send messages to intended destinations,
In some peer-to-pear systems, the job of maintaining the health ofthe network is taken on by a set of
specialized components. Such systems are not pure peer-to-peer systems, because they have
aifferent types of components that serve different functions, The components that support a peerto-
peer network act ke scaffolding: they help the network stay connected, they maintain information
about the locations of cifferent computers, and they help newcomers take their place within their
neighborhood.
“The most common applications of peer-to-peer systems are data transfer and data storage, For data
transfer, each computer in the system contributes to send data over the network. Ifthe destination
‘computer isin a particular computer's neighborhood, that computer helps send data along. For data
storage, the data set may be too large to fit on any single computer, or too valuable to store on just a
single computer. Each computer stores a small portion ofthe data, and there may be multiple copies
of the same data spread over diferent computers. When a computer falls, the data that was on it can
be restored from other copies and put back when a replacement arrives.
‘Skype, the voice- and video-chat service, is an example of a data transfer application with @ peer-to-
peer architecture. When two people on different computers are having a Skype conversation, their
communications are transmitted through a peer-to-peer network, This network is composed of other
computers running the Skype application. Each computer knows the location of afew other
computers in its neighborhoad. A computer helps send a packet to its destination by passing iton a
neighbor, which passes it on to some other neighbor, and so on, until the packet reaches its intended
destination, Skype is not a pure peer-to-peer system. A scaffolding network of supemodes is
nipsilmsew.composingprograms.com/pages/48-distriouted-computing.him| 3421v2re4, 420 PM 4.6 Distributed Computing
responsible for logging-in and logging-out users, maintaining information abot
computers, and modifying the network structure wiven users enter and exit.
Continue: 4.7 Distrbuted Data Processing
‘SengatngPogarstby et Gta, eda etn acu and non ef Can Pagans by Hari Asbon wd Gly Sana sara de Cae
nipsulmvew.composingprograms.com/pages/48-distriouted-computing.him| 4