client design client design
play

Client Design Client Design Srinidhi Varadarajan Topics Topics - PowerPoint PPT Presentation

Client Design Client Design Srinidhi Varadarajan Topics Topics Concurrency in client Concepts Approaches TCP timed echo example Why Use Concurrency in Servers Servers ? ? Why Use Concurrency in Improved response time


  1. Client Design Client Design Srinidhi Varadarajan

  2. Topics Topics � Concurrency in client – Concepts – Approaches � TCP timed echo example

  3. Why Use Concurrency in Servers Servers ? ? Why Use Concurrency in � Improved response time � Can be used to eliminate deadlocks � Simplifies implementation of multiprotocol and multiservice servers � Threads work on uniprocessors, but can take advantage of multiprocessors Except for multiprocessor execution, none of these reasons directly applies to clients.

  4. Why Use Concurrency in Clients Clients ? (1) ? (1) Why Use Concurrency in � Can separate functionality into distinct components, with advantages for code design and maintenance – Requester (sends requests) – Receiver and processor – User interface – Control � Client can simultaneously contact multiple servers – Distributed search – Compound documents with elements on multiple servers

  5. Why Use Concurrency in Clients Clients ? (2) ? (2) Why Use Concurrency in � Allows interaction while a request is in progress – Status checks – Abort operation – Modify parameters � Potential performance advantage for overlapping operations – Processing, file I/O, and network I/O – Overlap operations on multiple connections � Provides asynchrony – Set of multiple tasks can be performed without the imposition of a strict ordering

  6. Implementing Concurrency in Clients Implementing Concurrency in Clients � Two approaches (as for servers) – Multiple threads, using pthread_create() – Apparent concurrency, using select() � Multiple threads – Each thread performs a distinct set of tasks, or – Each thread performs a separate request or other task, or – Some combination of the above � Apparent concurrency – Single thread uses select() for asynchronous I/O – Time-outs should be included to prevent client deadlock

  7. Multithreaded Client (1) Multithreaded Client (1) � Single network socket (TCP or UDP) � Functional decomposition CLIENT MASTER Control Input Output control user socket user input output

  8. Multithreaded Client (2) Multithreaded Client (2) Multiple network sockets � Hybrid approach, since there is also functional � decomposition CLIENT MASTER Slave 1 Slave n Renderer input socket socket output

  9. Single- -Threaded Concurrent Client Threaded Concurrent Client Single Single thread uses select() call to find active � socket and file descriptors Decomposition by socket and functions � CLIENT input socket socket output

  10. TCPtecho Example (1) Example (1) TCPtecho � TCPtecho – Single client that accesses multiple servers (in this case, ECHO servers) – Utility is to simultaneously measure network throughput between the client and multiple servers � Basic tasks – Make connections to each server -- main() – Send data until all data is sent -- writer() – Receive data until all data is received -- reader()

  11. TCPtecho Example (2) Example (2) TCPtecho � writer() – For a given host … • Send as much data as possible up to total amount to send • Reduce amount left to send by amount actually sent • If all is sent, shutdown connection for send with shutdown() – writer() called when a socket is ready for send() – Since data to be sent may be larger than what can be sent, sockets are set to “non-blocking” to ensure that send() won’t block • ioctl( fd, FIONBIO, &one )

  12. TCPtecho Example (3) Example (3) TCPtecho � reader() – For a given host … • Receive as much data as possible, up to buffer size • Reduce amount received from amount to receive • If all is received close the connection with close()

  13. ioctl() () ioctl � ioctl( socket, command, arg_ptr ) � Commands – FIONBIO: enable non-blocking mode – FIONREAD: determine amount of data pending in the network’s input buffer – SIOCATMARK: determine whether or not all out of band data has been read � In TCPtecho – u_long one = 1 – ioctl(fd, FIONBIO, &one )

  14. Getsockopt() and () and Setsockopt Setsockopt() () Getsockopt � setsockopt() and getsockopt() also used to monitor and control socket operation � For example, to force TCP to immediately send data int optval = 1; setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (const char *) &optval, sizeof(int));

  15. You should now be able to … You should now be able to … � Describe the need for concurrency in a client � Describe approaches to making a client concurrent � Analyze and design a simple concurrent client � Use ioctlsocket() to control socket options

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend