Cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28.

Slides:



Advertisements
Similar presentations
Nonblocking I/O Blocking vs. non-blocking I/O
Advertisements

Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee Community.
Concurrency: Deadlock and Starvation Chapter 6. Deadlock Permanent blocking of a set of processes that either compete for system resources or communicate.
Guide to TCP/IP, Third Edition
I/O Multiplexing Road Map: 1. Motivation 2. Description of I/O multiplexing 3. Scenarios to use I/O multiplexing 4. I/O Models  Blocking I/O  Non-blocking.
Today’s topic Issues about sending structures with TCP. Server design alternatives: concurrent server and multiplexed server. I/O multiplexing.
28.2 Functionality Application Software Provides Applications supply the high-level services that user access, and determine how users perceive the capabilities.
Data Communications and Networking (Third Edition)
Slide 1 Client / Server Paradigm. Slide 2 Outline: Client / Server Paradigm Client / Server Model of Interaction Server Design Issues C/ S Points of Interaction.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
Internet Applications: Telnet, Ping and Traceroute.
Precept 3 COS 461. Concurrency is Useful Multi Processor/Core Multiple Inputs Don’t wait on slow devices.
I/O Hardware n Incredible variety of I/O devices n Common concepts: – Port – connection point to the computer – Bus (daisy chain or shared direct access)
1 Data Communications and Networking Socket Programming Part II: Design of Server Software Reference: Internetworking with TCP/IP, Volume III Client-Server.
McGraw-Hill©The McGraw-Hill Companies, Inc., 2004 Application Layer PART VI.
Client Server Model The client machine (or the client process) makes the request for some resource or service, and the server machine (the server process)
1 Concurrency: Deadlock and Starvation Chapter 6.
Department of Electronic Engineering City University of Hong Kong EE3900 Computer Networks Transport Protocols Slide 1 Transport Protocols.
An Introduction to Internetworking. Algorithm for client-server communication with UDP (connectionless) A SERVER A CLIENT Create a server-socket (listener)and.
Client Server Model and Software Design TCP/IP allows a programmer to establish communication between two application and to pass data back and forth.
Chapter 13: I/O Systems I/O Hardware Application I/O Interface
Chapter 26 Client Server Interaction Communication across a computer network requires a pair of application programs to cooperate. One application on one.
Client Software Design Objectives: Understand principles of C/S design, with focus on clients Review Windows implementations of Socket functions.
Cs423-cotter1 Example Client Program Reference Comer & Stevens, Chapter 7.
Process-to-Process Delivery:
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
TRANSPORT LAYER T.Najah Al-Subaie Kingdom of Saudi Arabia Prince Norah bint Abdul Rahman University College of Computer Since and Information System NET331.
1 Concurrency: Deadlock and Starvation Chapter 6.
1 Transport Layer Computer Networks. 2 Where are we?
Socket Programming References: redKlyde ’ s tutorial set Winsock2 for games (gamedev.net)
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
LWIP TCP/IP Stack 김백규.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 OSI Transport Layer Network Fundamentals – Chapter 4.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Chapter 4: Interprocess Communication‏ Pages
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
Nonblocking I/O Blocking vs. non-blocking I/O Nonblocking input, output, accept, and connect Readings –UNP Ch16 1.
The Socket Interface Chapter 21. Application Program Interface (API) Interface used between application programs and TCP/IP protocols Interface used between.
The Socket Interface Chapter 22. Introduction This chapter reviews one example of an Application Program Interface (API) which is the interface between.
1 Server Design Discuss Design issues for Servers Review Server Creation in Windows.
1 Example Servers Pt 1 Objective: To discuss key aspects of various server implementations.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
I/O Multiplexing. TCP Echo Client: I/O operation is sequential !! tcpcliserv/tcpcli01.c: lib/str_cli.c: TCP Client TCP Server stdin stdout fgets fputs.
Position of application layer. Application layer duties.
Example Servers Pt 2 Objective: To discuss key aspects of various server implementations.
Client-Server Model of Interaction Chapter 20. We have looked at the details of TCP/IP Protocols Protocols Router architecture Router architecture Now.
Processes CSCI 4534 Chapter 4. Introduction Early computer systems allowed one program to be executed at a time –The program had complete control of the.
1 Client-Server Interaction. 2 Functionality Transport layer and layers below –Basic communication –Reliability Application layer –Abstractions Files.
Client/Server Socket Programming Project
The Client-Server Model And the Socket API. Client-Server (1) The datagram service does not require cooperation between the peer applications but such.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 5.
Single Process, Concurrent, Connection-Oriented Servers (TCP) (Chapter 12)
The Client Server Model And Software Design
Berkeley Socket Abstraction
Chapter 6 Concurrency: Deadlock and Starvation Operating Systems: Internals and Design Principles, 6/E William Stallings.
I/O Multiplexing Chap 6. I/O Models  Blocking I/O Model  Nonblocking I/O Model  I/O Multiplexing Model  Signal Driven I/O Model  Asynchronous I/O.
1 Dimension of Server Designs r Iterative vs Concurrent r Connection-oriented vs. connectionless r Stateful and stateless m Constrained by application.
Netprog: Client/Server Issues1 Issues in Client/Server Programming Refs: Chapter 27.
McGraw-Hill Chapter 23 Process-to-Process Delivery: UDP, TCP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Client-Server Programming and Applications. References Douglas Comer, David Stevens, “Internetworking with TCP/IP: Client-Server Programming and Applications”,
TCP/IP1 Address Resolution Protocol Internet uses IP address to recognize a computer. But IP address needs to be translated to physical address (NIC).
R Some of these slides are from Prof Frank Lin SJSU. r Minor modifications are made. 1.
1 Issues in Client/Server Refs: Chapter 27 Case Studies RFCs.
File Transfer and access
Client/Server Example
Client-Server Interaction
Lecture 4 Socket Programming Issues
Issues in Client/Server Programming
Presentation transcript:

cs423-cotter1 Concurrency Issues in Client/Server Applications Chapters 15,16, 28

cs423-cotter2 Server Concurrency Control Must choose between Iterative or Concurrent –How many clients may query server? –How often will clients Query? –What mode of query will be used? –How long will service take?

cs423-cotter3 Server Concurrency Control Must choose between Iterative or Concurrent –How many clients may query server? –How often will clients Query? –What mode of query will be used? –How long will service take? If concurrent, must choose the level of concurrency –Apparent or real concurrency –Variable number of client threads –Fixed Maximum number of threads

cs423-cotter4 Server Concurrency Models Thread on demand –One thread per session –One thread per request

cs423-cotter5 Server Concurrency Models Thread on demand –One thread per session –One thread per request Thread Pool –Create thread pool –Allocate threads to queries as needed. –When query has been served, return thread to pool –When all threads busy, queue or discard other queries

cs423-cotter6 Socket Pre-allocation Techniques Associate a thread (or a thread pool) with each different service For TCP, associate each thread with the service socket, such that when a query arrives, one (and only one) thread will have accept unblocked, will create a new socket for this query, handle the query, and then return to accept. For UDP, each request is a single datagram, which gets assigned to a single slave thread.

cs423-cotter7 Concurrent Connection-oriented Master slave Port

cs423-cotter8 Concurrent Connectionless Master slave Port

cs423-cotter9 Delayed Concurrency in Servers Concurrency helpful when the cost of a new process (thread) is less than service time for the request. May vary by request. (Some database queries are short and others are long).

cs423-cotter10 Delayed Concurrency in Servers Concurrency helpful when the cost of a new process (thread) is less than service time for the request. May vary by request. (Some database queries are short and others are long). Start service iteratively and set timer. If timer expires, create new thread to finish service. Start new threads based on service requested (where multiple services are available).

cs423-cotter11 Concurrency in Clients Why? –Easier to program, because concurrency forces modularity –Easier to maintain, also because of modularity –Can interact with several servers at once –Allows the user to interact with server, even when a call is blocked.

cs423-cotter12 Concurrency in Clients Example Database query - “residents on Elm Street” Response may be short (in Lone Jack).... or very long (in KCMO)

cs423-cotter13 Concurrency in Clients Example Database query - “residents on Elm Street” Response may be short (in Lone Jack).... or very long (in KCMO) How does the user know when to abort a “failed” query? Might query server for status... Might terminate current query (if server is too slow) and restart on another server...

cs423-cotter14 Functional Concurrency in Clients Use multiple threads to perform different actions –One thread manages input (keyboard) –One thread manages input to socket –One thread manages output from socket –One thread manages control interaction with server –etc.

cs423-cotter15 Concurrency in Clients Multiple Servers Allows multiple accesses at the same time... so that performance measures (round trip delay, lost packets, etc.) are all taken against the same network environment. Faster than iterative model

cs423-cotter16 Concurrency in Clients Issues Concurrency Model: May use real or apparent concurrency (single threaded or multi-threaded). OS Support for concurrency: Some systems allow sharing memory between threads, while others may not. Functional Decomposition: What operations might be done in parallel, and which need to be done sequentially?

cs423-cotter17 Concurrency in Clients Singly threaded Allows memory sharing between connections May (or may not) overload, depending on rate of data exchange with multiple connections May deadlock!!

cs423-cotter18 Concurrent Client (TCPtecho) #include,,, #defineBUFSIZE4096/* write buffer size*/ #defineCCOUNT64*1024/* default character count*/ #defineWSVERSMAKEWORD(2, 0) #defineMIN(x, y)((x)>(y) ? (y) : (x)) #defineUSAGE"usage: TCPtecho [ -c count ] host1 host2...\n” struct hdat { char*hd_name;/* host name */ SOCKET hd_sock;/* host socket descriptor*/ unsigned hd_rc;/* recv character count */ unsigned hd_wc;/* send character count */ } hdat[FD_SETSIZE];/* fd to host name mapping*/ charbuf[BUFSIZE];/* read/write data buffer*/ voidTCPtecho(fd_set *, int); intreader(struct hdat *, fd_set *); voidwriter(struct hdat *, fd_set *); longmstime(u_long *);

cs423-cotter19 Concurrent Client (TCPtecho) void main(int argc, char *argv[]) { intccount = CCOUNT, i, hcount = 0, fd; unsigned longone = 1; fd_setafds; WSADATAwsdata; if (WSAStartup(WSVERS, &wsdata)) errexit("WSAStartup failed\n"); FD_ZERO(&afds); for (i=1; i<argc; ++i) { if (strcmp(argv[i], "-c") == 0) { if (++i < argc && (ccount = atoi(argv[i]))) continue; errexit(USAGE); }/* else, a host */

cs423-cotter20 Concurrent Client (TCPtecho) fd = connectTCP(argv[i], "echo"); if (ioctlsocket(fd, FIONBIO, &one)) { fprintf(stderr,"can't mark nonblocking (host %s): %d\n", argv[i], GetLastError()); continue; } hdat[hcount].hd_name = argv[i]; hdat[hcount].hd_sock = fd; hdat[hcount].hd_rc = hdat[hcount].hd_wc = ccount; ++hcount; FD_SET(fd, &afds); } TCPtecho(&afds, hcount); WSACleanup(); exit(0);}

cs423-cotter21 Concurrent Client (TCPtecho) void TCPtecho(fd_set *pafds, int hcount) { fd_setrfds, wfds;/* read/write fd sets*/ fd_setrcfds, wcfds;/* read/write fd sets (copy)*/ intfd, hndx, i; for (i=0; i<BUFSIZE; ++i)/* echo data*/ buf[i] = 'D'; memcpy(&rcfds, pafds, sizeof(rcfds)); memcpy(&wcfds, pafds, sizeof(wcfds)); (void) mstime((u_long *)0);/* set the epoch */

cs423-cotter22 Concurrent Client (TCPtecho) while (hcount) { memcpy(&rfds, &rcfds, sizeof(rfds)); memcpy(&wfds, &wcfds, sizeof(wfds)); if (select(FD_SETSIZE, &rfds, &wfds, (fd_set *)0, (struct timeval *)0) == SOCKET_ERROR) errexit("select failed: error %d\n",GetLastError()); for (hndx=0; hndx<hcount; ++hndx) { fd = hdat[hndx].hd_sock; if (FD_ISSET(fd, &rfds)) if (reader(&hdat[hndx], &rcfds) == 0){/* host done*/ for (i=hndx+1; i<hcount; ++i) hdat[i-1]=hdat[i]; hcount--; continue; } if (FD_ISSET(fd, &wfds)) writer(&hdat[hndx], &wcfds); }}}

cs423-cotter23 Concurrent Client (TCPtecho) intreader(struct hdat *phd, fd_set *pfdset) {... } voidwriter(struct hdat *phd, fd_set *pfdset) {... } longmstime(u_long *pms) {... }

cs423-cotter24 Deadlock in Client/Server Systems A situation where computation cannot proceed because a set or 2 or more components in the system is blocked and each component is waiting on another component in the set. Cannot be released through an external input. Often difficult to detect or prove, because it may depend on a particular, unusual sequence of events.

cs423-cotter25 Deadlock Between Client & Server May use request / response model to avoid deadlock. Must ensure that protocol design is “tight”. Remove ambiguities in the design. Assign responsibility for communication synchronization. (One side always starts)

cs423-cotter26 Starvation in Client/Servers Occurs when some clients cannot obtain service because other clients or processes are monopolizing the server resources. Results in unfair allocation of services

cs423-cotter27 Starvation in Client/Servers Occurs when some clients cannot obtain service because other clients or processes are monopolizing the server resources. Results in unfair allocation of services Delays waiting for a client to transmit (blocking on receive) can be managed through timeouts. For busy / malicious clients, servers multithreading or non-blocking can be used.

cs423-cotter28 Livelock in Clients / Servers Like deadlock, livelock results from circular dependency among processes and resources. System is locked into an endless self-generating sequence of commands that ultimately consumes all system resources.

cs423-cotter29 Livelock in Clients / Servers Like deadlock, livelock results from circular dependency among processes and resources. System is locked into an endless self- generating sequence of commands that ultimately consumes all system resources. Example: –File Server with time stamp logging. –Livelock occurs if a remote call to time is used –First file request comes in. Time stamp requires time (which generates an incoming message to file server). Incoming time response looks like a file request, which requires a new time stamp.....

cs423-cotter30 Planning for Concurrency Consider what system resources should be consumed by the server Consider what the demand for the service(s) is Provide limits (threads, processes, memory) that are appropriate. Incorporate logging into the server to track program problems, congestion, etc. Consider “livelock” problems when working with multiple services.