Concurrency in Clients Prof. Chuan-Ming Liu Computer Science and - - PowerPoint PPT Presentation

concurrency in clients
SMART_READER_LITE
LIVE PREVIEW

Concurrency in Clients Prof. Chuan-Ming Liu Computer Science and - - PowerPoint PPT Presentation

Mobile Computing & Software Engineering Lab Concurrency in Clients Prof. Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Taipei, TAIWAN NTUT, TAIWAN 1 Mobile Computing & Software


slide-1
SLIDE 1

NTUT, TAIWAN 1

Mobile Computing & Software Engineering Lab

Concurrency in Clients

  • Prof. Chuan-Ming Liu

Computer Science and Information Engineering National Taipei University of Technology Taipei, TAIWAN

slide-2
SLIDE 2

NTUT, TAIWAN 2

Mobile Computing & Software Engineering Lab

Introduction

This chapter considers the issue of concurrency in client software It shows an example client that illustrates concurrent operation

slide-3
SLIDE 3

NTUT, TAIWAN 3

Mobile Computing & Software Engineering Lab

The Advantage of Concurrency

Servers use concurrency for two main reasons:

Concurrency can improve the observed response time (and therefore the overall throughput to all clients) Concurrency can eliminate potential deadlocks

slide-4
SLIDE 4

NTUT, TAIWAN 4

Mobile Computing & Software Engineering Lab

The Advantage of Concurrency (cont.)

Concurrency does have advantages in clients:

Concurrent implementations can be easier to program because they separate functionality into conceptually separate components Concurrent implementations can be easier to maintain and extend because they make the code modular

slide-5
SLIDE 5

NTUT, TAIWAN 5

Mobile Computing & Software Engineering Lab

The Advantage of Concurrency (cont.)

Concurrent clients can contact several servers at the same time, either to compare response time

  • r merge the results the servers return

Concurrency can allow the user to change parameters, inquire about the client status, or control processing dynamically

slide-6
SLIDE 6

NTUT, TAIWAN 6

Mobile Computing & Software Engineering Lab

The Advantage of Concurrency (cont.)

This chapter will focus on the idea of interacting with multiple servers at the same time The key advantage of using concurrency in clients lies in asynchrony – allows a client to handle multiple tasks simultaneously without imposing a strict execution order on them

slide-7
SLIDE 7

NTUT, TAIWAN 7

Mobile Computing & Software Engineering Lab

The Motivation for Exercising Control

One possible use of asynchrony arises from the need to separate control functions from normal processing A user who invokes a client may have little

  • r no idea how long it will take to receive a

response or how large that response will be

slide-8
SLIDE 8

NTUT, TAIWAN 8

Mobile Computing & Software Engineering Lab

The Motivation for Exercising Control (cont.)

An appropriately designed concurrent client can permit the user to continue to interact with the client while the client waits for a response The user can find out whether any data has been received, choose to send a different request, or to terminate the communication gracefully

slide-9
SLIDE 9

NTUT, TAIWAN 9

Mobile Computing & Software Engineering Lab

The Motivation for Exercising Control (cont.)

For example, an concurrent implementation can read and process input from the user’s keyboard or mouse concurrently with database search

slide-10
SLIDE 10

NTUT, TAIWAN 10

Mobile Computing & Software Engineering Lab

Concurrent Contact with Multiple Servers

Concurrency can allow a single client to contact several servers at the same time and to report to the user as soon as it receives a response from any of them Consider how concurrency can enhance a client that uses ECHO to measure throughput

Because it makes all measurements at the same time, they are faster than a non-concurrent client, and are all affected equally by the loads on the CPU and the local network

slide-11
SLIDE 11

NTUT, TAIWAN 11

Mobile Computing & Software Engineering Lab

Implementing Concurrent Clients

Like concurrent servers, most concurrent client implementations follow one of the two basic approaches:

A multi-thread implementation that each thread handles one function A single thread implementation that uses select to handle multiple I/O events asynchronously

slide-12
SLIDE 12

NTUT, TAIWAN 12

Mobile Computing & Software Engineering Lab

Implementing Concurrent Clients (cont.)

As Fig. 17.1 illustrates, multiple threads allow a connection-oriented client to separate I/O processing

An input thread reads from standard input, formulates requests, and sends them to the server over the TCP connection A separate output thread receives responses from the server and writes them to the standard

  • utput

A control thread accepts commands from the user that control processing

slide-13
SLIDE 13

NTUT, TAIWAN 13

Mobile Computing & Software Engineering Lab

Figure 17.1

slide-14
SLIDE 14

NTUT, TAIWAN 14

Mobile Computing & Software Engineering Lab

Single-Thread Implementation

  • Fig. 17.2 shows the process structure used to

provide apparent concurrency in a single thread, connection-oriented client (Algorithm 8.5, the examples in Ch 13 through 15) If the input descriptor becomes ready, the client reads the input and either stores it for later use or acts on it immediately If a TCP socket becomes ready for output, the client prepares and sends a request across a TCP connection

slide-15
SLIDE 15

NTUT, TAIWAN 15

Mobile Computing & Software Engineering Lab

Figure 17.2

slide-16
SLIDE 16

NTUT, TAIWAN 16

Mobile Computing & Software Engineering Lab

Algorithm 8.5

slide-17
SLIDE 17

NTUT, TAIWAN 17

Mobile Computing & Software Engineering Lab

Single-Thread Implementation (cont.)

If a TCP socket becomes ready for input, the client reads the response that the server has sent and handles it The client reads input or responses from the server at whatever rate they are generated The client will continue to read and honor control commands even if the server fails to respond

slide-18
SLIDE 18

NTUT, TAIWAN 18

Mobile Computing & Software Engineering Lab

Single-Thread Implementation (cont.)

A single thread client can become deadlocked if it invokes a system function that blocks The programmer must be careful to ensure that the client does not block indefinitely waiting for an event that will not occur

slide-19
SLIDE 19

NTUT, TAIWAN 19

Mobile Computing & Software Engineering Lab

An Example Concurrent Client That Uses ECHO

  • Fig. 17.2a shows TCPtecho.c that uses the

ECHO service described in Ch 7 to measure network throughput to a set of machines

slide-20
SLIDE 20

NTUT, TAIWAN 20

Mobile Computing & Software Engineering Lab

Execution of the Concurrent Client

  • Fig. 17.3 shows sample output from three

separate executions of TCPtecho

slide-21
SLIDE 21

NTUT, TAIWAN 21

Mobile Computing & Software Engineering Lab

Figure 17.3

slide-22
SLIDE 22

NTUT, TAIWAN 22

Mobile Computing & Software Engineering Lab

Concurrency in the Example Code

A concurrent implementation of TCPtecho improves the program in two ways

Obtain a more accurate measure of the time required for each connection because congestion affects all connection equally A concurrent version makes TCPtecho more appealing to users (it offers faster response time than a sequential version

slide-23
SLIDE 23

NTUT, TAIWAN 23

Mobile Computing & Software Engineering Lab

Summary

Concurrent client implementation can offer faster response time and can avoid deadlock problems Concurrency can help designers separate control and status processing from normal input and output

slide-24
SLIDE 24

NTUT, TAIWAN 24

Mobile Computing & Software Engineering Lab

Summary (cont.)

We studied a TCP client that measures the time required to access the ECHO server

  • ne one or more machines

Avoid the differences in throughput caused by network congestion by making all measurements during the same time interval Appeals to users because it overlaps the measurements