380 likes | 981 Views
Client-Server Model of Interaction. Chapter 20. We have looked at the details of TCP/IP Protocols Router architecture Now want to look at application programs that use a TCP/IP internet Example applications are practical & interesting
E N D
Client-Server Model of Interaction Chapter 20
We have looked at the details of TCP/IP • Protocols • Router architecture • Now want to look at application programs that use a TCP/IP internet • Example applications are practical & interesting • But…focus instead on the patterns of interaction among the cooperating applications • Primary one is client-server paradigm • Forms basis of most network communications • Foundation for distributed algorithms • See basic model here; later chapters show use in specific applications
Client-Server Model • Server • Any program that offers a service that can be reached over a network • Accepts a request • Performs it service • Returns the result to the requester • For simple services, each request is a single IP datagram; response is another datagram
Client • An executing program that sends a request to a server and waits for a response • Client-server: • Extension of interprocess communication on single machine • Servers can be simple or complex • Time-of-day server: returns current time • Web-server: fetches a copy of a web page
Servers are usually application programs • Execute on any machine supporting TCP/IP • Timesharing system or a PC • Multiple servers can offer the same service • Can be on same machine or on multiple machines • Copies on independent machines increase reliability • “Server” can be applied to a machine • When the computer’s primary purpose is to support a particular server program
Example: UDP Echo Server • Simplest form of client-server interaction uses unreliable datagram delivery • UDP echo server • Echo server process gets use of UDP echo port • Enters infinite loop • Wait for datagram • Reverse source and destination addresses • Return the datagram to the original sender • Echo client is somewhere else • Gets unused UDP port, sends UDP msg to echo server, waits
Two points generally true of client-servers • 1 - Operation • Server starts execution before interaction begins • Accepts requests and sends responses w/o terminating • Client makes request and awaits response • Terminates after using server a finite number of times • 2 - Location • Server waits for requests at well-know port • Reserved for the service it offers • Client allocates an arbitrary, unused, nonreserved port
Time and Date Service • Time server • Used to set a computer’s time-of-day clock • Hardware device that keeps current date and time • Can do manually • Type in time and date when system boots • Use client-server interaction to do automatically • Configure one machine manually • All others contact server when they boot
Representation for the date and time • Many store time and date from an epoch • Use count of seconds since the epoch date • UNIX OS uses January 1, 1970 • TCP/IP defines epoch as January 1, 1900 • Reports time as seconds past the epoch • Time is 32-bit integer • Representation is compact • Allows easy comparison • Ties together date and time of day • Measure time by incrementing single binary integer
Timer server interaction • Interaction with time service like echo server • Server sits at well known port • Waits for UDP message • Responds with UDP message containing 32-bit current time
The Complexity of Servers • Sequential servers are simple • Process one request at a time • Assume OS queues the requests if server busy • Queue will not get too long since work is trivial • Usually more complex than that • Must accommodate multiple concurrent requests • Server typically has two parts • Single master program to accept new requests • Set of copies to handle individual requests
Server performs following steps: • Open port • Opens the well-known port where it can be reached • Wait for client • Start copy • Invoke independent, concurrent copy of itself • Copy handles the one request then terminates • Continue • Go to wait state while new copy handles request
Processing requests proceeds concurrently • New copy for each request • Short requests finish earlier than long requests • Independent of the order in which they are started • Advantage of concurrent server: • Speed • Disadvantage of concurrent server: • Complexity (more difficult to construct)
Other forms of complexity arise as well • Must enforce authorization & protection rules • Server programs execute with highest privilege • Cannot blindly honor requests from other sites • Must protect themselves against errors • May get malformed requests • May get requests that cause them to abort
Broadcasting a Request • Maybe client will not know server address • When booting, can use DHCP to obtain an address • But does not know address of DHCP server • For protocols where client does not know the address of a server, the client-server paradigm permits client to broadcast requests
Alternatives to Client-Server • ARP protocol (Chap 5) • Clients ask for information • ARP minimizes such interactions • Uses cache of answers to improve later queries • Improves performance when recent history of queries is a good indicator of future use • Does not change essence of client-server interaction • Program executes until needs information • Then becomes client to obtain the information • Caching lowers the cost for all except the first process
How to lower cost for the first request? • In a distributed system, do precollection • Background activities collect and propagate information before any program requests it • Basis for UNIX ruptime command • Reports CPU load and time since system startup • Background program on each machine is used • Periodically broadcasts information • Collects incoming information and stores in a file • Each machine always has a copy of latest info • Client never has to access the network • Reads info from secondary storage
Chief advantage of precollection is speed • Information available locally without delay • Main disadvantage: potential to be wasteful • Uses processor time and network bandwidth • Even when no one cares about the data being collected • Cost for reading and processing broadcasts is high • Precollection is not among most popular alternatives to client-server
Summary • Distributed programs need communication • Often use client-server interaction • Server process awaits request; then responds • Client program makes request, sends, waits • Client can send request directly or broadcast • Broadcast useful on local network • Machine not need to know address of server
Servers can use internet protocols like UDP • Accept and respond to requests across internet • Can communicate with physical frames • Restricted to single physical network • Precollection is an alternative to the client-server model • Precollects information to avoid delays