Concurrent Processing in Client-Server Software Prof. Chuan-Ming - - PowerPoint PPT Presentation

concurrent processing in client server software
SMART_READER_LITE
LIVE PREVIEW

Concurrent Processing in Client-Server Software Prof. Chuan-Ming - - PowerPoint PPT Presentation

Mobile Computing & Software Engineering Lab Concurrent Processing in Client-Server Software Prof. Chuan-Ming Liu Computer Science and Information Engineering National Taipei University of Technology Taipei, TAIWAN MCSE Lab, NTUT, TAIWAN


slide-1
SLIDE 1

MCSE Lab, NTUT, TAIWAN 1

Mobile Computing & Software Engineering Lab

Concurrent Processing in Client-Server Software

  • 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

Concurrency in Networks Concurrency in Servers Terminology and Concepts Example for Concurrent Process Creation Executing New Code Context Switching and Protocol Software Design Concurrency and Asynchronous I/O

slide-3
SLIDE 3

NTUT, TAIWAN 3

Mobile Computing & Software Engineering Lab

Concurrency in Networks

Concurrency

provides much of the power behind client- server interaction makes the software difficult to design and build

slide-4
SLIDE 4

NTUT, TAIWAN 4

Mobile Computing & Software Engineering Lab

Concurrency in Network

Concurrency = simultaneous computing virtually or practically

Time sharing scheme Multiprocessing

Concurrent processing is fundamental to distributed computing and occurs in

Network A computer system

slide-5
SLIDE 5

NTUT, TAIWAN 5

Mobile Computing & Software Engineering Lab

Single Network

D C B A

slide-6
SLIDE 6

NTUT, TAIWAN 6

Mobile Computing & Software Engineering Lab

Computer System

A time sharing system User 1 User 2 User 3

ftp rlogin http

slide-7
SLIDE 7

NTUT, TAIWAN 7

Mobile Computing & Software Engineering Lab

Concurrency in Networks

Besides, the set of all clients on a set

  • f machines can execute concurrently

Internet

c5 c4 c1 c3 c2

slide-8
SLIDE 8

NTUT, TAIWAN 8

Mobile Computing & Software Engineering Lab

Concurrency in Networks

Client software does not require any special attention or effort on the part of the programmer to make it usable concurrently i.e. each individual client operates much like any conventional program

slide-9
SLIDE 9

NTUT, TAIWAN 9

Mobile Computing & Software Engineering Lab

Concurrency in Servers

In contrast to a client, concurrency within a server requires considerable effort

Internet

c5 c4 c1 c3 server

slide-10
SLIDE 10

NTUT, TAIWAN 10

Mobile Computing & Software Engineering Lab

Terminology and Concepts

Process (task, or job) Threads Local and global variables Procedure calls

slide-11
SLIDE 11

NTUT, TAIWAN 11

Mobile Computing & Software Engineering Lab

Process

Fundamental unit of computation An address space + at least one thread of execution Information associated with a process

instruction pointer (associated with a thread) identity of the user compiled program memory locations for the program text and data

slide-12
SLIDE 12

NTUT, TAIWAN 12

Mobile Computing & Software Engineering Lab

Process

The process concept includes only the active execution of a computation, not the static version of the program In a uniprocessor architecture, the single CPU can only execute one thread at any time instance

To achieve concurrency by switching the CPU among all threads rapidly Concurrent execution

slide-13
SLIDE 13

NTUT, TAIWAN 13

Mobile Computing & Software Engineering Lab

Process

On a multiprocessor machine, all CPUs can execute simultaneously Keep in mind, the key issue is

transparency

slide-14
SLIDE 14

NTUT, TAIWAN 14

Mobile Computing & Software Engineering Lab

Threads

Threads of execution (lightweight processes)

Using instruction pointer Having a copy of local variables Independent from the other threads Associated with a single process Sharing all the global variables Sharing all the resources allocated to the process, including file descriptors

slide-15
SLIDE 15

NTUT, TAIWAN 15

Mobile Computing & Software Engineering Lab

Threads

A concurrent program can be written either to create separate processes or to create multiple threads within a single process

slide-16
SLIDE 16

NTUT, TAIWAN 16

Mobile Computing & Software Engineering Lab

Programs vs. Threads

When multiple threads execute a piece of code concurrently, each thread has its own independent copy of the local variables associated with the code Each process receives a separate copy of global variables; if multiple threads execute within a single process, they each have a copy of local variables, but all share the process copy of the global variables

slide-17
SLIDE 17

NTUT, TAIWAN 17

Mobile Computing & Software Engineering Lab

Procedure calls

In a procedure-oriented language, like C, executed code can contain calls to subprograms (procedures or functions) Using a stack to handle procedure calls When multiple threads execute a piece of code concurrently, each has its own run-time stack of procedure activation records

slide-18
SLIDE 18

NTUT, TAIWAN 18

Mobile Computing & Software Engineering Lab

Example on Concurrency Process

Run sum.c on-line System function fork

Divides the running program into two identical processes Starts a thread executing the new process in the same place of the code

Inserting fork into sum.c and run sum_fork.c

slide-19
SLIDE 19

NTUT, TAIWAN 19

Mobile Computing & Software Engineering Lab

Example

slide-20
SLIDE 20

NTUT, TAIWAN 20

Mobile Computing & Software Engineering Lab

Example on Concurrency Process

/* sum.c - A conventional C programe that sums integers from 1 to 5 */ #include <stdlib.h> #include <stdio.h> int sum; /* sum is a global variable */ main(){ int i; /* i is a local variable */ sum=0; for (i=1;i<=5; i++){ /* iterate i from 1 to 5 */ printf("The value of i is %d\n", i); fflush(stdout); /* flush the buffer */ sum += i; } printf("The sum is %d\n", sum); exit(0); /* terminate the program */ }

slide-21
SLIDE 21

NTUT, TAIWAN 21

Mobile Computing & Software Engineering Lab

Example on Concurrency Process

/* sum.c - A conventional C programe that sums integers from 1 to 5 */ #include <stdlib.h> #include <stdio.h> int sum; /* sum is a global variable */ main(){ int i; /* i is a local variable */ sum=0; fork(); /* create a new process */ for (i=1;i<=5; i++){ /* iterate i from 1 to 5 */ printf("The value of i is %d\n", i); fflush(stdout); /* flush the buffer */ sum += i; } printf("The sum is %d\n", sum); exit(0); /* terminate the program */ }

slide-22
SLIDE 22

NTUT, TAIWAN 22

Mobile Computing & Software Engineering Lab

Concurrency Process

In a uniprocess computer, OS allocates the available CPU power for a short time to each threads in round-robin fashion Timesliceing mechanism

Allocate the available processing equally among all available threads

slide-23
SLIDE 23

NTUT, TAIWAN 23

Mobile Computing & Software Engineering Lab

Single-Threaded Process Assumption

fork()

not duplicate all of the threads create a copy of a running process and the new process contains exactly one thread

The newly created process by fork() is said to be a singly-threaded process Although a process can contain multiple threads, the newly created process that results from a call to fork is singly-threaded.

slide-24
SLIDE 24

NTUT, TAIWAN 24

Mobile Computing & Software Engineering Lab

Processes Diverge

New process generated by fork

Not absolutely identical to the original process fork() returns a value to the original process and the new process

0 to the new process A positive integer to the original process to identify the newly created process

The value returned to the original is called a process identifier or process id (pid)

slide-25
SLIDE 25

NTUT, TAIWAN 25

Mobile Computing & Software Engineering Lab

Processes Diverge

#include <stdlib.h> #include <stdio.h> main(){ int pid; /* child process id */ pid = fork(); if (pid !=0){ /* parent process */ printf("The parent process prints this.\n"); } else { printf("The child process prints this.\n"); } exit(0); /* terminate the program */ }

slide-26
SLIDE 26

NTUT, TAIWAN 26

Mobile Computing & Software Engineering Lab

slide-27
SLIDE 27

NTUT, TAIWAN 27

Mobile Computing & Software Engineering Lab

Executing New Code

UNIX provide s a mechanism that allows any process to execute an independent, separate- compiled program The mechanism consists of a system call, execve, that replace the code that the currently executing process runs with the code from the new program Way to new process that executes the object code from a file, a process call fork and execve execve is very important for server to handle diverse services

slide-28
SLIDE 28

NTUT, TAIWAN 28

Mobile Computing & Software Engineering Lab

Context Switching

when the OS switch one thread to another, a context switch occurs Context switching between threads in a process requires less overhead than switching between a thread in one process and a thread in another

slide-29
SLIDE 29

NTUT, TAIWAN 29

Mobile Computing & Software Engineering Lab

Context Switching

Context switching needs CPU; therefore, is counted as an overhead to support concurrent processing To avoid unnecessary overhead, protocol software should be designed to minimize the context switching

slide-30
SLIDE 30

NTUT, TAIWAN 30

Mobile Computing & Software Engineering Lab

Concurrency and Asynchronous I/O

OS allows a single application to initiate and control concurrent I/O System call select, is such an operation which is used to find out which I/O device becomes ready first.