Contents

Apache keepAlive

โ€ป ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์„ ํ†ตํ•ด ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„œ๋ฒ„๋ฅผ ์šด์˜ํ•˜๋‹ค๋ณด๋ฉด ๊ฐ„ํ˜น ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณค ํ•œ๋‹ค. ์ด๋ฅผํ…Œ๋ฉด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋‹ค๋ฅธ์ด์œ ์—†์ด ์˜ฌ๋ผ๊ฐ„๋‹ค๊ฑฐ๋‚˜, ์‚ฌ์šฉ์ž ์ž…์žฅ์—์„œ ์‘๋‹ต์†๋„๊ฐ€ ๊ฐ„ํ—์ ์œผ๋กœ ๋Š๋ฆฐ๋‹ค๊ฑฐ๋‚˜. ๊ทธ๋Ÿด๋•Œ๋งˆ๋‹ค ์„ ๋ฐฐ๊ฐœ๋ฐœ์ž๋ถ„๋“ค๊ป˜์„œ ๊ฐ€์žฅ๋จผ์ € ์ž…์— ์˜ค๋ฅด๋‚ด๋ฆฌ๋Š” ๋‹จ์–ด. keepAlive.

๋Œ€์ถฉ ๊ฒ€์ƒ‰์„ ํ•ด๋ณด๋ฉด ์ ‘์†์„ ์œ ์ง€ํ•˜๊ฑฐ๋‚˜ ๊ทธ๋ ‡์ง€ ์•Š๊ฑฐ๋‚˜ ํ•˜๋Š” ์„ค์ •์ด๊ตฌ๋‚˜ ๋งŒ์œผ๋กœ ์ƒ๊ฐํ–ˆ์—ˆ๋Š”๋ฐ ์ œ๋Œ€๋กœ ์งš๊ณ  ๋„˜์–ด๊ฐ€๋Š” ์˜๋ฏธ์—์„œ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณผ ํ•„์š”๊ฐ€ ์žˆ์„๊ฒƒ ๊ฐ™๋‹ค.

์ •์˜

์šฐ์„  2.4๋ฒ„์ „ ๊ธฐ์ค€ ๋„ํ๋จผํŠธ์˜ ๋‚ด์šฉ์„ ๋ณผ ํ•„์š”๊ฐ€ ์žˆ๋‹ค. https://httpd.apache.org/docs/2.4/mod/core.html#keepalive

The Keep-Alive extension to HTTP/1.0 and the persistent connection feature of HTTP/1.1 provide long-lived HTTP sessions which allow multiple requests to be sent over the same TCP connection. In some cases this has been shown to result in an almost 50% speedup in latency times for HTML documents with many images. To enable Keep-Alive connections, set KeepAlive On.

๋ฐœ๋ฒˆ์—ญ(ํŒŒํŒŒ๊ณ ์˜ ํž˜!)์œผ๋กœ ์ดํ•ดํ•œ ๋‚ด์šฉ์œผ๋กœ๋Š”, keepAlive๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด 50%๊นŒ์ง€ ๋Œ€๊ธฐ์‹œ๊ฐ„์„ ๋‹จ์ถ•ํ• ์ˆ˜ ์žˆ๋‹ค๋Š” ์„ค์ •์ด๋ผ ๋‚˜์™€์žˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‚˜๊ฐ™์€ ์˜์–ด์šธ๋ ์ค‘์ด ์žˆ๋Š” ์‚ฌ๋žŒ๋“ค(?)์€ ์˜์–ด ๋ฌธ์„œ๋งŒ์„ ๊ฐ€์ง€๊ณ  ์™„๋ฒฝํžˆ ์ดํ•ดํ• ์ˆ˜๋Š” ์—†๋‹ค. ๊ทธ๋ž˜์„œ ์ด๊ฒƒ์ €๊ฒƒ ์ฐพ์•„๋ณด๊ณ  ๋‹ค์‹œ ์ •๋ฆฌ๋ฅผ ํ•ด๋ณธ๋‹ค.

์ •๋ฆฌ

๊ธฐ๋ณธ์ ์œผ๋กœ ์™ธ๋ถ€ ์‚ฌ์šฉ์ž์— ์˜ํ•ด ์š”์ฒญ(access)์ด ๋“ค์–ด์˜ค๊ฒŒ ๋˜๋ฉด mpm๋ฐฉ์‹์ด ์–ด๋–ค๊ฑฐ๋“  ๊ฐ„์— (์•„ํŒŒ์น˜ MPM์— ๋Œ€ํ•ด์„œ๋„ ์ •๋ฆฌ๋ฅผ ํ•ด์•ผ๊ฒ ๊ตฐ..) ์•„ํŒŒ์น˜๊ฐ€ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋“  WAS์—๊ฒŒ ๋„˜๊ฒจ์ฃผ๋“  ํ•˜๋‚˜์˜ ํ๋ฆ„์ด ๋“ค์–ด์˜ค๋Š”๋ฐ ๋™์ผํ•œ ์‚ฌ์šฉ์ž์— ๋Œ€ํ•ด์„œ ์ด ํ๋ฆ„์„ ๋Š๊ณ  ๋‹ค์‹œ ์š”์ฒญ ๋ฐ›์„๊ฒƒ์ธ๊ฐ€ ์•„๋‹ˆ๋ฉด ์—ฐ๊ฒฐ์„ ์œ ์ง€ํ•˜๊ณ  ๋ฐ”๋กœ ์ฒ˜๋ฆฌ๋ฅผ ํ• ๊ฒƒ์ธ๊ฐ€์— ๋Œ€ํ•œ ์„ค์ •๊ฐ’์œผ๋กœ ์ดํ•ดํ•˜๋ฉด ์ข‹์„๋“ฏ ์‹ถ๋‹ค. ํ•„์ž๊ฐ€ ํ‘œํ˜„์„ ์ž˜ ๋ชปํ•ด์„œ ๊ทธ๋Ÿฐ๊ฒƒ์ผ์ˆ˜๋„ ์žˆ์œผ๋‹ˆ ๊ทธ๋ฆผ์œผ๋กœ ๋ณด๋Š”๊ฒŒ ๊ฐ€์žฅ ๋น ๋ฅผ์ง€๋„ ๋ชจ๋ฅด๊ฒ ๋‹ค.

/images/apache-keep-alive/keepalive_on_off.png
์ถœ์ฒ˜ : https://www.svennd.be/keepalive-on-or-off-apache-tuning

์œ„ ๊ทธ๋ฆผ์€ IT์ „๊ณต์ž๋ผ๋ฉด(?) ํ•œ๋ฒˆ์ฏค์€ ๋ดค์„ tcp 3-way handshake ์ธ๋ฐ, keepAlive ๋ฅผ on ํ•˜๋ฉด ์ดˆ๊ธฐ ์—ฐ๊ฒฐํ•˜๋Š” ๋น„์šฉ์„ ์กฐ๊ธˆ์ด๋‚˜๋งˆ ์ค„์ผ์ˆ˜ ์žˆ๋‹ค๋Š”๊ฑธ ๋ณด์—ฌ์ค€๋‹ค. ์ฆ‰, ๋‹ค์‹œ๋งํ•˜๋ฉด keepAlive๋Š” ํ•œ๋ฒˆ ์—ฐ๊ฒฐ๋œ ์ƒ๋Œ€์— ๋Œ€ํ•ด์„œ ์—ฐ๊ฒฐ์„ ์žƒ์ง€ ์•Š๊ณ (์ด๋Ÿฐ์ €๋Ÿฐ ์„ค์ •๊ฐ’์— ์˜์กด) ์ง€์†์ ์œผ๋กœ ์š”์ฒญ์— ์‘๋‹ต์„ ํ•ด์ค„์ˆ˜ ์žˆ๋‹ค๋Š” ์˜ต์…˜์ด๋‹ค. ๊ฐ„๋‹จํ•˜๊ฒŒ ์ƒ๊ฐํ•˜๋ฉด ์ด ์„ค์ •๊ฐ’์„ ์ด์šฉํ•˜๋ฉด ๋ชจ๋“  ์š”์ฒญ์— ์˜ํ•ด์„œ ์ง€์†์ ์œผ๋กœ ์‘๋‹ต์„ ํ•ด์ค„์ˆ˜ ์žˆ์œผ๋‹ˆ ๋ฌด์กฐ๊ฑด onํ•˜๋ฉด ๋˜๋Š”๊ฑฐ ์•„๋‹๊นŒ? ํ•˜๋Š” ์ƒ๊ฐ์ด ๋จผ์ €๋“ ๋‹ค. default ๊ฐ’๋„ on ์ด๋‹ˆ. ํ—ˆ๋‚˜ ์ž์นซ ์ž˜๋ชปํ•˜๋ฉด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ๋ชจ๋“  ์ ‘์†์ž ๋งˆ๋‹ค ์—ฐ๊ฒฐ ์œ ์ง€๋ฅผ ํ•ด ๋†“์•„์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์•„ํŒŒ์น˜ ํ”„๋กœ์„ธ์Šค์ˆ˜๊ฐ€ ๊ธฐํ•˜ ๊ธ‰์ˆ˜์ ์œผ๋กœ ๋Š˜์–ด๋‚˜ MaxClient๊ฐ’์„ ์ดˆ๊ณผํ•˜๊ฒŒ ๋œ๋‹ค. ๋˜ํ•œ On์ƒํƒœ์ผ๋•Œ ์ ‘์†์œ ์ง€ ํ•˜๋Š” ํ”„๋กœ์„ธ์Šค๋“ค ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ทธ ๋งŒํผ ๋งŽ์ด ์‚ฌ์šฉํ•˜๊ฒŒ ๋œ๋‹ค. ์ด ์–‘๋‚ ์˜ ๊ฒ€ keepAlive๋Š” ๊ณผ์—ฐ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•ด์•ผ ํ•˜๋Š”๊ฑธ๊นŒ?

์‚ฌ์šฉ ์‹œ๊ธฐ

์šฐ์„  ์•ž์„œ ๋งํ–ˆ๋˜๊ฒƒ๊ณผ ๊ฐ™์ด ๊ธฐ๋ณธ๊ฐ’์€ On์ด๋‹ค. ์ฆ‰, ์•„ํŒŒ์น˜ ์„ค์น˜์‹œ ๊ธฐ๋ณธ์œผ๋กœ ์—ฐ๊ฒฐ์œ ์ง€๋ฅผ ํ•˜๋Š”๊ฒƒ. ํ•˜์ง€๋งŒ ์ƒํ™ฉ์— ๋”ฐ๋ผ Onํ• ์ง€ Offํ• ์ง€๋ฅผ ๊ฒฐ์ •ํ•ด์•ผ ํ•œ๋‹ค.

  • On ํ•ด์•ผํ•  ๊ฒฝ์šฐ ์ ‘์†์ž์˜ ์ˆ˜ ์ƒ๊ด€์—†์ด ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ถฉ๋ถ„ํ• ๊ฒฝ์šฐ

    ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ถฉ๋ถ„ํ•˜๋‹ค : ์ ‘์†์ž๊ฐ€ maxclient ๊ฐ’์— ๋„๋‹ฌํ–ˆ์„๊ฒฝ์šฐ, swap๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ƒํƒœ

  • Off ํ•ด์•ผํ•  ๊ฒฝ์šฐ
    • ๋™์‹œ ์ ‘์†์ž์ˆ˜๊ฐ€ ๋งŽ์„๊ฒฝ์šฐ
    • ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์ถฉ๋ถ„ํ•˜์ง€ ๋ชปํ• ๊ฒฝ์šฐ
  • ํ•˜์ง€๋งŒ ์œ„์˜ ๊ฒฝ์šฐ๋Š” ์ง€๊ทนํžˆ ์ผ๋ฐ˜์ ์ธ๊ฒฝ์šฐ๊ณ  ์šด์˜ํ•˜๋Š” ์„œ๋ฒ„์˜ ๋ฉ”๋ชจ๋ฆฌ์˜ ์ƒํƒœ๋‚˜ ์ ‘์†์ž์˜ ์ˆ˜๋ฅผ ํ™•์ธํ•˜๋ฉด์„œ ์กฐ์ •์ด ํ•„์š”ํ•˜๋‹ค. ๊ผญ keepAlive์— ๊ตญํ•œ๋˜๋Š”๊ฒƒ์€ ์•„๋‹ˆ์ง€๋งŒ ๋ชจ๋“  ๊ฐœ๋ฐœ์—๋Š” ์ ˆ๋Œ€์ ์ธ ๋‹ต์€ ์—†๋Š”๊ฒƒ ๊ฐ™๋‹ค.

keepAlive ๋ฅผ Onํ•  ๊ฒฝ์šฐ์˜ ์ถ”๊ฐ€ ์…‹ํŒ…๋ถ€๋ถ„

(์ฐธ๊ณ  : https://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html)

  • MaxKeepAliveRequest [ํšŒ์ˆ˜] ํ•˜๋‚˜์˜ ์ง€์†์ ์ธ ์—ฐ๊ฒฐ์—์„œ ์„œ๋น„์Šค๋ฅผ ์ œ๊ณตํ•  ์š”์ฒญ์˜ ์ตœ๋Œ€ ๊ฐ’์„ ์„ค์ •ํ•œ๋‹ค. 50 ๊ณผ 75 ์‚ฌ์ด ์ •๋„๋ฉด ์ถฉ๋ถ„ํ•˜๋‹ค๊ณ  ํ•œ๋‹ค.
  • KeepAliveTimeout [์ดˆ] ์—ฐ๊ฒฐ๋œ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ์ƒˆ๋กœ์šด ์š”์ฒญ์„ ๋ฐ›๊ธฐ๊นŒ์ง€ ์„œ๋ฒ„๊ฐ€ ์–ผ๋งˆ๋‚˜ ๊ธฐ๋‹ค๋ฆด ๊ฒƒ์ธ๊ฐ€๋ฅผ ์„ค์ •ํ•œ๋‹ค. (default : 15์ดˆ) ์ผ๋ฐ˜์ ์œผ๋กœ 1~5์ดˆ ์ •๋„๋กœ ์„ค์ •ํ•˜๊ณค ํ•œ๋‹ค.
  • MaxClients [ํšŒ์ˆ˜] ์ž์‹ํ”„๋กœ์„ธ์Šค๋“ค์˜ ์ตœ๋Œ€ ๊ฐ’์„ ์„ค์ •ํ•œ๋‹ค. ์ด๋Š” ๋ฉ”๋ชจ๋ฆฌ์˜ ํฌ๊ธฐ์™€ ์ƒ๊ด€๊ด€๊ณ„๊ฐ€ ์žˆ๋‹ค.
  • MaxRequestsPerChild [ํšŒ์ˆ˜] ํด๋ผ์ด์–ธํŠธ๋“ค์˜ ์š”์ฒญ ๊ฐœ์ˆ˜๋ฅผ ์ œํ•œ. ๋งŒ์•ฝ ์ž์‹ ํ”„๋กœ์„ธ์Šค๊ฐ€ ์ด ๊ฐ’๋งŒํผ์˜ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์„ ๋ฐ›์•˜๋‹ค๋ฉด ์ด ์ž์‹ ํ”„๋กœ์„ธ์Šค๋Š” ์ž๋™์œผ๋กœ ์ฃฝ๊ฒŒ ๋œ๋‹ค. 0 ์ผ ๊ฒฝ์šฐ์—” ๋ฌดํ•œ๋Œ€. ์ด ์„ค์ •๊ฐ’์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ๋ˆ„์ˆ˜๋ฅผ ๋ฐฉ์ง€ํ• ์ˆ˜ ์žˆ๋‹ค.

์–ด์จ‹๋“ , ์ •๋‹ต์€ ์—†๋‹ค. ์ƒํ™ฉ์— ๋งž์ถฐ์„œ ์„ค์ •ํ• ๊ฒƒ! ๊ทธ์—๋”ฐ๋ฅธ ์ฑ…์ž„์€ ๋ณธ์ธ์ด ๊ฐ€์ ธ๊ฐ€์•ผํ•˜๋Š”๊ฑธ ๋ช…์‹ฌ!

โ€ป ์ฟ ํŒก ํŒŒํŠธ๋„ˆ์Šค ํ™œ๋™์„ ํ†ตํ•ด ์ผ์ •์•ก์˜ ์ˆ˜์ˆ˜๋ฃŒ๋ฅผ ์ œ๊ณต๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


Buy me a coffeeBuy me a coffee