Part 1: Overview of Web Systems Part 2: Peer-to

advertisement

Part 1: Overview of Web Systems

Part 2: Peer-to-Peer Systems

Internet Computing Workshop

Tom Chothia

Introduction

• Part 1:

– Summary how Web pages, JavaScript, Servlets and JSP are related.

– How to run your own Servlets and JSP in

Netbeans

• Part 2

– Peer to Peer Systems.

– Very high level overview of the design of Napster,

Gnutella and Bittorrent.

– P2P case studies, BBC ’ s iPlayer.

4 Key Web Technologies

• Web Pages:

– HTML file passed via HTTP.

• JavaScript

– Code in HTML file, runs on client

• Servlets

– Server code that generates HTML file.

• JavaServer Pages

– Java code in HTML that runs on the server.

Server

HTML

Web Pages

HTTP GET

HTTP file

Client

HTML

Display

HTML file

JavaScript

• HTML is very basic.

• JavaScript is a simple scripting language.

• You can put into HTML web pages.

• It runs on the client.

Server

HTML&JS

HTML +

J.S. file

JavaScript

HTTP GET

HTTP file

Client

HTML&JS

JS interpreter

Display

Servlets

• Sometimes you don’t want to run code on the client.

• The webpage doesn’t have to be a file.

• A servlet is Java code that runs on the server to handle a request from the client.

• Servlet = a little be of a server.

HTTPServlets

• The javax.servlet.http.HttpServlet class lets you build a servlet to handle web page request.

• When someone requests the page the doGet method is called.

• The doGet method must write HTML output.

Server

HTML

Servlets

HTTP GET

HTTP file

Java code

Servlet: doGet

Client

HTML

Display

JavaServer Pages (JSP)

• When writing servlets you can end up writing lots of HTML.

• JSP lets you put the Java in a HTML file.

• Great for pages with a lot of HTML and a little Java.

Server

HTML

Java code

Servlet: doGet

HTML +

Java file

JSP

HTTP GET

HTTP file

Client

HTML

Display

4 Key Web Technologies

Language Where

Processed

Web Pages HTML N/A

JavaScript HTML &

JavaScript

Servlets Java

Client

Server

JavaServer

Pages

HTML &

Java

Server

Containers

• To run JSP or Servlets you need a

“JSP/Servlets container”.

• This is a web server that can run servlets and compile JSP.

• E.g. Apache TomCat, Glassfish.

• Good IDEs can run these for you.

Running JSP in Netbeans

• Create a Web Application project:

File > New Project… > Java Web > Web Application

• This creates the JSP page: index.jsp

• Edit index.html (it can call other Java code).

• Click Run, to start a web server and open the page in a browser.

Running Servlets in NetBeans

• Create a web app, as before.

• Create a servlet file:

File > New File… > Web > Servlet

• Click Next, Next and enter the URL Pattern

– The servlet is run when a client requests this URL.

• Edit the Servlet file. E.g. write the doGet() method.

• Click run to start up the server.

• Enter the URL in the browser to see your page.

Part 2: Peer-to-Peer Systems

Internet Computing Workshop

File Sharing P2P Networks

• Napster:

– The first big file sharing network.

– Online between 1999-2001.

– Central Coordinator.

• Gnutella:

– Most popular file-sharing network in mid 2000s.

– No central coordinator.

– Unstructured Network.

• BitTorrent:

– Lots of little P2P networks.

– Single tracker coordinates each download.

– Rewards up-loaders.

Napster

I Peer “A” asks the database for “x”.

H

F

“x”

E

C

“x”?

A,E

E

D

G

B

“x”?

A

“x”?

The database tells “A” which peer has the file.

“A” downloads the file from that peer.

“x”

“A” tells the database it has the file.

Other peers can then download the file from

“A”

Napster User Figures

Original Gnutella

In newer networks peers record the

IP address of other peers.

A searcher sends a request to all of it’s “neighbours”.

This is forwarded to all of there neighbours, up to a fixed hops.

A

Original Gnutella

The search request includes

A’s IP address.

Any peer with the requested file contacts A directly.

Peer “A” may then request the file.

A

BitTorrent: Setting Up

Tracker

A

Web Server

T

A

T

Peer “A” wants to share a find.

“A” must find a tracker to coordinate the download.

“A” makes a “torrent” file,

– The name of the file.

– The hash of the data.

– The IP address of the tracker.

“A” must put the torrent somewhere people can find it. E.g., on a web server.

“A” tells the tracker is wants to share the file.

T

B A

BitTorrent: Sharing

Tracker

A ,B

Web Server

T

A

Peer “B” finds the torrent file.

“B” finds the tracker IP and connects to it.

The tracker:

– tells “B” the IP of the file sharers.

– And adds “B” address to the list of sharers

“B” connects to “A” and then gets some pieces of the file.

Tracker

A, B,C

Web Server

T

T

B A

T

C

A,B

T

D

B,C

BitTorrent: Sharing

A

Peer “C” connects in the same way.

“A” will try to hand out different copies of the file.

“A” may disconnect.

“C” may get the rest of the file from “B”.

“D” can connect and the sharing continues without “A”.

Case Study: BBC’s iPlayer

• The BBC wants to provide TV programs via the Web.

• Streaming all that data costs a lot.

• Therefore the BBC tried out a peer-to-peer system for downloads.

• They used a centrally controlled coordinator and digital rights management.

Case Study: BBC’s iPlayer

The idea is:

• If I’m only downloading then I cost the BBC money

(they pay for bandwidth).

• If I upload as much as I download then I cost the

BBC very little.

• If I upload more than I download then I am providing a service for the BBC.

In theory, a company can save millions.

Case Study: BBC’s iPlayer

In fact:

• iPlayer users like to stream TV, not download.

• The P2P system can’t provide the exact information at the exact time to watch live.

• In December 2008 the BBC changed their download service to direct download via HTTP.

Key point: P2P has great potential, but it has it’s problems

Next Time:

• AJAX and other new web systems.

Download