Skip to content

Commit

Permalink
[#12] Write about database pool
Browse files Browse the repository at this point in the history
  • Loading branch information
Delf-Lee committed Nov 7, 2018
1 parent db59911 commit 43156a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ out/*
.idea/dictionaries
.idea/libraries
.idea/caches

# MacOS
.DS_Store
30 changes: 29 additions & 1 deletion contents/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,36 @@
---

### ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ํ’€
- **Connection Pool**
- ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์— ๋”ฐ๋ผ ๊ฐ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์Šค๋ ˆ๋“œ์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Connection์ด ํ•„์š”ํ•˜๋‹ค.
- Connection pool์€ ์ด๋Ÿฐ Connection์„ ์—ฌ๋Ÿฌ ๊ฐœ ์ƒ์„ฑํ•ด ๋‘์–ด ์ €์žฅํ•ด ๋†“์€ **๊ณต๊ฐ„(์บ์‹œ)**, ๋˜๋Š” ์ด ๊ณต๊ฐ„์˜ Connection์„ ํ•„์š”ํ•  ๋•Œ ๊บผ๋‚ด ์“ฐ๊ณ  ๋ฐ˜ํ™˜ํ•˜๋Š” **๊ธฐ๋ฒ•**์„ ๋งํ•œ๋‹ค.
![](./images/db-img/db-connection-02.png)

- **DB์— ์ ‘๊ทผํ•˜๋Š” ๋‹จ๊ณ„**
1. ์›น ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์‹คํ–‰๋˜๋ฉด์„œ DB์™€ ์—ฐ๊ฒฐ๋œ Connection ๊ฐ์ฒด๋“ค์„ ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•˜์—ฌ pool์— ์ €์žฅํ•œ๋‹ค.
2. DB์— ์š”์ฒญ ์‹œ, pool์—์„œ Connection ๊ฐ์ฒด๋ฅผ ๊ฐ€์ ธ์™€ DB์— ์ ‘๊ทผํ•œ๋‹ค.
3. ์ฒ˜๋ฆฌ๊ฐ€ ๋๋‚˜๋ฉด ๋‹ค์‹œ pool์— ๋ฐ˜ํ™˜ํ•œ๋‹ค.

![](./images/db-img/db-connection-01.jpeg)

- **Connction์ด ๋ถ€์กฑํ•˜๋ฉด?**
๋ชจ๋“  ์š”์ฒญ์ด DB์— ์ ‘๊ทผํ•˜๊ณ  ์žˆ๊ณ  ๋‚จ์€ Conncetion์ด ์—†๋‹ค๋ฉด, ํ•ด๋‹น ํด๋ผ์ด์–ธํŠธ๋Š” ๋Œ€๊ธฐ ์ƒํƒœ๋กœ ์ „ํ™˜์‹œํ‚ค๊ณ  Pool์— Connection์ด ๋ฐ˜ํ™˜๋˜๋ฉด ๋Œ€๊ธฐ ์ƒํƒœ์— ์žˆ๋Š” ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ˆœ์ฐจ์ ์œผ๋กœ ์ œ๊ณต๋œ๋‹ค.

- **์™œ ์‚ฌ์šฉํ• ๊นŒ?**
- ๋งค ์—ฐ๊ฒฐ๋งˆ๋‹ค Connection ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์†Œ๋ฉธ์‹œํ‚ค๋Š” ๋น„์šฉ์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค.
- ๋ฏธ๋ฆฌ ์ƒ์„ฑ๋œ Connection ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, DB ์ ‘๊ทผ ์‹œ๊ฐ„์ด ๋‹จ์ถ•๋œ๋‹ค.
- DB์— ์ ‘๊ทผํ•˜๋Š” Connection์˜ ์ˆ˜๋ฅผ ์ œํ•œํ•˜์—ฌ, ๋ฉ”๋ชจ๋ฆฌ์™€ DB์— ๊ฑธ๋ฆฌ๋Š” ๋ถ€ํ•˜๋ฅผ ์กฐ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

- **Thread Pool**
- ๋น„์Šทํ•œ ๋งฅ๋ฝ์œผ๋กœ Thread pool์ด๋ผ๋Š” ๊ฐœ๋…๋„ ์žˆ๋‹ค.
- ์ด ์—ญ์‹œ ๋งค ์š”์ฒญ๋งˆ๋‹ค ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  Thread๋ฅผ ๋งŒ๋“œ๋Š”๊ฒƒ์ด ์•„๋‹Œ, ๋ฏธ๋ฆฌ ์ƒ์„ฑํ•œ pool ๋‚ด์˜ Thread๋ฅผ ์†Œ๋ฉธ์‹œํ‚ค์ง€ ์•Š๊ณ  ์žฌ์‚ฌ์šฉํ•˜์—ฌ ํšจ์œจ์ ์œผ๋กœ ์ž์›์„ ํ™œ์šฉํ•˜๋Š” ๊ธฐ๋ฒ•.

- **Thread Pool๊ณผ Connection pool**
- WAS์—์„œ Thread pool๊ณผ Connection pool๋‚ด์˜ Thread์™€ Connection์˜ ์ˆ˜๋Š” ์ง์ ‘์ ์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ์™€ ๊ด€๋ จ์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ๋งŽ์ด ์‚ฌ์šฉํ•˜๋ฉด ํ•  ์ˆ˜๋ก ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๋งŽ์ด ์ ์œ ํ•˜๊ฒŒ ๋œ๋‹ค. ๊ทธ๋ ‡๋‹ค๊ณ  ๋ฐ˜๋Œ€๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์œ„ํ•ด ์ ๊ฒŒ ์ง€์ •ํ•œ๋‹ค๋ฉด, ์„œ๋ฒ„์—์„œ๋Š” ๋งŽ์€ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜์ง€ ๋ชปํ•˜๊ณ  ๋Œ€๊ธฐ ํ•  ์ˆ˜ ๋ฐ–์— ์—†๋‹ค.
- ๋ณดํ†ต WAS์˜ Thread์˜ ์ˆ˜๊ฐ€ Conncetion์˜ ์ˆ˜๋ณด๋‹ค ๋งŽ์€ ๊ฒƒ์ด ์ข‹์€๋ฐ, ๊ทธ ์ด์œ ๋Š” ๋ชจ๋“  ์š”์ฒญ์ด DB์— ์ ‘๊ทผํ•˜๋Š” ์ž‘์—…์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

> :arrow_double_up:[Top](#4-database) :leftwards_arrow_with_hook:[Back](https://github.com/Do-Hee/tech-interview#4-database) :information_source:[Home](https://github.com/Do-Hee/tech-interview#tech-interview)
> - []()
> - https://delf-lee.github.io/post/connection-pool/
### ์ •๊ทœํ™” 1์ฐจ 2์ฐจ 3์ฐจ BCNF
> :arrow_double_up:[Top](#4-database) :leftwards_arrow_with_hook:[Back](https://github.com/Do-Hee/tech-interview#4-database) :information_source:[Home](https://github.com/Do-Hee/tech-interview#tech-interview)
Expand Down
Binary file added contents/images/db-img/db-connection-01.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added contents/images/db-img/db-connection-02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 43156a5

Please sign in to comment.