Announcements: CS 372 – introduction to computer networks* Assignment 2 is posted. 

advertisement
CS 372 – introduction to computer networks*
Wednesday June 30
Announcements:
 Assignment 2 is posted.
* Based in part on slides by Bechir Hamdaoui and Paul D. Paulson.
Acknowledgement: slides drawn heavily from Kurose & Ross
Chapter 2, slide: 1
Chapter 2: Application layer
 Principles of network
applications


app architectures
app requirements
 P2P file sharing
 Socket programming
with TCP
 Web and HTTP
 File transfer: FTP
Chapter 2, slide: 2
Web and HTTP
First some terminologies:
 Web page consists of objects
 Object can be HTML file, JPEG image, Java
applet, audio file,…
 Web page consists of base HTML-file which
includes several referenced objects
 Each object is addressable by a URL
 Example URL (Uniform Resource Locator):
www.someschool.edu/someDept/pic.gif
host name
path name
Chapter 2, slide: 3
HTTP overview: app architecture
HTTP: hypertext
transfer protocol
 Web’s appl-layer protocol
 client/server model


PC running
Explorer
client: browser that
requests, receives,
“displays” Web objects
server: Web server
sends objects in
response to requests
 HTTP 1.0: RFC 1945
Server
running
Apache Web
server
Mac running
Navigator
 HTTP 1.1: RFC 2068
Chapter 2, slide: 4
HTTP overview (continued)
Uses TCP:
 client initiates TCP
connection (creates socket)
to server, port 80
 server accepts TCP
connection from client
 HTTP messages exchanged
between browser (HTTP
client) and Web server
(HTTP server)
 TCP connection closed
HTTP is “stateless”
 server maintains no
information about
past client requests
aside
Protocols that maintain
“state” are complex!
 past history (state) must
be maintained
 if server/client crashes,
their views of “state” may
be inconsistent, must be
reconciled
Chapter 2, slide: 5
HTTP connections
Nonpersistent HTTP
 At most one object is
sent over a TCP
connection.
 HTTP/1.0 uses
nonpersistent HTTP
Persistent HTTP
 Multiple objects can
be sent over single
TCP connection
between client and
server.
 HTTP/1.1 uses
persistent connections
in default mode
Chapter 2, slide: 6
Nonpersistent HTTP
(contains text,
Suppose user enters URL
references to 10
www.someSchool.edu/someDepartment/home.index
jpeg images)
1a. HTTP client initiates TCP
connection to HTTP server
(process) at
www.someSchool.edu on port 80
2. HTTP client sends HTTP
request message (containing
URL) into TCP connection
socket. Message indicates
that client wants object
someDepartment/home.index
1b. HTTP server at host
www.someSchool.edu waiting
for TCP connection at port 80.
“accepts” connection, notifying
client
3. HTTP server receives request
message, forms response
message containing requested
object, and sends message
into its socket
time
Chapter 2, slide: 7
Nonpersistent HTTP (cont.)
4. HTTP server closes TCP
5. HTTP client receives response
connection.
message containing html file,
displays html. Parsing html
file, finds 10 referenced jpeg
objects
time 6. Steps 1-5 repeated for each
of 10 jpeg objects
Chapter 2, slide: 8
Non-Persistent HTTP: Response time
Definition of RTT (round
trip time): time to send
a small packet to travel
from client to server
and back.
Response time:
 one RTT to initiate TCP
connection
 one RTT for HTTP
request and first few
bytes of HTTP response
to return
 file transmission time
= 2RTT + transmit time
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
Chapter 2, slide: 9
Non-Persistent HTTP: issues
Nonpersistent HTTP:
 Name some issues??
 requires 2 RTTs per
object
 E.g., a 10 object-page
needs ~ 20 RTTs
 Open/close TCP
connection for each
object => OS overhead
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
 Any ideas for
improvement?
Chapter 2, slide: 10
Persistent HTTP
Persistent HTTP
 server leaves
connection open after
sending response
 subsequent HTTP
messages between
same client/server sent
over open connection
 reduces response time
Persistent without pipelining:
 client issues new request
only when previous
response has been received
 one RTT for each
referenced object
Persistent with pipelining:
 default in HTTP/1.1
 client sends requests as
soon as it encounters a
referenced object
 as little as one RTT for all
the referenced objects
Chapter 2, slide: 11
HTTP request message
 two types of HTTP messages: request, response
 HTTP request message:
 ASCII (human-readable format)
request line
(GET, POST,
HEAD commands)
GET /somedir/page.html HTTP/1.1
Host: www.someschool.edu
User-agent: Mozilla/4.0
header Connection: close
lines Accept-language:fr
Carriage return,
line feed
indicates end
of message
(extra carriage return, line feed)
Chapter 2, slide: 12
HTTP response message
status line
(protocol
status code
status phrase)
header
lines
Entity body:
data, e.g.,
requested
HTML file
HTTP/1.1 200 OK
Connection close
Date: Thu, 06 Aug 1998 12:00:15 GMT
Server: Apache/1.3.0 (Unix)
Last-Modified: Mon, 22 Jun 1998 …...
Content-Length: 6821
Content-Type: text/html
data data data data data ...
Chapter 2, slide: 13
HTTP response status codes
In first line in server -> client response message.
A few sample codes:
200 OK

request succeeded, requested object later in this message
301 Moved Permanently

requested object moved, new location specified later in
this message (Location:)
400 Bad Request

request message not understood by server
404 Not Found

requested document not found on this server
505 HTTP Version Not Supported
Chapter 2, slide: 14
Trying out HTTP (client side) for yourself
1. Telnet to your favorite Web server:
telnet cis.poly.edu 80
Opens TCP connection:
• to port 80 (default HTTP port)
• at cis.poly.edu (~ IP address)
• anything typed is sent there
2. Type in a GET HTTP request:
GET /~ross/ HTTP/1.1
Host: cis.poly.edu
By typing this in (hit carriage
return twice), you send
this minimal (but complete)
GET request to HTTP server
3. Look at response message sent by HTTP server!
Try it at home or lab!
Chapter 2, slide: 15
Web and HTTP: Review Question
 A HTTP request consists of:



1 basic html object
2 referenced JPEG objects
All objects of size = 106bits
 RTT = 1 second
 Transmission rate = 1Mbps
 Consider transmission delay of
objects only
 Question: how long it takes
to receive the entire page:
a)
b)
c)
Non-persistent connection
Persistent without pipelining
Persistent with pipelining
initiate TCP
connection
RTT
request
file
RTT
file
received
time
time to
transmit
file
time
Chapter 2, slide: 16
Web and HTTP: Review Question
 A HTTP request consists of:



1 basic html object
2 referenced JPEG objects
All objects of size = 106bits
 RTT = 1 second
 Transmission rate = 1Mbps
 Consider transmission delay of
initiate TCP
connection
RTT
request
file
objects only
 Answer: (transmit time = 1 sec)
a) 3+3+3=9 sec
time to
transmit
file
RTT
file
received
initiate + request + transmit for each of all 3
b) 1+2+2+2=7 sec
time
time
initiate + (request + transmit for each of all 3)
c) 1+2+3=6 sec
initiate + (request + transmit for basic) + (one
request for 2 + two transmits, one for each of the 2 objects)
Chapter 2, slide: 17
User-server state: cookies
Example:
Many major Web sites use
 Susan always access
cookies
Internet always from PC
Four components:
 visits specific e1) cookie header line of
HTTP response message
commerce site for first
2) cookie header line in
time
HTTP request message
3) cookie file kept on user’s  when initial HTTP
host, managed by user’s
requests arrives at site,
browser
site creates:
4) back-end database at
 unique ID
Web site
 entry in backend
database for ID
Cookies: keeping “state” (cont.)
client
ebay 8734
cookie file
ebay 8734
amazon 1678
server
usual http request msg
usual http response
Set-cookie: 1678
usual http request msg
cookie: 1678
one week later:
ebay 8734
amazon 1678
usual http response msg
usual http request msg
cookie: 1678
usual http response msg
Amazon server
creates ID
create
1678 for user entry
cookiespecific
action
cookiespectific
action
access
access
backend
database
Cookies (continued)
What cookies can bring:
 authorization
 shopping carts
 recommendations
 user session state
(Web e-mail)
aside
Cookies and privacy:
• cookies permit sites to
learn a lot about you
• you may supply name
and e-mail to sites
How to keep “state”:
• protocol endpoints: maintain state
at sender/receiver over multiple
transactions
• cookies: http messages carry state
Web caches (or proxy server)
Goal: satisfy client request without involving origin server
 If page is needed,
origin
server
browser requests it
from the Web cache
 Q: what if object not in
client
Proxy
server
cache??
cache requests object
from origin server, then
returns object to client
client
origin
server
Chapter 2, slide: 21
More about Web caching
 cache acts as both
client and server
Why Web caching?
 reduce response time
for client request
 typically cache is
installed by ISP
(university, company,
residential ISP)
 reduce traffic on an
institution’s access link.
Chapter 2, slide: 22
Caching example
origin
servers
Assumptions
 avg. object size = 0.1x106bits
 avg. request rate from
institution to origin servers =
10/sec
 Internet delay = 2 sec
Consequences
 utilization on LAN = 10%
(LAN: local area network)
 utilization on access link = 100%
 total delay = Internet delay +
access delay + LAN delay
= 2 sec + minutes + milliseconds
public
Internet
1 Mbps
access link
institutional
network
10 Mbps LAN
institutional
cache
Chapter 2, slide: 23
Caching example (cont)
origin
servers
possible solution
 increase bandwidth of access
link to, say, 10 Mbps
public
Internet
consequence
 utilization on LAN = 10%
10 Mbps
access link
 utilization on access link = 10%
 Total delay
= Internet delay +
access delay + LAN delay
= 2 sec + msecs + msecs
 often a costly upgrade
institutional
network
10 Mbps LAN
institutional
cache
Chapter 2, slide: 24
Caching example (cont)
origin
servers
possible solution: web cache
 suppose hit rate is 0.4
public
Internet
consequence
 40% requests will be satisfied
1 Mbps
access link
almost immediately
 60% requests satisfied by
origin server
institutional
network
10 Mbps LAN
 utilization of access link
reduced to 60%
 total avg delay will also be
reduced
institutional
cache
Chapter 2, slide: 25
Web cache (cont)
Advantages are obvious:
 Reduce response time
 Reduce internet traffic
Any problems with caches??
 Local cache copies of web pages
may not be up-to-date??
 What do we do then?
Solution
 Upon receiving a web
request, a cache must
consult origin server to
check whether the
requested page is up-todate
 Conditional GET method


What:
Sent by cache to origin
server: check page status
When:
For each new request:
client checks with cache
Chapter 2, slide: 26
Conditional GET
 Goal: don’t send object if cache
has up-to-date version
 How: cache specifies date of
cached copy in HTTP request
If-modified-since: <date>
cache
server
HTTP request msg
If-modifiedsince: <date>
HTTP response
object
not
modified
HTTP/1.0
304 Not Modified
 Server: response contains no
object if cached copy is up-todate:
HTTP/1.0 304 Not Modified
HTTP request msg
If-modifiedsince: <date>
HTTP response
object
modified
HTTP/1.0 200 OK
<data>
Chapter 2, slide: 27
Chapter 2: Application layer
 Principles of network
applications
 Web and HTTP
 FTP
 P2P file sharing
 Socket programming
with TCP
Chapter 2, slide: 28
FTP: the file transfer protocol
user
at host
FTP
FTP
user
client
interface
file transfer
local file
system
FTP
server
remote file
system
 transfer file to/from remote host
 client/server model
client: that initiates transfer (to or from remote)
 server: remote host
 ftp: RFC 959

Chapter 2, slide: 29
FTP: separate control, data connections
 FTP client contacts FTP
TCP control connection
port 21
server to open TCP control
connection
 client browses remote
directory by sending
commands over the TCP
control connection.
FTP
client
TCP data connection
port 20
FTP
server
 when server receives file transfer command, server
opens 2nd TCP data connection (for file) to client
 after transferring one file, server closes TCP data
connection.
Chapter 2, slide: 30
FTP: separate control, data connections
More on FTP
 server opens a separate
TCP data connection for
each file to transfer
 TCP control stays on
TCP control connection
port 21
FTP
client
TCP data connection
port 20
FTP
server
 control connection:
called: “out of band”
 FTP server maintains “state”: current directory,
earlier authent. => limit on concurrent connections
Chapter 2, slide: 31
Chapter 2: Application layer
 Principles of network
applications
 Web and HTTP
 FTP
 P2P file sharing
 Socket programming
with TCP
Chapter 2, slide: 32
File sharing approaches
There are 2 approaches
Bob
server
peers
 Centralized:
Client-server architecture
Alice
 Distributed:
P2P architecture
(e.g., BitTorrent)
server
obtain list
of peers
trading
chunks
peer
Chapter 2, slide: 33
File sharing: P2P vs. client-server architectures
Client-Server
P2P
Single point of failure
Fault-tolerant
Scalability
Not scalable
Scalable
Security
More secure
Less secure
Bottleneck
Better
Robustness to failure
Performance
Chapter 2, slide: 34
Comparing Client-Server, P2P architectures
Question : What is the file distribution time:
from one server to N hosts?
us: server upload
bandwidth
Server
us
File, size F
dN
uN
u1
d1
u2
ui: client/peer i
upload bandwidth
d2
di: client/peer i
download bandwidth
Network (with
abundant bandwidth)
Chapter 2, slide: 35
Client-server: file distribution time
 server sequentially
sends N copies:

NF/us time
 client i takes F/di
time to download
Time to distribute F
to N clients using = dcs
client/server approach
lower bound is also
achievable
Server
F
us
dN
u1 d1 u2
d2
Network (with
abundant bandwidth)
uN
> max { NF/us, F/min(d
i) }
i
increases linearly in N
(for large N)
Chapter 2, slide: 36
P2P: file distribution time
 server must send one
copy: F/us time
 client i takes F/di time
to download
Server
F
us
dN
 NF bits must be downloaded
u1 d1 u2
d2
Network (with
abundant bandwidth)
uN
- NF bits must be uploaded
- Fastest possible upload rate
(assuming all nodes sending file chunks to
same peer) is:
us + Sui
i=1,N
dP2P > max { F/us, F/min(di) , NF/(us + Sui) }
i=1,N
Chapter 2, slide: 37
Comparing Client-server, P2P architectures
Minimum Distribution Time
3.5
P2P
Client-Server
3
2.5
2
1.5
1
0.5
0
0
5
10
15
20
25
30
35
N
Chapter 2, slide: 38
Chapter 2: Application layer
 Principles of network
applications


app architectures
app requirements
 P2P file sharing
 Socket programming
with TCP (assignment 2)
 Web and HTTP
 FTP
Chapter 2, slide: 39
Assignment 2- programming part
Building a Multi-Threaded Web Server
 Read Chapter 2, Section 7 first
• Good examples on how to write socket-programs in
Java using TCP
 Then
do your assignment
• Socket/Java programming: relatively simple
and easy to do
Chapter 2, slide: 40
Chapter 2: Summary
our study of network apps now complete!
 application architectures
 client-server
 P2P
 application service
requirements:

reliability, bandwidth,
delay
 specific protocols:
 HTTP
 FTP
 P2P
 socket programming
(assignment 2)
 Internet transport
service model


connection-oriented,
reliable: TCP
unreliable, datagrams: UDP
Chapter 2, slide: 41
Download