[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)์ด ํน์ ๋๋๊ฐ?
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
- HTTP uses TCP:
- client initiates TCP connection(creates socket) to server, port 80
- server accepts TCP connection from client
- HTTP messages(application-layer protocol messages) exchanged between browser(HTTP client) and Web server(HTTP server)
- TCP connection closed
- HTTP is stateless: ์ด์ ์์ฒญ์ ๊ธฐ์ตํ์ง ์๋๋ค.
Non-persistent/persistent HTTP
โ HTTP๊ฐ TCP๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ์์๋ 2๊ฐ์ง๊ฐ ์๋ค.
- Non-persistent HTTP
- RTT(Round Trip Time): time for a small packet to travel from client to server and back
- a small packet์ Transmission Delay๋ฅผ ๋ฌด์ํ๋ค๋ ๋ป, ๋จ์ ํจํท๋น ๋คํธ์ํฌ ์๋ณต์๊ฐ ์ ๋๋ก ํด์
- 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์ ์๊ฐ์ด ๊ฑธ๋ฆฐ๋ค.
HTTP request/response Message
- request message
๋งจ ์์ค์
GET /index.html HTTP/1.1\r\n
HEAD
: ํ ์คํธ ๋ชฉ์ ์ผ๋ก, ๋ณธ๋ฌธ์ ๋ฐ์ ํ์๊ฐ ์์ ๋ ์ฌ์ฉGET
: ์กฐํ์ฉ ๋ฉ์๋. ํ๋ผ๋ฏธํฐ๋ฅผ URL์?
๋ก ์ฐ๊ฒฐํ์ฌ ๋ณด๋ธ๋ค.POST
: ์๋ฒ์ ์ฒ๋ฆฌ๋ฅผ ์์ฒญํ ๋ ์ฌ์ฉํ๋ ๋ฉ์๋PUT
: File Upload๋ฅผ ํ๊ณ ์ถ์ ๋ ์ฌ์ฉ- response message
data data dataโฆ: data, e.g. http request file
- response status codes:
200
: ok300
: Moved Permanently400
: Bad Request404
: Not Found505
: HTTP Version Not Supported
- response status codes:
Cookies
cookie: HTTP์ stateless
๋ฅผ ๋ณด์ํ๊ธฐ ์ํจ
- cookie์ four components:
- cookie header line of HTTP response message
- cookie header line in next HTTP request message
- ์ฌ์ฉ์ ๋ธ๋ผ์ฐ์ ์ ์ํด ๊ด๋ฆฌ๋๋ ์ฌ์ฉ์ ํธ์คํธ์ ์ ์ฅ๋ ์ฟ ํค ํ์ผ
- back-end database at Web site
Web cache
Web cache: ์ธํฐ๋ท์์ ์์ฃผ ์ ๊ทผํ๋ ์น ํ์ด์ง๋ ์ฝํ
์ธ ๋ฅผ ์์๋ก ์ ์ฅํด๋๋ ์์คํ
- โ์ค๊ฐ ์ ์ฅ์โ๋ก ์๋
ํด๋ผ์ด์ธํธ์ ์๋ณธ ์๋ฒ ์ฌ์ด์์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌ
- operation of Web cache:
- ์ฌ์ฉ์ ์ค์ : user configures browser to point to a (local) Web cache
- ์์ฒญ ์ ๋ฌ: browser sends all HTTP requests to cache
- ์บ์ ํ์ธ:
if object in cache
: cache returns object to clientelse
: 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 ์ญํ ์ ๋์์ ์ํํจ.
- ๋ํ origin server๋ response header์ ์บ์ฑ ์ ์ฑ
์ ๋ช
์ ๊ฐ๋ฅ
Cache-Control: max-age=<seconds>
: ํด๋น ์๊ฐ(์ด) ๋์ ์บ์ฑ ํ์ฉCache-Control: no-cache
: ์บ์ฑ ๊ธ์ง
โ Web Caching์ด ์ ํ์ํ๊ฐ?
reduce response time
: cache is closer to clientreduce traffic
on an institutionโs access link- Internet is dense with caches: ์ธํฐ๋ท์๋ ๋ง์ ์บ์๊ฐ ๋ถ์ฐ๋์ด ์์ด ํจ์จ์ ์ธ ์ฝํ ์ธ ์ ๋ฌ์ด ๊ฐ๋ฅ
enables โpoorโ content providers
to more effectively deliver content
- web caching ์๋๋ฆฌ์ค
access link ์ฌ์ฉ๋ฅ : 97% โ ํฐ ๋๊ธฐ์ด ์ง์ฐ
- ์๋ฃจ์ :
- ์ด ๋ฐฉ๋ฒ์ ํจ๊ณผ์ ์ด์ง๋ง ๋น์ฉ์ด ๋ง์ด ๋๋ ํด๊ฒฐ์ฑ
- install a web cache
cache hit rate
๊ฐ 40%์ธ ๊ฒฝ์ฐ 40%์ ์์ฒญ์ ์บ์์์ ๋ฎ์ ์ง์ฐ ์๊ฐ(๋ฐ๋ฆฌ์ด)์ผ๋ก ์ฒ๋ฆฌ
60%์ ์์ฒญ์ ์ฌ์ ํ ์๋ณธ ์๋ฒ์์ ์ฒ๋ฆฌ
ํ๊ท ์ง์ฐ ์๊ฐ = 0.6 * (์๋ณธ ์๋ฒ์์์ ์ง์ฐ) + 0.4 * (์บ์์์์ ์ง์ฐ)
= 0.6 * (2.01์ด) + 0.4 * (๋ฐ๋ฆฌ์ด) โ 1.2์ด
Conditional GET
๐Conditional GET: client์ cache์ ์ด๋ฏธ ์ต์ ๋ฒ์ ์ ๊ฐ์ฒด๊ฐ ์๋ค๋ฉด, ์๋ฒ๊ฐ ๊ฐ์ฒด๋ฅผ ๋ค์ ๋ณด๋ด์ง ์๋๋ก ํ๋ ๊ฒ
Client
: HTTP ์์ฒญ์If-modified-since: <date>
ํค๋๋ฅผ ํฌํจํ์ฌ ์์ ์ด ๊ฐ์ง ์บ์๋ ๋ฒ์ ์ ๋ ์ง๋ฅผ ๋ช ์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 ๋ธ๋กํน ์ํ
- HTTP/2 ํ๊ณ
- ๋จ์ผ TCP ์ฐ๊ฒฐ์ ์์กด โ ํจํท ์์ค ๋ฐ์ ์ ๋ชจ๋ ๊ฐ์ฒด ์ ์ก์ด ์ง์ฐ
- TCP ์ฐ๊ฒฐ ์์ฒด์๋ ๊ธฐ๋ณธ์ ์ธ ๋ณด์ ๋ฉ์ปค๋์ฆ์ด ์์
๐ป HTTP/3
- UDP ๊ธฐ๋ฐ์
QUIC protocol
์ฌ์ฉ - ํฅ์๋ ๋ณด์: ๊ธฐ๋ณธ์ ์ผ๋ก ์ํธํ ์ ๊ณต
- ๊ฐ์ฒด๋ณ ์ค๋ฅ ๋ฐ ํผ์ก ์ ์ด: ํ๋์ ๊ฐ์ฒด ์ ์ก ๋ฌธ์ ๊ฐ ๋ค๋ฅธ ๊ฐ์ฒด ์ ์ก์ ์ํฅ์ ๋ฏธ์น์ง ์์
- more pipelining: ๋ณ๋ ฌ ์ฒ๋ฆฌ ๊ธฐ๋ฅ ํฅ์
E-mail, SMTP
E-mail์ 3๊ฐ์ง ๊ตฌ์ฑ์์
- user agent
- mail servers
- 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
SMTP between mail servers to send email messages
- client: sending mail server
- server: receiving mail server