Concurrent Processing in Client-Server Software

Similar documents
Concurrency. Stefan D. Bruda. Winter 2018

Process a program in execution; process execution must progress in sequential fashion. Operating Systems

CHAPTER 2: PROCESS MANAGEMENT

Chapter 3: Processes. Operating System Concepts 8th Edition,

Concurrent Server Design Multiple- vs. Single-Thread

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Processes. Process Concept

The Client Server Model and Software Design

Prepared by Prof. Hui Jiang Process. Prof. Hui Jiang Dept of Electrical Engineering and Computer Science, York University

Process. Prepared by Prof. Hui Jiang Dept. of EECS, York Univ. 1. Process in Memory (I) PROCESS. Process. How OS manages CPU usage? No.

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Processes. Overview. Processes. Process Creation. Process Creation fork() Processes. CPU scheduling. Pål Halvorsen 21/9-2005

Fall 2015 COMP Operating Systems. Lab #3

Module 4: Processes. Process Concept Process Scheduling Operation on Processes Cooperating Processes Interprocess Communication

Chapter 3: Process-Concept. Operating System Concepts 8 th Edition,

Chapter 4: Processes. Process Concept

Computer Systems Assignment 2: Fork and Threads Package

* What are the different states for a task in an OS?

Chapter 4: Processes

CS510 Operating System Foundations. Jonathan Walpole

Operating systems and concurrency - B03

CSC 1600 Unix Processes. Goals of This Lecture

CS 3733 Operating Systems

SMD149 - Operating Systems

518 Lecture Notes Week 3

Eastern Mediterranean University School of Computing and Technology Department of Information Technology. ITEC202 Operating Systems

Lecture Topics. Announcements. Today: Threads (Stallings, chapter , 4.6) Next: Concurrency (Stallings, chapter , 5.

Processes and Threads

Processes. CS 475, Spring 2018 Concurrent & Distributed Systems

3.1 Introduction. Computers perform operations concurrently

Operating System Labs. Yuanbin Wu

Unix Processes. What is a Process?

A process. the stack

CS370 Operating Systems Midterm Review

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

4.8 Summary. Practice Exercises

Chapter 3: Processes. Operating System Concepts 8 th Edition,

CS370: System Architecture & Software [Fall 2014] Dept. Of Computer Science, Colorado State University

Operating Systems. Figure: Process States. 1 P a g e

OPERATING SYSTEMS. UNIT II Sections A, B & D. An operating system executes a variety of programs:

Operating System Design

Chapter 3: Processes. Operating System Concepts 9 th Edit9on

Process Concept. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

OS 1 st Exam Name Solution St # (Q1) (19 points) True/False. Circle the appropriate choice (there are no trick questions).

CSC 539: Operating Systems Structure and Design. Spring 2006

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Lecture 2 Process Management

Processes. CS 416: Operating Systems Design, Spring 2011 Department of Computer Science Rutgers University

Processes. Dr. Yingwu Zhu

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Processes. Johan Montelius KTH

Operating Systems Comprehensive Exam. Spring Student ID # 3/16/2006

Processes. CS3026 Operating Systems Lecture 05

Chapter 3: Processes. Operating System Concepts Essentials 2 nd Edition

CS 475. Process = Address space + one thread of control Concurrent program = multiple threads of control

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

CS 333 Introduction to Operating Systems. Class 3 Threads & Concurrency. Jonathan Walpole Computer Science Portland State University

Operating Systems & Concurrency: Process Concepts

628 Lecture Notes Week 4

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

W4118 Operating Systems. Junfeng Yang

CSE 153 Design of Operating Systems Fall 2018

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

CSC 716 Advanced Operating System Fall 2007 Exam 1. Answer all the questions. The maximum credit for each question is as shown.

Process. Program Vs. process. During execution, the process may be in one of the following states

UNIX Input/Output Buffering

Processes. OS Structure. OS Structure. Modes of Execution. Typical Functions of an OS Kernel. Non-Kernel OS. COMP755 Advanced Operating Systems

Chapter 3 Processes. Process Concept. Process Concept. Process Concept (Cont.) Process Concept (Cont.) Process Concept (Cont.)

Chapter 3: Processes. Chapter 3: Processes. Process in Memory. Process Concept. Process State. Diagram of Process State

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Operating Systems Lab

REVIEW OF COMMONLY USED DATA STRUCTURES IN OS

Operating Systems Comprehensive Exam. Spring Student ID # 3/20/2013

Operating Systems. Computer Science & Information Technology (CS) Rank under AIR 100

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Dr. Rafiq Zakaria Campus. Maulana Azad College of Arts, Science & Commerce, Aurangabad. Department of Computer Science. Academic Year

Processes, Threads, SMP, and Microkernels

Part Two - Process Management. Chapter 3: Processes

Operating Systems. II. Processes

Chapter 3: Processes

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

Page 1. Analogy: Problems: Operating Systems Lecture 7. Operating Systems Lecture 7

The Big Picture So Far. Chapter 4: Processes

Processes and More. CSCI 315 Operating Systems Design Department of Computer Science

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Course: Operating Systems Instructor: M Umair. M Umair

Process Management! Goals of this Lecture!

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Chapter 4: Multithreaded

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Processes and Non-Preemptive Scheduling. Otto J. Anshus

External Data Representation (XDR)

CS 261 Fall Mike Lam, Professor. Processes

Mon Sep 17, 2007 Lecture 3: Process Management

fork System-Level Function

CPSC 341 OS & Networks. Threads. Dr. Yingwu Zhu

CS 322 Operating Systems Practice Midterm Questions

System Call. Preview. System Call. System Call. System Call 9/7/2018

Transcription:

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 1

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 NTUT, TAIWAN 2

Concurrency in Networks Concurrency provides much of the power behind clientserver interaction makes the software difficult to design and build NTUT, TAIWAN 3

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 NTUT, TAIWAN 4

Single Network A C D B NTUT, TAIWAN 5

Computer System A time sharing system ftp rlogin http User 1 User 2 User 3 NTUT, TAIWAN 6

Concurrency in Networks Besides, the set of all clients on a set of machines can execute concurrently c3 Internet c2 c4 c5 c1 NTUT, TAIWAN 7

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 NTUT, TAIWAN 8

Concurrency in Servers In contrast to a client, concurrency within a server requires considerable effort c3 Internet server c4 c5 c1 NTUT, TAIWAN 9

Terminology and Concepts Process (task, or job) Threads Local and global variables Procedure calls NTUT, TAIWAN 10

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 NTUT, TAIWAN 11

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 NTUT, TAIWAN 12

Process On a multiprocessor machine, all CPUs can execute simultaneously Keep in mind, the key issue is transparency NTUT, TAIWAN 13

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 NTUT, TAIWAN 14

Threads A concurrent program can be written either to create separate processes or to create multiple threads within a single process NTUT, TAIWAN 15

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 NTUT, TAIWAN 16

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 NTUT, TAIWAN 17

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 NTUT, TAIWAN 18

Example NTUT, TAIWAN 19

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 */ } NTUT, TAIWAN 20

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 */ } NTUT, TAIWAN 21

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 NTUT, TAIWAN 22

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. NTUT, TAIWAN 23

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) NTUT, TAIWAN 24

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 */ } NTUT, TAIWAN 25

NTUT, TAIWAN 26

Executing New Code UNIX provide s a mechanism that allows any process to execute an independent, separatecompiled 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 NTUT, TAIWAN 27

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 NTUT, TAIWAN 28

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 NTUT, TAIWAN 29

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. NTUT, TAIWAN 30