Course Introduction

Download Report

Transcript Course Introduction

r Some of these slides are from Prof Frank
Lin SJSU.
r Minor modifications are made.
1
Client-server model
Typical network app has two
pieces: client and server
Client:
application
transport
network
data link
physical
initiates contact with server
(“speaks first”)
typically requests service from
server,
for Web, client is implemented in
browser; for e-mail, in mail reader
Server:
provides requested service to client
e.g., Web server sends requested
Web page, mail server delivers email
request
reply
application
transport
network
data link
physical
2
More on Client Server Model
Clients initiate requests
Servers wait for incoming requests and provide services
Servers always up and running
Operating systems normally start servers automatically
when they start
More differences
Servers access system resources => special privileges
Servers sometimes handle security issues
3
Connectionless vs. ConnectionOriented Protocols
Connectionless protocols
UDP
Fast
Unreliable
Connection-oriented protocols
TCP
Slower
Reliable
Examples
4
Stateless vs. Stateful Protocols
Stateful protocols
Keeping states in the servers
Reducing the size and number of messages
Applications sometimes need session information
Stateless protocols
Simple
Protocol reliability
example
Stateless file server
Stateful file server
5
How to keep track of clients?
Two ways
End points (IP address, port number)
What is wrong?
Handles
A short identifier allocated by the server, stored
in server’s database and sent to the client
6
Keeping track of clients: handles
user accounts
shopping carts
Web portals
Advertising
Secretly collecting users’ browsing habits
What to do?
7
More on Stateful Protocols
Keeping correct states is challenging
What happens when clients crash and reboot?
What happens when messages arrive out of
order, get duplicated or get lost?
Keeping states sometimes poses security
risks
Tracking browsing patterns
Loss of confidential information (e.g. credit
card number, ssn)
8
Concurrent Processing
Concurrent Processing:
Why is it needed?
Achieving concurrent processing
Time sharing
multiprocessing
Concurrency in clients
no special efforts by client programmers
Concurrency in servers
Special efforts needed by server programmers
• Multiple processes
• Multiple threads
9
Processes and Threads
Processes
Fundamental unit of computation
An address space and at least one thread of
execution (instruction pointer)
Thread
Light-weight process
Program vs process
Static concept
10
Sharing of Variables
Local Variable Rule - When
multiple processes or
threads execute a piece of
code concurrently, each
creates its own independent
copy of the variables
associated with the code
(local variables)
int x;
for (i=1; i<=10; i++)
printf (“%d\n”, i+x);
Global Variable Rule - Each
process creates a copy of
global variables, but
multiple threads within a
single process share the
process’s global variables
11
Procedure Calls
Procedure Call Rule - When multiple threads execute a
piece of code concurrently, each has its own stack of
procedure activation records
Example - Putting the rules together!
12
Example of Concurrent Process
Creation
Example 1
Sequential processing
Example 2
Concurrent version
• Computationally light
• Computationally intensive
Both processes do the same job!
13
Sequential C Example
/* seq.c - A conventional C program that sums integers
from 1 to 5 */
#include <stdlib.h>
#include <stdio.h>
int sum;
/* global variable */
main() {
int i;
/* local variable */
sum = 0;
for (i=1; i<=5; i++) {
/* iterate from 1 to 5 */
printf(“The value of i is %d\n”, i);
fflush (stdout);
/* flush buffer */
sum += i;
}
printf (“The sum is %d\n”, sum);
exit (0);
}
14
Concurrent C Example
/* concurr.c - A concurrent C program that sums integers
from 1 to 5 */
#include <stdlib.h>
#include <stdio.h>
int sum;
/* global variable */
main() {
int i;
/* local variable */
sum = 0;
fork();
for (i=1; i<=5; i++) {
/* iterate from 1 to 5 */
printf(“The value of i is %d\n”, i);
fflush (stdout);
/* flush buffer */
sum += i;
}
printf (“The sum is %d\n”, sum);
exit (0);
}
15
Concurrent Processes (II)
Processes perform different tasks
Distinguished by the return value of fork()
fork and execve allow newly created processes to execute an
independent, separately-compiled program
/* sum.c - A concurrent C program that performs different
tasks for two processes */
#include <stdlib.h>
#include <stdio.h>
main() {
int pid;
/* local variable */
pid=fork();
if (pid != 0) {
/* original process */
printf(“The original process prints this.\n”);
} else {
/* newly created process */
printf (“The new process prints this.\n”);
}
exit(0);
}
16
Concurrency in I/O
Let us take a browser as an example
It needs to respond to input from users
Mouse clicks
Keyboard input
It needs to respond to input from the network
Downloaded web pages, images, …
It needs to send request to the network
Send a HTTP request
How to handle this scenario?
Asynchronous I/O (aka non-blocking I/O)
Concurrency in I/O
select system call
17