Post

[CS] Computer Networking: Application layer(1) - soket, HTTP, cache

[CS] Computer Networking: Application layer(1) - soket, HTTP, cache

๐Ÿ“š์ปดํ“จํ„ฐ ๋„คํŠธ์›Œํฌ ์ „๊ณต ์ˆ˜์—… ์ •๋ฆฌ

Client-server paradigm


  • server:
    • always-on host
    • permanent IP address
    • often in data centers, for scaling
  • clients:
    • contact, communicate with server
    • may have dynamic IP addresses

Sokets


  • process sends/receives messages to/from soket
  • socket analogous to door
    • sending process relies on transport infrastructure on other side of door to deliver message to socket at receiving process
  • socket interface b/w transfer layer

  • ์–ด๋–ป๊ฒŒ process(soket)์ด ํŠน์ •๋˜๋Š”๊ฐ€?
    • IP addr, port-number์„ ํ†ตํ•ด
    • ์˜ˆ: web-server = 203.252.112.1:80 alt text

Transport protocols


TCP service


  • reliable transport b/w sending and receiving process
  • flow control: sender wonโ€™t overwhelm receiver
  • congestion control: throttle sender when network overloaded
  • connections-oriented: setup required b/w client and server processes
  • does no provide: timing, security, minimum throughput guarantee

UDP service


  • faster, lighter than TCP
  • unreliable data transfer
  • dose no provide: reliability, flow/congestion control, timing, throughput guarantee or connection setup

Web and HTTP

HTTP


HTTP: hypertext transfer protocol

  • Webโ€™s application-layer protocol
  • client/serve model
    • client: browser that requests, receives, (using HTTP protocol) and displays Web objects
    • server: Web server sends (using HTTP protocol) objects in response to requests alt text
  • HTTP uses TCP:
    1. client initiates TCP connection(creates socket) to server, port 80
    2. server accepts TCP connection from client
    3. HTTP messages(application-layer protocol messages) exchanged between browser(HTTP client) and Web server(HTTP server)
    4. TCP connection closed
  • HTTP is stateless: ์ด์ „ ์š”์ฒญ์„ ๊ธฐ์–ตํ•˜์ง€ ์•Š๋Š”๋‹ค.

    Non-persistent/persistent HTTP


    โœ… HTTP๊ฐ€ TCP๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์—๋Š” 2๊ฐ€์ง€๊ฐ€ ์žˆ๋‹ค.

    1. Non-persistent HTTP
    • TCP connection์„ ์š”์ฒญ์ด ๋“ค์–ด์˜ฌ๋•Œ๋งˆ๋‹ค ์ƒ์„ฑํ•˜๊ณ  ๋๋‚˜๋ฉด close 2. Persistent HTTP
    • ์ƒ์„ฑ๋œ TCP connection์„ ๊ณ„์† ์‚ฌ์šฉ
    • Non-persistent๋ณด๋‹ค ํšจ์œจ์  alt text alt text
  • RTT(Round Trip Time): time for a small packet to travel from client to server and back
    • a small packet์€ Transmission Delay๋ฅผ ๋ฌด์‹œํ•œ๋‹ค๋Š” ๋œป, ๋‹จ์œ„ ํŒจํ‚ท๋‹น ๋„คํŠธ์›Œํฌ ์™•๋ณต์‹œ๊ฐ„ ์ •๋„๋กœ ํ•ด์„

alt text

  • Non-persistent HTTP์˜ ๊ฒฝ์šฐ
  • TCP ์ปค๋„ฅ์…˜์„ ์ƒ์„ฑํ•  ๋•Œ ๋งˆ๋‹ค 1RTT๊ฐ€ ์†Œ์š”.
  • ์›ํ•˜๋Š” ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๋ฐ›๊ธฐ์œ„ํ•ด 1RTT๊ฐ€ ์†Œ์š”.
  • ์ฆ‰ Non-persistent HTTP์—์„œ ์˜ค๋ธŒ์ ํŠธ ํ•˜๋‚˜๋‹น 2RTT+file transmission time๊ฐ€ ์†Œ์š”๋˜๊ณ  100๊ฐœ๋ผ๋ฉด 200RTT๊ฐ€ ์†Œ์š”

โœ… ๊ทธ๋ž˜์„œ HTTP1.1 ๋ฒ„์ „์—์„œ๋Š” persistent HTTP๋ฅผ ์ง€์›!

  • ์„œ๋ฒ„๊ฐ€ Response๋ฅผ ๋ณด๋‚ธ ํ›„์—๋„ TCP ์ปค๋„ฅ์…˜์„ ์œ ์ง€
  • ์ปค๋„ฅ์…˜ ์—ฐ๊ฒฐ์— 1 RTT, ์—ฌ๋Ÿฌ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ์ „์†กํ•˜๋Š”๋ฐ ์•ฝ 1RTT
  • ์—ฌ๋Ÿฌ๊ฐœ์˜ ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ๋ณด๋‚ธ๋‹คํ•ด๋„ 2RTT + a์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฐ๋‹ค.

alt text alt text

HTTP request/response Message


  • request message alt text

    ๋งจ ์œ—์ค„์— GET /index.html HTTP/1.1\r\n

  • HEAD: ํ…Œ์ŠคํŠธ ๋ชฉ์ ์œผ๋กœ, ๋ณธ๋ฌธ์„ ๋ฐ›์„ ํ•„์š”๊ฐ€ ์—†์„ ๋•Œ ์‚ฌ์šฉ
  • GET: ์กฐํšŒ์šฉ ๋ฉ”์„œ๋“œ. ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ URL์— ?๋กœ ์—ฐ๊ฒฐํ•˜์—ฌ ๋ณด๋‚ธ๋‹ค.
  • POST: ์„œ๋ฒ„์— ์ฒ˜๋ฆฌ๋ฅผ ์š”์ฒญํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ
  • PUT: File Upload๋ฅผ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉ

  • response message alt text

    data data dataโ€ฆ: data, e.g. http request file

    • response status codes:
      • 200: ok
      • 300: Moved Permanently
      • 400: Bad Request
      • 404: Not Found
      • 505: HTTP Version Not Supported

Cookies


cookie: HTTP์˜ stateless๋ฅผ ๋ณด์™„ํ•˜๊ธฐ ์œ„ํ•จ

  • cookie์˜ four components:
    1. cookie header line of HTTP response message
    2. cookie header line in next HTTP request message
    3. ์‚ฌ์šฉ์ž ๋ธŒ๋ผ์šฐ์ €์— ์˜ํ•ด ๊ด€๋ฆฌ๋˜๋Š” ์‚ฌ์šฉ์ž ํ˜ธ์ŠคํŠธ์— ์ €์žฅ๋œ ์ฟ ํ‚ค ํŒŒ์ผ
    4. back-end database at Web site

alt text

Web cache


Web cache: ์ธํ„ฐ๋„ท์—์„œ ์ž์ฃผ ์ ‘๊ทผํ•˜๋Š” ์›น ํŽ˜์ด์ง€๋‚˜ ์ฝ˜ํ…์ธ ๋ฅผ ์ž„์‹œ๋กœ ์ €์žฅํ•ด๋‘๋Š” ์‹œ์Šคํ…œ alt text

  • โ€œ์ค‘๊ฐ„ ์ €์žฅ์†Œโ€๋กœ ์ž‘๋™
  • ํด๋ผ์ด์–ธํŠธ์™€ ์›๋ณธ ์„œ๋ฒ„ ์‚ฌ์ด์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌ

  • operation of Web cache:
    1. ์‚ฌ์šฉ์ž ์„ค์ •: user configures browser to point to a (local) Web cache
    2. ์š”์ฒญ ์ „๋‹ฌ: browser sends all HTTP requests to cache
    3. ์บ์‹œ ํ™•์ธ:
    • if object in cache: cache returns object to client
    • else: cache requests object from origin server, caches received object, then returns object to client

client๊ฐ€ requestํ•˜๋ฉด server๊ฐ€ ์•„๋‹Œ web ํ”„๋ก์‹œ(web cache)์—์„œ responseํ•˜๋ฉฐ http๋ฅผ request๋ฐ›์„๋•Œ procxy(web cache)์— ์ •๋ณด๊ฐ€ ์—†์œผ๋ฉด server์—์„œ ํ”„๋ก์‹œ๋กœ ๋ฐ›์•„์˜ค๊ณ  ๋‹ค์‹œ clientํ•œํ…Œ response. ๊ทธ ๋‹ด ์š”์ฒญ์—๋Š” procxy์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋ฐ”๋กœ responseํ•จ

  • Web cache๋Š” server/client ์—ญํ• ์„ ๋™์‹œ์— ์ˆ˜ํ–‰ํ•จ. alt text
  • ๋˜ํ•œ origin server๋Š” response header์— ์บ์‹ฑ ์ •์ฑ…์„ ๋ช…์‹œ ๊ฐ€๋Šฅ
    • Cache-Control: max-age=<seconds>: ํ•ด๋‹น ์‹œ๊ฐ„(์ดˆ) ๋™์•ˆ ์บ์‹ฑ ํ—ˆ์šฉ
    • Cache-Control: no-cache: ์บ์‹ฑ ๊ธˆ์ง€

โœ…Web Caching์ด ์™œ ํ•„์š”ํ•œ๊ฐ€?

  1. reduce response time: cache is closer to client
  2. reduce traffic on an institutionโ€™s access link
  3. Internet is dense with caches: ์ธํ„ฐ๋„ท์—๋Š” ๋งŽ์€ ์บ์‹œ๊ฐ€ ๋ถ„์‚ฐ๋˜์–ด ์žˆ์–ด ํšจ์œจ์ ์ธ ์ฝ˜ํ…์ธ  ์ „๋‹ฌ์ด ๊ฐ€๋Šฅ
  4. enables โ€œpoorโ€ content providers to more effectively deliver content
  • web caching ์‹œ๋‚˜๋ฆฌ์˜ค
    alt text

    access link ์‚ฌ์šฉ๋ฅ : 97% โ†’ ํฐ ๋Œ€๊ธฐ์—ด ์ง€์—ฐ

  • ์†”๋ฃจ์…˜:
    1. buy a faster access link
      alt text

      access link: 1.54 Mbps โ†’ 154 Mbps (100๋ฐฐ ์ฆ๊ฐ€)
      access link ์‚ฌ์šฉ๋ฅ : 0.97 โ†’ 0.0097 (97% โ†’ 0.97%)
      end-end time = 2์ดˆ + ๋ฐ€๋ฆฌ์ดˆ + ๋งˆ์ดํฌ๋กœ์ดˆ

  • ์ด ๋ฐฉ๋ฒ•์€ ํšจ๊ณผ์ ์ด์ง€๋งŒ ๋น„์šฉ์ด ๋งŽ์ด ๋“œ๋Š” ํ•ด๊ฒฐ์ฑ…
  1. install a web cache
    alt text

    cache hit rate๊ฐ€ 40%์ธ ๊ฒฝ์šฐ 40%์˜ ์š”์ฒญ์€ ์บ์‹œ์—์„œ ๋‚ฎ์€ ์ง€์—ฐ ์‹œ๊ฐ„(๋ฐ€๋ฆฌ์ดˆ)์œผ๋กœ ์ฒ˜๋ฆฌ
    60%์˜ ์š”์ฒญ์€ ์—ฌ์ „ํžˆ ์›๋ณธ ์„œ๋ฒ„์—์„œ ์ฒ˜๋ฆฌ
    ํ‰๊ท  ์ง€์—ฐ ์‹œ๊ฐ„ = 0.6 * (์›๋ณธ ์„œ๋ฒ„์—์„œ์˜ ์ง€์—ฐ) + 0.4 * (์บ์‹œ์—์„œ์˜ ์ง€์—ฐ)
    = 0.6 * (2.01์ดˆ) + 0.4 * (๋ฐ€๋ฆฌ์ดˆ) โ‰ˆ 1.2์ดˆ

Conditional GET


๐Ÿ“šConditional GET: client์˜ cache์— ์ด๋ฏธ ์ตœ์‹  ๋ฒ„์ „์˜ ๊ฐ์ฒด๊ฐ€ ์žˆ๋‹ค๋ฉด, ์„œ๋ฒ„๊ฐ€ ๊ฐ์ฒด๋ฅผ ๋‹ค์‹œ ๋ณด๋‚ด์ง€ ์•Š๋„๋ก ํ•˜๋Š” ๊ฒƒ

alt text โœ…์ž‘๋™ ๋ฐฉ์‹:

  1. Client: HTTP ์š”์ฒญ์— If-modified-since: <date> ํ—ค๋”๋ฅผ ํฌํ•จํ•˜์—ฌ ์ž์‹ ์ด ๊ฐ€์ง„ ์บ์‹œ๋œ ๋ฒ„์ „์˜ ๋‚ ์งœ๋ฅผ ๋ช…์‹œ
  2. Server:
    • ์š”์ฒญ๋ฐ›์€ ๊ฐ์ฒด๊ฐ€ ๋‚ ์งœ ์ดํ›„๋กœ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์•˜๋‹ค๋ฉด โ†’ HTTP/1.0 304 Not Modified ์‘๋‹ต (๊ฐ์ฒด ๋ฐ์ดํ„ฐ ์—†์Œ)
    • ์š”์ฒญ๋ฐ›์€ ๊ฐ์ฒด๊ฐ€ ๋‚ ์งœ ์ดํ›„๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ๋‹ค๋ฉด โ†’ HTTP/1.0 200 OK ์‘๋‹ต๊ณผ ํ•จ๊ป˜ ์ƒˆ๋กœ์šด ๊ฐ์ฒด ๋ฐ์ดํ„ฐ ์ „์†ก

HTTP1.1, 2, 3


๐Ÿ’ป HTTP/1.1

  • Pipelining: ๋‹จ์ผ TCP ์—ฐ๊ฒฐ์—์„œ ์—ฌ๋Ÿฌ GET ์š”์ฒญ์„ ์ˆœ์ฐจ์ ์œผ๋กœ ๋ณด๋‚ผ ์ˆ˜ ์žˆ์Œ
  • FCFS(First-Come-First-Served) Scheduling: ์„œ๋ฒ„๋Š” ์š”์ฒญ ๋ฐ›์€ ์ˆœ์„œ๋Œ€๋กœ ์‘๋‹ต
  • HOL(Head-of-Line) ๋ธ”๋กœํ‚น ๋ฌธ์ œ ๋ฐœ์ƒ:
    • ํฐ ๊ฐ์ฒด ๋’ค์— ์ž‘์€ ๊ฐ์ฒด๊ฐ€ ๋Œ€๊ธฐํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ ๋ฐœ์ƒ
    • TCP ํŒจํ‚ท ์†์‹ค ์‹œ ๋ชจ๋“  ๊ฐ์ฒด ์ „์†ก์ด ์ง€์—ฐ

๐Ÿ’ป HTTP/2

  • HTTP/1.1๊ณผ ํ˜ธํ™˜์„ฑ ์œ ์ง€
  • Priority Scheduling: ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ง€์ •ํ•œ ์šฐ์„ ์ˆœ์œ„์— ๋”ฐ๋ผ ์ „์†ก ์ˆœ์„œ ๊ฒฐ์ •
  • Server Push: ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์š”์ฒญํ•˜์ง€ ์•Š์€ ๊ฐ์ฒด๋„ ์„œ๋ฒ„๊ฐ€ ๋ฏธ๋ฆฌ ์ „์†ก ๊ฐ€๋Šฅ
  • ํ”„๋ ˆ์ž„ ๋ถ„ํ•  ๋ฐ interleaving: ๊ฐ์ฒด๋ฅผ ์ž‘์€ ํ”„๋ ˆ์ž„์œผ๋กœ ๋‚˜๋ˆ„์–ด ์ „์†กํ•˜์—ฌ HOL ๋ธ”๋กœํ‚น ์™„ํ™”
    • ๊ฐ์ฒด๋ฅผ ์ž‘์€ ํ”„๋ ˆ์ž„์œผ๋กœ ๋‚˜๋ˆ„์–ด interleaving ๋ฐฉ์‹์œผ๋กœ ์ „์†ก
    • ํฐ ๊ฐ์ฒด(์˜ˆ: ๋น„๋””์˜ค ํŒŒ์ผ)๊ฐ€ ์ „์†ก๋˜๋Š” ๋„์ค‘์—๋„ ์ž‘์€ ๊ฐ์ฒด(์˜ˆ: CSS, JS ํŒŒ์ผ)๋“ค์ด ํ•จ๊ป˜ ์ „์†ก๊ฐ€๋Šฅ โ†’ HOL ๋ธ”๋กœํ‚น ๋ฌธ์ œ๋ฅผ ํฌ๊ฒŒ ์™„ํ™” alt text
  • HTTP/2 ํ•œ๊ณ„
    • ๋‹จ์ผ TCP ์—ฐ๊ฒฐ์— ์˜์กด โ†’ ํŒจํ‚ท ์†์‹ค ๋ฐœ์ƒ ์‹œ ๋ชจ๋“  ๊ฐ์ฒด ์ „์†ก์ด ์ง€์—ฐ
    • TCP ์—ฐ๊ฒฐ ์ž์ฒด์—๋Š” ๊ธฐ๋ณธ์ ์ธ ๋ณด์•ˆ ๋ฉ”์ปค๋‹ˆ์ฆ˜์ด ์—†์Œ

๐Ÿ’ป HTTP/3

  • UDP ๊ธฐ๋ฐ˜์˜ QUIC protocol ์‚ฌ์šฉ
  • ํ–ฅ์ƒ๋œ ๋ณด์•ˆ: ๊ธฐ๋ณธ์ ์œผ๋กœ ์•”ํ˜ธํ™” ์ œ๊ณต
  • ๊ฐ์ฒด๋ณ„ ์˜ค๋ฅ˜ ๋ฐ ํ˜ผ์žก ์ œ์–ด: ํ•˜๋‚˜์˜ ๊ฐ์ฒด ์ „์†ก ๋ฌธ์ œ๊ฐ€ ๋‹ค๋ฅธ ๊ฐ์ฒด ์ „์†ก์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Œ
  • more pipelining: ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ ๊ธฐ๋Šฅ ํ–ฅ์ƒ

E-mail, SMTP


E-mail์˜ 3๊ฐ€์ง€ ๊ตฌ์„ฑ์š”์†Œ

  1. user agent
  2. mail servers
  3. SMTP(simple mail transfer protocol)
  • user agent:
    • a.k.a. โ€œmail readerโ€
    • outgoing, incoming messages stored on server
  • mail servers:
    • mailbox: contains incoming messages for user
    • message queue of outgoing (to be sent) mail messages

alt text
SMTP between mail servers to send email messages

  • client: sending mail server
  • server: receiving mail server

alt text

This post is licensed under CC BY 4.0 by the author.