Está en la página 1de 15

Bi ging K thut Mng nng cao TS. Trn Quang Vinh Chng 3. Lp ng Dng 3.1.

Chc nng, nhim v 3.2. H thng tn min (Domain Name System -DNS) 3.3. Th in t (Electronic Mail) ---------------------------------------------------------------------------------------3.4. Cc ng dng ngang hng (Peer-to-Peer Applications) 3.4.1. Gii thiu Theo s liu thng k lu lng Internet ton cu trong nhng nm gn y. Lu lng P2P ngy cng tng nhanh v p o cc loi lu lng khc nh Web, email, hay Internet video.

Bi ging ny s cung cp nhng hiu bit c bn nht v nguyn l hot ng, kin trc, cng nh nh gi hiu nng ca P2P. Trong gii hn ca bi ging, ta ch xt n kha cnh k thut, khng bn n vn bn quyn, hay s hu tr tu ca cc ni dung chia s bi cc ng dng P2P. Vy kin trc P2P l g?

peer-peer

Cc giao thc v cc ng dng hc trong cc bi trc nh HTTP, FTP, DNS, Email vn l cc ng dng hot ng theo c ch client/server, chng hot ng da trn s hot ng lin tc v tin cy ca server. Kin trc P2P khng cn server hoc ti thiu ha vai tr ca cc server. Thay vo , kin trc P2P bao gm tng cp hosts (peers) kt ni mt cch khng lin tc vi nhau v trao i thng tin trc tip vi nhau (qua lin kt logic). Cc peers khng s hu bi nh cung cp dch v m l thit b u cui c kim sot bi users nh laptop, PCs, PDAs, hay SmartPhone. hiu bn cht, kin trc, v hot ng ca P2P, chng ta s nghin cu P2P qua 3 ng dng ph bin ca n. - ng dng phn phi file (File Distributation): phn pht mt file t mt ngun n mt s lng ln cc peers. i din ca ng dng phn phi file l h thng BitTorrent ni ting. - Nghin cu k thut phn tn mt c s d liu n mt cng ng ln cc peers. minh ha cho ng dng ny, chng ta s xem xt cc khi nim v DHT (Distibuted Hash Table). - Cui cng, tm hiu v Skype, h thng in thoi Internet ph bin nht hin nay. 3.4.2. P2P File Distribution
2

y l dch v c bn ca P2P, cho php phn phi mt file ln t mt server n cc host (peers). File y thng c kch thc ln nh mt b phim, phin bn mi ca mt h iu hnh, hay cc bn nhc MP3. Trong h thng client/server, server phi gi i cc bn copy ca file cho mi peer, dn n tiu th lng ln bng thng v cc ti nguyn mng khc. Trong P2P, mi peer thc hin vic ti phn phi bt k phn no ca file n bt k peer no c nhu cu. Nh vy, cc peers ng vai tr h tr server trong vic phn pht file. Cu hi cn t ra y l: Cn bao nhiu thi gian phn pht mt file t mt ngun (server) n mt s lng ln cc users (client/peer)? Distribution Time: l thi gian cn thit mi peer trong N peers u nhn c mt bn copy ca file F. nh gi hiu qu hot ng ca kin trc client/server v P2P, ta xt mt m hnh nh lng n gin c ch ra trn hnh v.
us: server upload bandwidth
u1 us dN uN d1 u2

Server

ui: peer i upload bandwidth


d2

di: peer i download bandwidth

Network (with abundant bandwidth)

Mt server kt ni n N peers qua Internet, gi us l tc upload ca server, ui, di l tc upload, download ca peer i. File cn phn pht c kch thc F (bit). Gi thit mng li c bng thng khng gii hn, server v cc peers khng tham gia vo cc hot ng khc. M hnh Client-Server - Server phi truyn mt bn copy ca file n mi peer phc v N peers, server phi truyn NF bt thi gian truyn ti thiu l NF/us.

- Gi dmin l tc download ti thiu ca cc peers, d min = min{d1 , di ,..., d N } . Mt peer vi tc download thp nht s khng th nhn c F bt sau khong thi gian t hn F/dmin giy. Do min distribution time l F/dmin. Nh vy, distribution time i vi kin trc client-server l:

NF F DC/S = max , u s d min


M hnh P2P

(2.1)

- gi fiel F n cc peers, server phi gi mi phn ca file t nht mt ln ln Internet qua upload link distribution time ti thiu l F/us. - Peer i cn ti thiu F/dmin (s) download - phc v N peers, h thng cn phi truyn F bt n N peers, tng s bt cn truyn l NF. Tng dung lng upload ca h thng chnh l upload ca server v upload ca cc peers utotal = us + u1 + .+ uN. Min distribution time l: NF/utotal. Nh vy, distribution time i vi kin trc client-server l:
F F NF = max , , N u s d min us + ui i =1

DP 2 P

(2.2)

So snh kt qu t hai cng thc (2.1) v (2.2) vi cc gii thit: cc peers c cng tc upload u, mt peer c th truyn ton b file trong 1 gi (F/u=1 gi), tc upload ca server bng 10 ln tc upload ca peer (us=10u), tc download ca cc peers ln so vi tc upload ca server (dmin us). Nhn xt: - Distribution time i vi h thng client/server tng tuyn tnh khi s lng peers tng v khng c gii hn trn. - Distribution time i vi h thng P2P lun nh hn, ngoi ra n c c gii hn trn khi s peers tng, hay ni cch khc, h thng vn hot ng hiu qu khi s peers tham gia vo h thng tng ln.

Client upload rate = u, F/u = 1 hour, us = 10u, dmin us

4.4.3. BitTorrent a) Gii thiu BitTorrrent l mt giao thc P2P chy lp ng dng, ng thi cng l tn ca mt chng trnh c s dng chia s ti nguyn trn mng P2P, c pht trin bi Bram Cohen (2001). BitTorrrent l mt chng trnh m ngun m. n nay, c rt nhiu bn BitTorrent client khc nhau (Torrent, Transmission, rTorrent, KTorrent, BitComet, and Deluge) chng nhng u tng thch vi giao thc BitTorrent. Ging nh c rt nhiu web browser client khc nhau tng thch vi giao thc HTTP. b) ng dng BitTorrent l mt h thng chia s file c s dng nhiu nht hin nay. Tnh n thng 1/2012, c 150 triu active users trn tng s users c th n t. Ngoi ng dng chia s file truyn thng, giao thc BitTorrent cn c Facebook v Twitter (l hai mng x hi ph bin hin nay) s dng phn phi cc bn tin cp nht (updates) ca ngi dng ln servers ca mnh. c) Thut ng - Torrent: l tp hp cc peers tham gia vo vic chia s mt file. Ti mt thi im, mt torrent c th c hng chc n hng trm ngn peers.

File c phn m rng .torrent l file cha cc thng tin tng qut v file c chia s (tn file, kch thc, s chunks, a ch tracker). File .torent c th search trn Google hoc search trn cc tracker. - Chunk: n v thng tin c cc peers s dng trao i thng tin vi nhau, c kch thc 256kB (hoc ln hn ty vo dung lng file cn chia s) - Tracker: nt c s ca mt torrent, qun l cc peers trong torrent. Mt s tracker ni ting: - thepiratebay.org (open tracker), peers: 5.164.500, torrents: 636.734 - demonoid.com, peers: 3.138.042, torrents: *no info* - torrentbox.com (open tracker), peers: 1.144.100, torrents: 40.818 - hdvnbits.org (private tracker), peers: 250,000, torrents: 30,000 d) Nguyn tc hot ng chung Khi mt peer mi tham gia vo torrent, n cha c chunk no, nhng n s tch ly cc chunks theo thi gian. Khi mt peer dowload chunk th ng thi n cng upload chunks. Khi mt peer ti v mt chn vn mt file, n c th ra khi torretn hoc tip tc duy tr upload chunk cho cc peers khc.

participating in torrent

tracker: tracks peers

peers exchanging chunks of a file

torrent: group of

obtain list of peers trading chunks

peer

V d: Xt mt v d n gin lm r c ch hot ng ca BitTorrent Khi mt peer (Alice) xin vo torrent, tracker s chn ngu nhin mt tp (e.g., 50 peers) v gi a ch IP ca cc peers cho Alice. Alice thit lp cc concurrent TCP connection vi danh sch cc peers nhn c t tracker. Nu kt ni thnh cng, cc peer ny c gi l cc peer ln cn ca Alice.
6

Do mi peers c mt tp cc chunks khc nhau, Alice nh k gi cc yu cu n cc peers ln cn (qua TCP connections) ly danh sch cc chunks, sau Alice gi cc yu cu nhn cc chunks m mnh cha c. Alice s phi quyt nh 2 vn : (i) chunks no cn ti v trc tin v (ii) ti chunks t peer no. Quy tc: (1) Rarest first: u tin ti v cc chunks him nht (cc chunk nhn c t yu cu t cc peers ln cn nht), k thut ny lm cho cc chunks c phn phi mt cch u nhau. (thiu 1 chunk cung khng th ti to li file gc) (2) Highest rate first: + Chn cc peer c tc upload ln nht ly chunks (thng thng l 4 peers), ng thi cng upload chunks n cc peers ny. K thut ny c lp li mi 10 giy cho php cc peers c th down/upload tc tt nht c th. + Chn ngu nhin thm mt peer giao dch. K thut ny lp li mi 30 giy cho php cc peer mi c th nhn c chunks v c chunks trao i. K thut trn c gi l tit-for-tat n ming-tr ming, kt qu l khi bn upload (phc v) tc cao nht th bn s nhn c cc i tc c cng c tc upload ln nht v do bn c th download (c phc v) tc ln nht. Ngoi ra BitTorrent cn s dng rt nhiu k thut khc nhau lm tng hiu qu ca giao thc P2P. Nhn xt: (Vic s dng server tp trung gy ra vn g?) - Vic s dng tracker tp trung gy ra mt im li ton h thng (single points of failure). - gii quyn vn ny, s dng cc tracker phn tn (distributed trackers hay tracker-less). Tuy nhin, vn then cht t ra cho cc ng dng P2P ni ring v cc ng dng phn tn ni chung l index, hay cch thit k mt c s d liu sao cho n c kh nng tm kim v cp nht mt cch hiu qu, c bit khi s lng peer tng ln nhanh chng. Nghin cu cc th h pht trin ca P2P s cho ta cu tr li.
7

4.4.4. Cc th h P2P a) P2P th h th nht Th h th nht ca P2P da trn mt c s d liu tp trung vi cc chc nng indexing v querying n gin. Thng tin c lu trn database bao gm cc cp <key, value>, v d: <Transformer III, 202.101.2.10>. Cc peers truy vn database bng cch cung cp mt key, nu cp (key, value) tn ti trn database, server s tr v value (a ch IP ca peer cha ni dng c yu cu) tng ng vi key c hi. Th h th nht l k thut lai ghp gia kin trc client/server v P2P. Mt i din ca th h ny l Napster.

Nhn xt: D nhn thy, phng php ny mc phi vn mt im li single-point-offailure, h thng hon ton sp khi center server b li. b) P2P th h th hai P2P th h hai tm cch xy dng mt database c kh nng phn phi mt nhm nh cc cp <key, value> n cc peers, mi peer duy tr mt danh sch cc a ch IP ca cc peers trong nhm. Nh vy, mt peer c th gi query n tt c cc peers khc trong nhm, ch peer cha cp gi tr (key, value) trng vi query s tr li. i din: KaZaa vi FastTrack protocol v Gnutella.
8

Nhn xt: Phng php ny yu cu cc peer nm c (keep track of) tt c cc peers trong nhm khng p ng c yu cu m rng mng (unscalable). c) P2P th h th ba Mi peer c gn mt s nhn dng (IDentifier) l mt s nguyn trong khong [0, 2n-1] vi n xc nh. Lu , mi ID c th biu din bi n bt. Mi key cng c gn mt s nguyn cng di vi ID. gn mt s nguyn cho key, s dng bng bm (hash table) nh x (map) mi key vi mt s nguyn trong khong [0, 2n-1].

V d: e.g., key = h(Transformer III) tr v mt s nguyn x Bng bm c public n all peers trong h thng do , mt database phn tn s dng bng bm c gi l bng bm phn tn (distributed hash table DHT). BitTorrent l i din ca th h P2P th ba, s dng DHT ti u hot ng ca h thng P2P. 4.4.5. Distributed Hask Table (DHTs) nh ngha: DHTs l mt k thut cho php indexing v searching hiu qu mt database ln. Bng bm phn tn (Distributed hash tables - DHT) l mt lp cc h thng phn tn, cung cp mt dch v tra cu cc cp <key,value> c lu tr trong DHT, bt k nt mng no tham gia vo DHT cng c th ly c gi tr lin kt vi mt kha cho trc mt cch hiu qu. Nhim v lu tr nh x <key,value>c phn tn gia cc nt, bng cch s gim bt li nu c thay i trong mt tp hp cc nt tham gia. iu ny cho php s dng DHT cho mt s lng cc ln cc nt mng. DHT to nn nn tng cho vic xy dng cc dch v phc tp hn, chng hn nh cc h thng file phn tn, chia x file trong P2P, h thng phn phi ni dung (content distribution), web cache c tnh hp tc, multicast, anycast, dch v tn min, v instant message. How to assign keys to peers? Gn cc keys cho mi peers hay phng php lu cc cp <key,value> cho cc peers mt cch phn tn l vn trng tm ca DHT. Nguyn tc: Gn mi cp <key,value> cho peer no c ID gn nht (closest) vi key . V d: Vi n=4, cc peers s vc ID trong khong [0,15]. Gi s c 8 peers vi cc ID: 1, 3, 4, 5, 8, 10 , 12, 14. Cn lu tr cp gi tr <11, .> vo mt trong 8 peers trn.
10

- Theo nguyn tc closest, ta chn c peer c ID =12 l gi tr k tip ca key 11 cp gi tr <11, .> s c lu vo peer 12. - Nu key = ID ca peer th lu lun vo peer ny. - Nu key ln hn tt c cc ID ca peers, th s dng lut modulo-2n v gn cho peer c ID nh nht. V d: key = 15 gn cho peer 1. Nhn xt: - Thng thng, mt peers mun query hoc insert mt cp <key,value>, n phi gi cc messages n tt c cc peers. Ni cch khc mt peer phi c IP address ca tt c cc peers cn li, phng php ny l khng th trong trng hp h thng c hng triu peers. - Cc k thut sau y gip gii quyt vn ny. a) Circular DHT Thut ton Circular DHT cung cp mt gii php hu hiu lm gim s lng thng tin m mt peer cn qun l. Theo , mi peer ch cn bit thng tin ca 2 peers: peer k trc n v peer k sau n (immediate successor and predecessor). V d: Trn hnh v, peer 3 (0011) mun xc nh peer no chu trch nhim cho key 11 (1011) , cho c trng hp query v insert. - Peer 3 to mt message who is responsible for key 11? v gi n peer k trc n, peer 4 (0100). - V mi peer u bit ID ca peer k trc n, nn mi khi nhn c message, peer c th quyt nh tr li (nu n l peer chu trch nhim) hoc tip tc forward n peer k trc n. - C nh vy, peer 12(1100) chu trch nhim cho key 11 s tr li cho peer 3 (12 gi trc tip cho 3).

11

O(N) messages on avg to resolve query, when there are N peers

1 3
11 ?

Whos response for key 11?

15
I am
11 ?

4 5

Define closest as closest successor

12

11 ? 11 ? 11 ?

10

Nhn xt: - Mc d mi peer ch cn bit thng tin v 2 peers cnh n, nhng tm c peer chu trch nhim cho mt cp <key, value>, trong trng hp xu nht, tt c N nodes trong DHT phi forward message quanh mt vng trn phc tp ca thut thon l O(N). Trng hp trung bnh l N/2. (5 bn tin cho v d trn) - DHT phi nh i (trade-off) gia s lng peer ln cn m mt peer cn qun l v s bn tin DHT cn phi gi cho mt query hoc insert. - Ni cch khc, nu mi peer nm c thng tin ca tt c cc peer ln cn (mesh overlay), ch cn gi i mt bn tin. Nu mi peer ch cn nm thng tin ca 2 peer pha trc v sau n, th phi gi i trung bnh l N/2 bn tin cho mi query. b) Circular DHT with Shortcuts Nh vy cn phi ci tin phng php trn sao cho s lng peers ln cn m mt peer phi nm v s bn tin cho mi query mc chp nhn c. Mt trong cc phng php hiu qu l vn s dng Circular DHT nh trn nhng c b sung thm mt s shortcuts (ng tt) sao cho mi peer khng ch nm gi thng tin ca 2 peers k trc v sau n, m cn nm gia mt s lng va phi cc shortcuts n cc peers ln cn tri u theo vng trn.

12

1
I am

15

Whos resp for key 1110 (14)?

4 12 10
V d: Peer 3 cn query tm peer chu trch nhim cho key 14, n kim tra danh sch peer k trc v cc shortcuts ca n. Trong trng hp ny, peer 3 c 2 la chn (4 v 8), n s gi query message trc tip n peer 8 theo lut peer gn nht vi key cho (closest peer to the key). Tng t, peer 8 s gi query message n peer 15. Nhn xt: - 6 message trong c ch circular DHT gim xung cn 2 message trong Circular DHT with Shortcuts. - Vi thit k tt c th gim phc tp t O(N) xung cn O(logN). - Cu hi tip theo l mi peer cn bao nhiu shortcut v peer no c chn lm shortcuts? Cu hi ny nhn c s quan tm rt ln ca cng ng nghin cu. H tm cch thit k sao cho DHT c th chy trong O(logN). c) Peer Churn Trong h thng P2P, mt peer c th nhp vo hoc thot ra m khng cn bo trc. Do vy khi thit k DHT cn phi quan tm n vn join and disjoin peer (peer churn) m bo duy tr c hot ng ca h thng. gii quyn vn ny, yu cu mi peer phi bit a ch IP ca 2 successors (2 peers k trc n).

5 8

13

Mi peer nh k ping 2 successors ny bit n cn sng hay khng.

15

3 4

12 10
V d:

5 8

To handle peer churn, require each peer to know the IP address of its two successors. Each peer periodically pings its two successors to see if they are still alive.

Peer 5 t ngt ri mng, peer 4 pht hin ra nh ping, chuyn 8 thnh successor th nht v hi 8 bit ai l successor ca 8, sau gn successor ca 8 thnh successor th hai ca mnh. Home work: - What if peer 4 and 5 abruptly leave at the same time? - What if peer 13 wants to join? 4.4.6. Case Study: P2P Internet Telephony with Skype Skype l mt ng dng P2P thng dng nht hin nay, lun c khong 8 triu users online mi thi im. Ngoi dch v thoi t PC n PC, Skype cn cung cp dch v thoi t PC n phone, t phone n PC, v video conference t PC n PC. Janus Friis (sinh nm 1976 ti Copenhagen, an Mch) l ngi sng lp phn mm chia s tp tin (file sharing) KaZaA, v Skype. Thng 9 nm 2005, anh v ngi ng s hu Niklas Zennstrm bn mt phn Skype cho eBay vi gi 2,6 t dollar M v mt phn cho tp on Microsoft vi gi 8,5 t dollar M vo thng 5 nm 2011. Skype s dng cc k thut P2P vi rt nhiu ci tin, cho thy P2P c th c s dng trong cc ng dng cn i xa hn c cc dch v phn phi ni dung v
14

chia s file. V d nh dch v thoi PC-PC qua Internet cho php 2 computer trao i thng tin vi nhau trong thi gian thc. Ngoi ra Skype cn s dng cc k thut P2P cho hai ng dng quan trng khc l user location v NAT traversal (cho php cc PC pha sau NAT cng c th s dng Skype). NAT ngn chn mt host t outside home network khi u vic thit lp mt kt ni n mt host inside home network.

P2P Case study: Skype


inherently P2P: pairs of users communicate. proprietary Skype application-layer login server protocol (inferred via reverse engineering) hierarchical overlay with SNs Index maps usernames to IP addresses; distributed over SNs

Skype clients (SC)

Supernode (SN)

Peers as relays

problem when both Alice and Bob are behind NATs.

solution:

NAT prevents an outside peer from initiating a call to insider peer using Alices and Bobs SNs, relay is chosen each peer initiates session with relay. peers can now communicate through NATs via relay

15