๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Computer Network(COSE342)

[์ปดํ“จํ„ฐ๋„คํŠธ์›Œํฌ] CH2. Application Layer (#2)

HTTP connection establishment

1. Non-persistent HTTP

๊ฐœ์š”

1a. Http ํด๋ผ์ด์–ธํŠธ๊ฐ€ HTTP ์„œ๋ฒ„๋กœ TCP ์—ฐ๊ฒฐ์„ initiate, ์‹œ์ž‘ํ•œ๋‹ค. (www.someSchool.edu on port 80)
1b. HTTP ์„œ๋ฒ„๊ฐ€ TCP ์—ฐ๊ฒฐ์„ ๊ธฐ๋‹ค๋ฆฐ๋‹ค. ์—ฐ๊ฒฐ์„ "accepts" ํ•˜๊ณ  ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์•Œ๋ฆฐ๋‹ค
2. HTTP ํด๋ผ์ด์–ธํŠธ๊ฐ€ TCP ์—ฐ๊ฒฐ ์†Œ์ผ“์„ ํ†ตํ•ด URL ์ •๋ณด๊ฐ€ ํฌํ•จ๋œ request message๋ฅผ ์ „์†กํ•œ๋‹ค.
๋ฉ”์‹œ์ง€๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ "someDepartment/home"์—์„œ ์›ํ•˜๋Š” object๊ฐ€ ๋ญ”์ง€ ์ ํ˜€์žˆ์Œ
3. HTTP ์„œ๋ฒ„๋Š” request message๋ฅผ ๋ฐ›๊ณ  response message๋ฅผ ๊ตฌ์„ฑํ•œ๋‹ค.
์—ฌ๊ธฐ์—” ์š”์ฒญ๋ฐ›์€ object๊ฐ€ ํฌํ•จ๋˜๊ณ , ์ด ๋ฉ”์‹œ์ง€๋ฅผ ์†Œ์ผ“์„ ํ†ตํ•ด ์ „์†กํ•œ๋‹ค.
4. HTTP ์„œ๋ฒ„๊ฐ€ TCP connection์„ ๋‹ซ๋Š”๋‹ค(close)
5. HTTP ํด๋ผ์ด์–ธํŠธ๋Š” html file์„ ํฌํ•จํ•œ response message๋ฅผ ๋ฐ›๊ณ , ์ด html์„ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ณด์—ฌ์ค€๋‹ค.
Html ํŒŒ์ผ์„ ๊ตฌ๋ฌธ๋ถ„์„(parsing) ํ•ด์„œ 10๊ฐœ์˜ ์ฐธ์กฐ๋œ jpeg objects๋ฅผ ์ฐพ๋Š”๋‹ค.
6. ๊ฐ 10๊ฐœ์˜ jpeg objects์— ๋Œ€ํ•ด 1-5 ๋‹จ๊ณ„๋ฅผ ๋ฐ˜๋ณตํ•œ๋‹ค.
(10๊ฐœ์˜ ๋ถ„๋ฆฌ๋œ ๊ฐ๊ฐ์˜ ์—ฐ๊ฒฐ์„ ์—ด์–ด์„œ parallelํ•˜๊ฒŒ ์ง„ํ–‰)

TCP connection์€ ๋‹ค์Œ๊ณผ ๊ฐ™์€ resource๋ฅผ ํ•„์š”๋กœ ํ•จ

  • port number
  • TCB (look-up table)
  • Send buffer
  • Receive buffer

Response Time

RTT(definition) : ์ž‘์€ ํŒจํ‚ท์ด client๋กœ๋ถ€ํ„ฐ ์„œ๋ฒ„๋กœ ๊ฐ”๋‹ค๊ฐ€ ๋‹ค์‹œ ๋Œ์•„์˜ค๋Š”๋ฐ ์†Œ์š”๋˜๋Š” ์‹œ๊ฐ„

  • HTTP Connection response time
    1. TCP connection์„ ์‹œ์ž‘ํ•˜๋Š”๋ฐ 1RTT
    2. TCP connection์„ establishmentํ•˜๊ณ  HTTP requestํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ 1/2RTT
    3. ์š”์ฒญ๋ฐ›์€ ํŒŒ์ผ์„ ์ „์†กํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„ 1/2RTT + transmission time
  • ์ฆ‰ non-persistent HTTP response time = 2*RTT + file TX time

2. Non-Persistent vs Persistent

Non-Persistent HTTP issue

  1. response๋ฅผ ๋ณด๋‚ด๊ณ  ๋‚˜์„œ ์„œ๋ฒ„๊ฐ€ connection์„ closeํ•จ.
    • ๊ทธ๋ž˜์„œ ํ•œ object๋‹น ์ตœ์†Œ 2 RTTs๊ฐ€ ๊ฑธ๋ฆผ
    • ๊ฐ TCP connection๋งˆ๋‹ค OS overhead๊ฐ€ ๋ฐœ์ƒํ•จ (๊ฐ„์ ‘์ ์ธ ์ฒ˜๋ฆฌ ์‹œ๊ฐ„ ยท ๋ฉ”๋ชจ๋ฆฌ)
    • ๋ธŒ๋ผ์šฐ์ €๋Š” referenced object๋ฅผ ๊ฐ€์ ธ์˜ค๊ธฐ ์œ„ํ•ด์„œ ๋ณ‘๋ ฌ์ ์œผ๋กœ TCP connection์„ ์—ฐ๋‹ค.
  2. Shortcomings (๊ฒฐ์ )
    • ๋ชจ๋“  obj๋งˆ๋‹ค ์ƒˆ๋กœ์šด TCP connection์„ ์—ด๊ธฐ ๋•Œ๋ฌธ์— ๊ทธ ๋•Œ๋งˆ๋‹ค client์™€ server ์–‘ ์ชฝ์— ์ƒˆ๋กœ์šด ๋ฒ„ํผ์™€ ๋ณ€์ˆ˜๋“ค์ด ํ•„์š”ํ•จ
    • ์ƒˆ๋กœ์šด TCP connection์„ ์—ด ๋•Œ ๋งˆ๋‹ค additional delay๊ฐ€ ๋ฐœ์ƒํ•จ.

Persistent HTTP

  1. sending response๊ฐ€ ๋๋‚œ ์ดํ›„์—๋„ connection์„ ์—ด๋ฆฐ ์ฑ„๋กœ ๋‚ด๋ฒ„๋ ค๋‘ 
    • ์ด์–ด์ง€๋Š” HTTP messages๊ฐ€ ๊ฐ™์€ client/server ์‚ฌ์ด์˜ open connection์œผ๋กœ ์™”๋‹ค ๊ฐ”๋‹ค ํ•จ
    • ํด๋ผ์ด์–ธํŠธ๋Š” referenced object๋ฅผ ๋ฐœ๊ฒฌํ•˜์ž ๋งˆ์ž request๋ฅผ ๋ณด๋‚ธ๋‹ค
    • ์ฐธ์กฐ๋œ ๋ชจ๋“  object์— ๋Œ€ํ•ด ์ตœ์†Œ 1 RTT !

HTTP Multiplexing : ์š”์ฒญ์„ ํ•œ ๋ฒˆ์— ๋ณด๋‚ด๊ณ  ๋‹ต๋ณ€์„ ํ•˜๋‚˜์”ฉ ์ˆœ์„œ๋Œ€๋กœ ๋ฐ›๋Š”๋‹ค.

HTTP server architecture

1. Single-Threaded Web Server

  • ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด main thread์—์„œ response ๋ฅผ ๋ณด๋ƒ„. ๋‹ค๋ฅธ ์š”์ฒญ์„ ๋ณด๋‚ด์„œ ์‘๋‹ต์„ ๋ฐ›์œผ๋ ค๋ฉด ๊ทธ ์ด์ „์˜ ๊ฒƒ์ด ์ฒ˜๋ฆฌ ์™„๋ฃŒ ๋˜์–ด์žˆ์–ด์•ผ ํ•จ

2. Multi Threaded Web Server

  • ์š”์ฒญ์„ ๋ณด๋‚ด๋ฉด main thread์—์„œ๋Š” connection๋งŒ ํ•˜๊ณ  worker thread๋ฅผ ํ•˜๋‚˜ ํŒŒ์„œ ๊ทธ ์ชฝ์—์„œ ์‘๋‹ต์„ ์ฒ˜๋ฆฌํ•˜๊ณ  thread๋ฅผ ๋‹ซ์Œ.
  • ์—ฌ๋Ÿฌ ์š”์ฒญ์ด ์˜ค๋ฉด thread๊ฐ€ ์—ฌ๋Ÿฌ๊ฐœ ์—ด๋ ค์„œ ๋ณ‘๋ ฌ์ ์œผ๋กœ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
  • ์ฆ‰, main thread๋Š” request์˜ handling๋งŒ ์ง‘์ค‘ํ•˜๊ณ , worker thread์—์„œ Data transfer์„ ๊ด€๋ฆฌํ•œ๋‹ค.

3. Thread Pool Web server

  • worker thread๋ฅผ ์—ด๊ณ  ๋‹ซ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๊ณ ์ •๋œ thread์˜ pool ์•ˆ์—์„œ ์žฌ์‚ฌ์šฉ ํ•œ๋‹ค. (destroy X)
  • request๋“ค์„ linked list๋กœ ๋ฌถ์–ด์„œ ๊ด€๋ฆฌํ•˜๊ณ , worker thread์—์„œ ํ•˜๋‚˜์”ฉ ์‘๋‹ตํ•  ๋•Œ๋งˆ๋‹ค ํ•ด๋‹น request๋ฅผ ๋ฆฌ์ŠคํŠธ์—์„œ ์ง€์šฐ๋ฉด์„œ ๊ด€๋ฆฌํ•œ๋‹ค.

HTTP message formats

1. Request message

  • ASCII

  • \r = carriage return character = cr
  • \n = line-feed character = lf

Uploading Form Input

  1. POST method
    • Web page๋Š” ๋ณดํ†ต form input์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋‹ค
    • input์€ entity body ์•ˆ์— ๋‹ด๊ฒจ์„œ server์— ์—…๋กœ๋“œ ๋œ๋‹ค.
  2. URL method

Method Type

  1. HTTP/1.0
    • GET
    • POST
    • HEAD
      • ์„œ๋ฒ„์—๊ฒŒ ์š”์ฒญ๋œ object๋ฅผ ์‘๋‹ต์—†์Œ์œผ๋กœ ๋†”๋‘๋ผ๊ณ  ์š”์ฒญํ•จ(?)
  2. HTTP/1.1
    • GET, POST, HEAD
    • PUT ; entity body์— ์žˆ๋Š” ํŒŒ์ผ์„ url field์— ์žˆ๋Š” ํŠน์ • ๊ฒฝ๋กœ์— ์—…๋กœ๋“œํ•œ๋‹ค
    • DELETE ; url field์— ์žˆ๋Š” ํŠน์ • ํŒŒ์ผ์„ ์ง€์šด๋‹ค.

2. Response message

HTTP Response Status Code

  • Status code ๋Š” response message์˜ ์ฒซ๋ฒˆ์งธ line์— ์žˆ์Œ
  • 200 OK
    : ์„ฑ๊ณต์ ์œผ๋กœ ์š”์ฒญํ–ˆ๊ณ , ์ด ๋ฉ”์‹œ์ง€์— ์š”์ฒญํ•œ object๊ฐ€ ๋‹ด๊ฒจ ์žˆ๋‹ค.
  • 301 Moved Permanently
    : ์š”์ฒญํ•œ object๊ฐ€ ์ด๋™๋˜์—ˆ๋‹ค. ์ด ๋ฉ”์‹œ์ง€์— ์ƒˆ๋กœ์šด ์œ„์น˜๋ฅผ ๋ณด๋‚ด์ฃผ๊ฒ ๋‹ค. (Location : )
  • 400 Bad Request
    : Request ๋ฉ”์‹œ์ง€๋ฅผ server๊ฐ€ ์ดํ•ดํ•˜์ง€ ๋ชปํ–ˆ๋‹ค
  • 404 Not Found
    : ์š”์ฒญํ•œ ๋ฌธ์„œ๊ฐ€ ์ด ์„œ๋ฒ„์—์„œ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค.
  • 505 HTTP Version Not Supported.

Cookies ; To Keep "STATES"

Recall : HTTP๋Š” ์—ฐ๊ฒฐ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • ์„œ๋ฒ„๋Š” ๋ชจ๋“  request๋ฅผ ์ฒ˜์Œ ๋ฐ›๋Š” request๋กœ ๊ฐ„์ฃผํ•œ๋‹ค. ( ์ด์ „ ๋ฐ์ดํ„ฐ๊ฐ€ ์ „ํ˜€ ์—†์œผ๋‹ˆ ๋ชจ๋ฅด๋Š”๊ฒŒ ๋‹น์—ฐ )
  • ๊ทธ๋ ‡๋‹ค๋ฉด ๋งž์ถคํ˜• ๊ด‘๊ณ ๋Š” ์–ด๋–ป๊ฒŒ ๋‚˜์˜ ๊ด€์‹ฌ์‚ฌ๋ฅผ ํŒŒ์•…ํ–ˆ์„๊นŒ?

-> ๋งŽ์€ ์›น์‚ฌ์ดํŠธ๊ฐ€ ์ฟ ํ‚ค๋ฅผ ํ™œ์šฉํ•œ๋‹ค.

4๊ฐ€์ง€ ๊ตฌ์„ฑ์š”์†Œ๊ฐ€ ์žˆ๋‹ค

  1. HTTP response message์˜ Cookie header line
  2. ๋‹ค์Œ HTTP request message์˜ Cookie header line
  3. ์‚ฌ์šฉ์ž์˜ ํ˜ธ์ŠคํŠธ์—์„œ ๋ณด๊ด€ํ•˜๊ณ , ์‚ฌ์šฉ์ž์˜ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๊ด€๋ฆฌํ•˜๋Š” ์ฟ ํ‚ค ํŒŒ์ผ.
  4. ์›น ์‚ฌ์ดํŠธ์— ์žˆ๋Š” ๋ฐฑ์—”๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค

์˜ˆ์‹œ :

  1. ์ˆ˜์ž”์€ ์–ธ์ œ๋‚˜ ์ธํ„ฐ๋„ท์„ PC๋กœ ๋“ค์–ด๊ฐ„๋‹ค
  2. ์–ด๋–ค ํŠน์ •ํ•œ ์ด์ปค๋จธ์Šค ์‚ฌ์ดํŠธ์— ์ฒ˜์Œ ์ ‘์†ํ•œ๋‹ค
  3. ์‚ฌ์ดํŠธ์— initial HTTP requests๊ฐ€ ๋„์ฐฉํ•˜๋ฉด ์‚ฌ์ดํŠธ๋Š” ๋‹ค์Œ์„ ๋งŒ๋“ค์–ด๋‚ธ๋‹ค.
    • unique ID
    • ๋ฐฑ์—”๋“œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ID์— ๋Œ€ํ•œ entry

1. What cookies can be used for :

  • Authorization
  • Shopping carts
  • Recommendations
  • User session state (Web e-mail)

2. How to keep "state"

  • Protocol endpoints : ์—ฌ๋Ÿฌ transactions์— ๋Œ€ํ•ด์„œ sender/receiver์˜ ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•œ๋‹ค.
  • Cookies : http message๊ฐ€ state๋ฅผ ์šด๋ฐ˜(?)ํ•จ

3. Cookies and privacy

  • ์ฟ ํ‚ค๋Š” ๋‹น์‹ ์— ๋Œ€ํ•œ ๋งŽ์€ ์ •๋ณด๋ฅผ ์‚ฌ์ดํŠธ์—๊ฒŒ ์ œ๊ณตํ•œ๋‹ค
  • ํŠนํžˆ ์‚ฌ์ดํŠธ์— ์ด๋ฆ„๊ณผ ์ด๋ฉ”์ผ์„ ์ œ๊ณตํ•  ์ˆ˜๋„ ์žˆ๋‹ค.

Web cashing (Proxy Server)

Goal : origin ์„œ๋ฒ„์— ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ  client request๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด!

  1. ์œ ์ €๋Š” ์บ์‹œ๋ฅผ ํ†ตํ•ด ์›น์— ์ ‘๊ทผํ•˜๋„๋ก ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์„ค์ •ํ•œ๋‹ค.
  2. ๋ธŒ๋ผ์šฐ์ €๋Š” ๋ชจ๋“  HTTP ์š”์ฒญ์„ ์บ์‹œ๋กœ ๋ณด๋‚ธ๋‹ค
    • ๋งŒ์•ฝ ์บ์‹œ์— object๊ฐ€ ์กด์žฌํ•˜๋ฉด ์บ์‹œ๊ฐ€ object๋ฅผ ๋ฐ˜ํ™˜ํ•ด์ค€๋‹ค
    • ๋งŒ์•ฝ ์—†์œผ๋ฉด cashe๊ฐ€ origin server๋กœ object๋ฅผ ์š”์ฒญํ•˜๊ณ , ์ด๋ฅผ ๋ฐ›์•„์„œ client์—๊ฒŒ ๋ณด๋‚ด์ค€๋‹ค.

Why Web caching ?

  • client request์— ๋Œ€ํ•ด ์‘๋‹ตํ•˜๋Š” ์‹œ๊ฐ„์„ ์ค„์ด๊ธฐ ์œ„ํ•ด
  • link์— ์ ‘๊ทผํ•˜๋Š”๋ฐ ์†Œ์š”๋˜๋Š” traffic์„ ์ค„์ด๊ธฐ ์œ„ํ•ด

Caching Example

  1. ๊ฐ€์ •
  • ํ‰๊ท  obj size : 100K bits
  • browser -> origin server request rate : 15/sec
  • data rate to browsers : 1.50 Mbps
  • router -> server RTT : 2 sec
  • access link rate : 1.54 Mbps
  1. ๊ฒฐ๊ณผ
  • LAN Utilization : 0.15%
  • access link utilization = 99%
  • total delay = Internet delay + access delay + LAN delay = 2sec + minutes + usecs