Skip to content

Commit

Permalink
Add java/tomcat architecture
Browse files Browse the repository at this point in the history
- ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ ํ†ฐ์บฃ์˜ ์•„ํ‚คํ…์ฒ˜
  • Loading branch information
hyh1016 committed Jul 16, 2024
1 parent 7bd4c24 commit 7d6c551
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Binary file added java/imgs/tomcat-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions java/tomcat_architecture.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Tomcat Architecture

## ํ†ฐ์บฃ์€ WAS๊ฐ€ ์•„๋‹ˆ๋ผ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ

### WAS๋ž€?

- Jakarta EE(์ „ Java EE)๋ผ๋Š” ๋ช…์„ธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ตฌํ˜„์ฒด๋ฅผ WAS๋ผ๊ณ  ํ•จ

### ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ

- ํ†ฐ์บฃ์€ Jakarta EE์˜ ์ „์ฒด ๋ช…์„ธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋Œ€์‹  Servlet๊ณผ JSP ์‹คํ–‰ ํ™˜๊ฒฝ์„ ์ œ๊ณตํ•˜๋Š” ๋ฐ์— ์ง‘์ค‘ํ•˜๊ธฐ ๋•Œ๋ฌธ์— WAS๋ณด๋‹ค๋Š” ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋กœ ๋ถ„๋ฅ˜๋จ

## ํ†ฐ์บฃ ์•„ํ‚คํ…์ฒ˜

![tomcat-architecture](./imgs/tomcat-architecture.png)
https://www3.ntu.edu.sg/home/ehchua/programming/howto/Tomcat_More.html

- ํ†ฐ์บฃ **์„œ๋ฒ„**๋Š” ์—ฌ๋Ÿฌ ๊ฐœ์˜ **์„œ๋น„์Šค**๋กœ ๊ตฌ์„ฑ
- ๊ฐ **์„œ๋น„์Šค**๋Š” ํ•˜๋‚˜์˜ **์—”์ง„**๊ณผ ์—ฌ๋Ÿฌ ๊ฐœ์˜ **์ปค๋„ฅํ„ฐ**๋ฅผ ํฌํ•จํ•˜๋ฉฐ, ์ปค๋„ฅํ„ฐ๋ฅผ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›๊ณ  ์—”์ง„์—์„œ ์ฒ˜๋ฆฌํ•œ ๋’ค ์‘๋‹ต์„ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰
- **์—”์ง„**์€ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ฃผ์ฒด๋กœ, ๋„๋ฉ”์ธ์œผ๋กœ ๋ถ„๋ฅ˜๋˜๋Š” ์—ฌ๋Ÿฌ **ํ˜ธ์ŠคํŠธ**๋ฅผ ํฌํ•จ
- **์ปค๋„ฅํ„ฐ**๋Š” ํŠน์ • ํ”„๋กœํ† ์ฝœ/ํŠน์ • ํฌํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„ ์ ์ ˆํ•œ ์—”์ง„์œผ๋กœ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰
- **ํ˜ธ์ŠคํŠธ**๋Š” ๋„๋ฉ”์ธ๊ณผ ์—ฐ๊ฒฐ๋œ ํ•˜๋‚˜์˜ ์›น์‚ฌ์ดํŠธ๋กœ, ํ•œ ๊ฐœ ์ด์ƒ์˜ **์ปจํ…์ŠคํŠธ**๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ์Œ
- **์ปจํ…์ŠคํŠธ**๋Š” ๊ฐœ๋ณ„ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ, ๋ฃจํŠธ ๋””๋ ‰ํ† ๋ฆฌ์™€ ์„ค์ • ์ •๋ณด๋ฅผ ํฌํ•จ
- ๊ทธ ์™ธ์—๋„ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ตฌ์„ฑ ์š”์†Œ๊ฐ€ ์กด์žฌ
- **Realm(๋ ๋ฆ„)** - ์ธ์ฆ/๊ถŒํ•œ ๋ถ€์—ฌ๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ
- **Valve(๋ฐธ๋ธŒ)** - ์š”์ฒญ์„ ๊ฐ€๋กœ์ฑ„ ํŠน์ • ์ฒ˜๋ฆฌ๋ฅผ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋Š” ์ปดํฌ๋„ŒํŠธ

## Connector

- ํด๋ผ์ด์–ธํŠธ์˜ ์›น ์š”์ฒญ์„ ๋ฐ›์•„ ์ ์ ˆํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰

### ์ปค๋„ฅํ„ฐ์˜ ์ข…๋ฅ˜

- HTTP/HTTPS ํ˜ธ์ถœ์„ ์œ„ํ•œ HTTP 1.1 ์ปค๋„ฅํ„ฐ
- HTTP 2 ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์œผ๋ฉด `server.xml` ํŒŒ์ผ์˜ HTTP 1.1 ์ปค๋„ฅํ„ฐ ํƒœ๊ทธ ๋‚ด์—์„œ HTTP 2 UpgradeProtocol์„ ์ง€์ •ํ•˜๋ฉด ๋จ
- AJP(Apache JServ Protocol) ํ˜ธ์ถœ์„ ์œ„ํ•œ AJP/1.3 ์ปค๋„ฅํ„ฐ

### AJP ์ปค๋„ฅํ„ฐ

- ํ†ฐ์บฃ-์›น์„œ๋ฒ„ ๊ฐ„ ํ†ต์‹  ์ตœ์ ํ™”๋ฅผ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ (ํ†ฐ์บฃ-์›น์„œ๋ฒ„ ๊ฐ„ HTTP๋ฅผ ์“ฐ๋Š” ๊ฒƒ๋ณด๋‹ค ๋น ๋ฆ„)
- Spring Boot๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” ๋ณดํ†ต ๋‚ด์žฅ ํ†ฐ์บฃ์„ ์ด์šฉํ•˜๋ฉฐ ๋ณ„๋„ ์ •์  ์„œ๋ฒ„๋ฅผ ๋‘์ง€ ์•Š์œผ๋ฏ€๋กœ AJP ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜์ง€๋Š” ์•Š์Œ
- ๋…๋ฆฝ์  ๋‹จ์ผ ์„œ๋ฒ„๋ฅผ ๊ด€๋ฆฌํ•จ์œผ๋กœ์จ ๋ฐฐํฌ ๋ฐ ๊ด€๋ฆฌ ์šฉ์ด์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ
- AJP๊ฐ€ ํ†ฐ์บฃ-์›น์„œ๋ฒ„ ํ†ต์‹ ์— ์žˆ์–ด์„œ๋Š” HTTP๋ณด๋‹ค ๋น ๋ฅธ ์ด์œ ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Œ
- ๋ฐ”์ด๋„ˆ๋ฆฌ ํฌ๋งท ์‚ฌ์šฉ์œผ๋กœ ํ”„๋กœํ† ์ฝœ ์˜ค๋ฒ„ํ—ค๋“œ ์ ˆ๊ฐ - HTTP๋Š” ์–ด์จŒ๋“  ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜. ๋ฐ”์ด๋„ˆ๋ฆฌ ํ”„๋กœํ† ์ฝœ์€ ํ•„์š”ํ•œ ํŒจํ‚ท ์ˆ˜, ํŒจํ‚ท์˜ ํฌ๊ธฐ๊ฐ€ ์ ˆ๊ฐ ๊ฐ€๋Šฅ
- ๋ฐ”์ด๋„ˆ๋ฆฌ ์ธ์ฝ”๋”ฉ - HTTP ๋ฉ”์„œ๋“œ, ํ—ค๋” ๋“ฑ์— ๋Œ€ํ•œ ๋ฐ”์ด๋„ˆ๋ฆฌ ์ธ์ฝ”๋”ฉ์„ ์ •์˜ (GET์„ 2๋ฐ”์ดํŠธ๋กœ ํ‘œํ˜„)
- ์—ฐ๊ฒฐ ์œ ์ง€ - HTTP/1.1 Keep-Alive๋ณด๋‹ค ๋” ํšจ์œจ์ ์œผ๋กœ ์—ฐ๊ฒฐ์„ ์žฌ์‚ฌ์šฉํ•ด ํ•ธ๋“œ์‰์ดํฌ ๋น„์šฉ์„ ์ ˆ๊ฐ
- ๋ถ€ํ•˜ ๋ถ„์‚ฐ - ์ •์  ์ปจํ…์ธ ๋Š” Apache๊ฐ€, ๋™์  ์ปจํ…์ธ ๋Š” AJP๋ฅผ ํ†ตํ•ด Tomcat์œผ๋กœ ์ „๋‹ฌ

### HTTP ์ปค๋„ฅํ„ฐ

- HTTP ํ”„๋กœํ† ์ฝœ๋กœ ์„œ๋ธ”๋ฆฟ/JSP์— ๋Œ€ํ•œ ์š”์ฒญ, ์ •์  ์ปจํ…์ธ  ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ปค๋„ฅํ„ฐ(์ž๋ฐ” ํด๋ž˜์Šค)
- ๊ธฐ๋ณธ์ ์œผ๋กœ SpringBoot์˜ ๋‚ด์žฅ ํ†ฐ์บฃ์—์„œ๋„ 8080ํฌํŠธ๋ฅผ ๋ฆฌ์Šค๋‹ํ•˜๋Š” HTTP/1.1 ์ปค๋„ฅํ„ฐ๋ฅผ ์‚ฌ์šฉ
- HTTP ์ปค๋„ฅํ„ฐ์˜ ์ข…๋ฅ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Œ
- HTTP/1.1 ์ปค๋„ฅํ„ฐ
- NIO HTTP ์ปค๋„ฅํ„ฐ
- ARP HTTP ์ปค๋„ฅํ„ฐ
- ๋‚ด๋ถ€์ ์œผ๋กœ ์Šค๋ ˆ๋“œ ํ’€์„ ์‚ฌ์šฉํ•˜๋ฉฐ ์ด ํ’€์€ `ThreadPoolExecutor`๋ฅผ ํ†ตํ•ด ๊ด€๋ฆฌ๋จ

### ํ”„๋กœํ† ์ฝœ ๊ตฌํ˜„์ฒด

- ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„ ๊ฐ„ ํ†ต์‹  ๋ฐฉ์‹์„ ์ •์˜ํ•˜๋Š” ๊ตฌ์„ฑ ์š”์†Œ
- BIO/NIO/APR 3์ข…๋ฅ˜๊ฐ€ ์žˆ๋Š”๋ฐ BIO๋Š” Tomcat 8.0๋ถ€ํ„ฐ ์‚ญ์ œ๋จ
- ํ˜„์žฌ SpringBoot์—์„œ๋Š” `Http11NioProtocol` ์„ ์‚ฌ์šฉ

### HTTP 11 NIO Protocol

- ํ˜„์žฌ ๊ธฐ๋ณธ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” HTTP ์ปค๋„ฅํ„ฐ
- ๋น„๋™๊ธฐ์‹ I/O๋ฅผ ์‚ฌ์šฉ
- ๊ตฌ์„ฑ ์š”์†Œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Œ
- Acceptor - ์†Œ์ผ“ ์—ฐ๊ฒฐ์„ ์ˆ˜๋ฝํ•˜๊ณ  ์ด๋ฒคํŠธ ํ์— ์บก์Šํ™”ํ•œ ์†Œ์ผ“ ์ฑ„๋„์„ ๋ฐœํ–‰
- Poller - ์ด๋ฒคํŠธ ํ๋กœ๋ถ€ํ„ฐ Acceptor๊ฐ€ ๋„ฃ์€ ์ด๋ฒคํŠธ๋ฅผ ์†Œ๋น„. ์†Œ์ผ“ ์ฑ„๋„์„ Selector์— ๋“ฑ๋ก. Selector๋Š” ์†Œ์ผ“์„ ์•Œ๋งž์€ ์›Œ์ปค ์Šค๋ ˆ๋“œ์— ์ „๋‹ฌ
- Executor(Worker Thread) - ์†Œ์ผ“์„ ๋ฐ›์•„ Engine(Servlet)์— ์š”์ฒญ์„ ์œ„์ž„
- Poller์™€ Acceptor๋Š” ๋ฌดํ•œ ๋ฃจํ”„๋ฅผ ๋Œ๋ฉฐ ํ์— ๋„ฃ์„ ๊ฒƒ์„ ๋ฐ›์•„ ๋„ฃ๊ณ  ํ์—์„œ ๊บผ๋‚ด๋Š” ๋‹จ์ผ ๋ฐ๋ชฌ ์Šค๋ ˆ๋“œ

0 comments on commit 7d6c551

Please sign in to comment.