DB Connection Pool ์— ๋Œ€ํ•ด ๐Ÿค”

yeeun leeยท2020๋…„ 7์›” 12์ผ
0

์„œ๋ฒ„ ์†๋„ ํ–ฅ์ƒ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋‹ค๊ฐ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ ํ’€์„ ์•Œ๊ฒŒ ๋๋‹ค. ์—ฐ๊ฒฐ ํ’€์€ ์ง€์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ MySQL, ์˜ค๋ผํด, PostgreSQL ๊ฐ™์€ ๊ธฐ๋ณธ์ ์ธ DBMS์—์„œ๋Š” ๋‹ค ์ง€์›๋œ๋‹ค.

Connection Pool

์—ฐ๊ฒฐ ํ’€๋˜๋Š” ์ปค๋„ฅ์…˜ ํ’€(connection pool)์€ ์†Œํ”„ํŠธ์›จ์–ด ๊ณตํ•™์—์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ์˜ ์ถ”๊ฐ€ ์š”์ฒญ์ด ํ•„์š”ํ•  ๋•Œ ์—ฐ๊ฒฐ์„ ์žฌ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ด€๋ฆฌ๋˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ์˜ ์บ์‹œ์ด๋‹ค.

์—ฐ๊ฒฐ ํ’€์„ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์˜ ๋ช…๋ น ์‹คํ–‰์˜ ์„ฑ๋Šฅ์„ ๊ฐ•ํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ ์‚ฌ์šฉ์ž๋งˆ๋‹ค ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๊ฒฐ์„ ์—ด๊ณ  ์œ ์ง€๋ณด์ˆ˜ํ•˜๋Š” ๊ฒƒ์€ ๋น„์šฉ์ด ๋งŽ์ด ๋“ค๊ณ  ์ž์›์„ ๋‚ญ๋น„ํ•œ๋‹ค.

์—ฐ๊ฒฐ ํ’€์˜ ๊ฒฝ์šฐ ์—ฐ๊ฒฐ์ด ์ˆ˜๋ฆฝ๋œ ์ดํ›„์— ํ’€์— ์œ„์น˜ํ•ด ์žˆ์œผ๋ฏ€๋กœ ๋‹ค์‹œ ์‚ฌ์šฉํ•˜๋ฉด ์ƒˆ๋กœ์šด ์—ฐ๊ฒฐ์„ ์ˆ˜๋ฆฝํ•  ํ•„์š”๊ฐ€ ์—†์–ด์ง„๋‹ค. ๋ชจ๋“  ์—ฐ๊ฒฐ์ด ์‚ฌ์šฉ ์ค‘์ด๋ฉด ์ƒˆ๋กœ์šด ์—ฐ๊ฒฐ์„ ๋งŒ๋“ค๊ณ  ํ’€์— ์ถ”๊ฐ€๋œ๋‹ค. ์—ฐ๊ฒฐ ํ’€์€ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐ์„ ์ˆ˜๋ฆฝํ•˜๋Š”๋ฐ๊นŒ์ง€ ๋Œ€๊ธฐํ•ด์•ผํ•˜๋Š” ์‹œ๊ฐ„์„ ์ค„์ด๊ธฐ๋„ ํ•œ๋‹ค.

DAO๊ฐ€ init๋˜๋Š” ์‹œ์ ์— ์ปค๋„ฅ์…˜ ํ’€์„ ์ƒ์„ฑํ•˜๊ณ , cursor๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ fetchํ•  ๋•Œ connection pool์—์„œ ๊ฐ€์ ธ์™€์„œ ์‚ฌ์šฉ. ์—ฐ๊ฒฐ์„ ๊ณ„์† ์—ด์—ˆ๋‹ค ๋‹ซ์•˜๋‹ค๊ฐ€ ํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๊ธฐ ๋•Œ๋ฌธ์— ์†๋„ ํ–ฅ์ƒ ํšจ๊ณผ๋ฅผ ์ค„ ์ˆ˜ ์žˆ๋‹ค.

๊ณต์‹ ๋ฌธ์„œ

Features

  • Maintain a minimum number of connection pools by default.
  • If a number of unuse connections less than zero, dynamically add connections to pool until the current number of inuse connections equal maximum of the pool.
  • Release the idle connections in regular until a number of unuse - connections equal minimum of the pool.
  • Support auto-commit mode.
  • Support for ping check to get healthy connections.๐Ÿค”
profile
์ด์‚ฌ๊ฐ„ ๋ธ”๋กœ๊ทธ: yenilee.github.io

0๊ฐœ์˜ ๋Œ“๊ธ€