๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ชฉ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค.

[Tomcat] ์„œ๋ฒ„ ์บ์‰ฌ ๊ณต๊ฐ„ ๋ถ€์กฑ

Server
    ๐Ÿ’ก WAS(Web Application Server)์ธ ํ†ฐ์บฃ(Tomcat) ์šด์˜ ์ค‘ ์บ์‰ฌ ๊ณต๊ฐ„ ๋ถ€์กฑ ์—๋Ÿฌ ๊ด€๋ จ ์ •๋ฆฌ

    - Tomcat ๋ฒ„์ „(version): 9.0.70
    Tomcat์— ๋Œ€ํ•ด์„œ ์•Œ๊ณ  ์‹ถ์œผ์‹œ๋‹ค๋ฉด ์—ฌ๊ธฐ๋ฅผ ๋ณด์„ธ์š”!

    ์ƒํ™ฉ์ •๋ฆฌ

    WAS(Web Application Server)์ธ ํ†ฐ์บฃ(Tomcat: ์ˆ˜์ปท๊ณ ์–‘์ด)์„ ์šด์˜ ํ•˜๋‹ค๊ฐ€ ์บ์‰ฌ ๊ณต๊ฐ„์ด ๋ถ€์กฑํ•˜๋‹ค๋Š” ์—๋Ÿฌ๋ฅผ ๋งˆ์ฃผ์ณค์Šต๋‹ˆ๋‹ค.

    org.apache.catalina.webresources.Cache backgroundProcess
    ์ •๋ณด: The background cache eviction process was unable to free [10] percent of the cache for Context [] - consider increasing the ma
    ximum size of the cache. After eviction approximately [8,127] KB of data remained in the cache.

     

    ํ†ฐ์บฃ์€ ์บ์‰ฌ๋ฅผ ์–ด๋””์„œ ์…‹ํŒ…ํ•˜๋‚˜ ํ–ˆ๋”๋‹ˆ ์ด๋ฒˆ ๊ธฐํšŒ์— ์ •๋ฆฌํ•ด๋ด…๋‹ˆ๋‹ค.

     


     

    context.xml ํŽธ์ง‘

    ์šฐ์„  ํ†ฐ์บฃ์ด ์„ค์น˜๋œ ๊ฒฝ๋กœ๋กœ ๊ฐ€์„œ conf ๋””๋ ‰ํ† ๋ฆฌ์— ์žˆ๋Š” context.xml(์—†์œผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ) ํŒŒ์ผ์„ ์—ด์–ด์ค๋‹ˆ๋‹ค.

     

    ${CATALINA_HOME}/conf/context.xml (์—†์œผ๋ฉด ์ƒˆ๋กœ ์ƒ์„ฑ)

    # context.xml ํŽธ์ง‘
    $ vi ${CATALINA_HOME}/conf/context.xml
    
    # vim ์ด ์„ค์น˜๋œ ๊ฒฝ์šฐ ์•„๋ž˜ ๋ช…๋ น์–ด๋กœ ํŽธ์ง‘๊ธฐ๋ฅผ ์—ด๋ฉด ์กฐ๊ธˆ ๋” ๊ฐ€๋…์„ฑ์ด ์ข‹์•„์š”!
    $ vim ${CATALINA_HOME}/conf/context.xml

     

    ํ†ฐ์บฃ ์บ์‰ฌ ์„ค์ • (How to set cache in tomcat-9.0.70)

    context.xml์˜ resource๋ฅผ ์„ค์ •ํ•˜๋Š” ๊ฒƒ ๊ด€๋ จํ•ด์„œ ์กฐ๊ธˆ ๋” ์ž์„ธํžˆ ์–ด๋–ค ๊ฒƒ๋“ค์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•˜์‹œ๋‹ค๋ฉด??
    ์—ฌ๊ธฐ๋ฅผ ๋ณด์„ธ์š”!

     

    ์œ„์˜ ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํฌ๊ฒŒ ์•„๋ž˜ 2๊ฐ€์ง€ ์ž…๋‹ˆ๋‹ค

    ์บ์‰ฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ์„ค์ •ํ•œ๋‹ค

    <Resources cachingAllowed="false" />
    ๋”๋ณด๊ธฐ

    document์— ์žˆ๋Š” cachingAllowed ์†์„ฑ ์„ค๋ช…

     

    ์›๋ฌธ: If the value of this flag is true, the cache for static resources will be used. If not specified, the default value of the flag is true. This value may be changed while the web application is running (e.g. via JMX). When the cache is disabled any resources currently in the cache are cleared from the cache.

     

    ๋ฒˆ์—ญ: ์ด ํ”Œ๋ž˜๊ทธ์˜ ๊ฐ’์ด true์ด๋ฉด ์ •์  ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•œ ์บ์‹œ๊ฐ€ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ํ”Œ๋ž˜๊ทธ์˜ ๊ธฐ๋ณธ๊ฐ’์€ true์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์€ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ(์˜ˆ: JMX๋ฅผ ํ†ตํ•ด) ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์บ์‹œ๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋˜๋ฉด ํ˜„์žฌ ์บ์‹œ์— ์žˆ๋Š” ๋ชจ๋“  ๋ฆฌ์†Œ์Šค๊ฐ€ ์บ์‹œ์—์„œ ์ง€์›Œ์ง‘๋‹ˆ๋‹ค.

    cachingAllowed์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ฝ์–ด๋ณด๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    1. ๊ธฐ๋ณธ๊ฐ’์€ true
    2. ์ •์  ๋ฆฌ์†Œ์Šค์— ๋Œ€ํ•ด์„œ๋งŒ ์บ์‹œ๊ฐ€ ์‚ฌ์šฉ๋จ
    3. ํ†ฐ์บฃ์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ์—๋„ ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅํ•จ
    4. ๋น„ํ™œ์„ฑํ™” ์‹œ ํ˜„์žฌ ์บ์‹œ์— ์žˆ๋Š” ๋ชจ๋“  ๋ฆฌ์†Œ์Šค ์ง€์›Œ์ง

     

     

    ์บ์‰ฌ ๊ณต๊ฐ„ ํฌ๊ธฐ๋ฅผ ๋Š˜๋ฆฐ๋‹ค

    <Resources cachingAllowed="true" cacheMaxSize="100000"/>
    cacheMaxSize ๋‹จ์œ„: Kilobytes
    cacheMaxSize ๊ธฐ๋ณธ๊ฐ’: 10240(KB. ์•ฝ 10MB)
    cacheMaxSize๋Š” ๊ฐ์ž ์„œ๋ฒ„ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์„ค์ •ํ•ด์ฃผ์„ธ์š”!
    ๋”๋ณด๊ธฐ

    document์— ์žˆ๋Š” cacheMaxSize ์†์„ฑ ์„ค๋ช…

     

    ์›๋ฌธ: The maximum size of the static resource cache in kilobytes. If not specified, the default value is 10240 (10 megabytes). This value may be changed while the web application is running (e.g. via JMX). If the cache is using more memory than the new limit the cache will attempt to reduce in size over time to meet the new limit. If necessary, cacheObjectMaxSize will be reduced to ensure that it is no larger than cacheMaxSize/20.

     

    ๋ฒˆ์—ญ: ์ •์  ๋ฆฌ์†Œ์Šค ์บ์‹œ์˜ ์ตœ๋Œ€ ํฌ๊ธฐ(KB)์ž…๋‹ˆ๋‹ค. ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’์€ 10240(10MB)์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์€ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ(์˜ˆ: JMX๋ฅผ ํ†ตํ•ด) ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์บ์‹œ๊ฐ€ ์ƒˆ ์ œํ•œ๋ณด๋‹ค ๋” ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ ์บ์‹œ๋Š” ์ƒˆ ์ œํ•œ์„ ์ถฉ์กฑํ•˜๊ธฐ ์œ„ํ•ด ์‹œ๊ฐ„์ด ์ง€๋‚จ์— ๋”ฐ๋ผ ํฌ๊ธฐ๋ฅผ ์ค„์ด๋ ค๊ณ  ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค. ํ•„์š”ํ•œ ๊ฒฝ์šฐ cacheObjectMaxSize๋Š” cacheMaxSize/20๋ณด๋‹ค ํฌ์ง€ ์•Š๋„๋ก ์ค„์ž…๋‹ˆ๋‹ค.

    cacheMaxSize์— ๋Œ€ํ•œ ์„ค๋ช…์„ ์ฝ์–ด๋ณด๋ฉด ๊ฐ„๋‹จํ•˜๊ฒŒ๋Š” ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

    1. ์บ์‹œ ์ตœ๋Œ€ ํฌ๊ธฐ(KB). ๊ธฐ๋ณธ๊ฐ’ 10240KB (10MB)
    2. ํ†ฐ์บฃ์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ ๋ณ€๊ฒฝ ๊ฐ€๋Šฅํ•จ
    3. ๋ณ€๊ฒฝ๋œ ์บ์‹œ๊ฐ€ ๊ธฐ์กด ์‚ฌ์ด์ฆˆ๋ณด๋‹ค ์ž‘๊ฒŒ ์„ค์ •๋œ ๊ฒฝ์šฐ ์„œ์„œํžˆ ๋ฉ”๋ชจ๋ฆฌ ์ ์œ  ์‚ฌ์ด์ฆˆ๋ฅผ ์ค„์ด๋ ค๊ณ  ์‹œ๋„ํ•จ

     

    ํ•„์š”ํ•œ ๊ฒฝ์šฐ cacheObjectMaxSize๋ฅผ cacheMaxSize / 20 ๋ณด๋‹ค ํฌ์ง€ ์•Š๊ฒŒ ์„ค์ •ํ•˜๋ผ๋Š”๋ฐ ์—ฌ๊ธฐ์„œ cacheObjectMaxSize๋Š” ๋ญ˜๊นŒ??

    ๋”๋ณด๊ธฐ

    document์— ์žˆ๋Š” cacheObjectMaxSize ์†์„ฑ ์„ค๋ช…

     

    ์›๋ฌธ: Maximum size of the static resource that will be placed in the cache. If not specified, the default value is 512 (512 kilobytes). If this value is greater than cacheMaxSize/20 it will be reduced to cacheMaxSize/20. This value may be changed while the web application is running (e.g. via JMX).

     

    ๋ฒˆ์—ญ: ์บ์‹œ์— ๋ฐฐ์น˜๋  ์ •์  ๋ฆฌ์†Œ์Šค์˜ ์ตœ๋Œ€ ํฌ๊ธฐ์ž…๋‹ˆ๋‹ค. ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’์€ 512(512ํ‚ฌ๋กœ๋ฐ”์ดํŠธ)์ž…๋‹ˆ๋‹ค. ์ด ๊ฐ’์ด cacheMaxSize/20๋ณด๋‹ค ํฌ๋ฉด cacheMaxSize/20์œผ๋กœ ์ค„์–ด๋“ญ๋‹ˆ๋‹ค. ์ด ๊ฐ’์€ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰๋˜๋Š” ๋™์•ˆ(์˜ˆ: JMX๋ฅผ ํ†ตํ•ด) ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์Œ.. cacheObjectMaxSize ์—ญ์‹œ ์‹คํ–‰๋˜๋Š” ๋™์•ˆ์— ๋ณ€๊ฒฝ์ด ๊ฐ€๋Šฅ ํ•˜๋‹ค๊ณ  ํ•˜๋„ค์š”!

    cacheObjectMaxSize์™€ cacheMaxSize์˜ ๊ด€๊ณ„๋ฅผ ์ •๋ฆฌํ•ด๋ณด๋ฉด

    1. ๊ธฐ๋ณธ๊ฐ’
      1. cacheMaxSize: 10240 KB
      2. cacheObjectMaxSize 512 KB
    2. ์ตœ๋Œ€ ํฌ๊ธฐ
      1. cacheObjectMaxSize์˜ ์ตœ๋Œ€ ํฌ๊ธฐ๋Š” cacheMaxSize / 20์ด๊ณ  ๋งŒ์•ฝ cacheMaxSize / 20 ์‚ฌ์ด์ฆˆ๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ ์ž๋™์œผ๋กœ cacheMaxSize / 20 ์œผ๋กœ ์ค„์–ด๋“ ๋‹ค

    ๋ฌด์Šจ ์ฐจ์ด์ธ์ง€๋Š” ํ™•์‹คํžˆ ์™€๋‹ฟ์ง€๋Š” ์•Š๋„ค์š” :(

     

    context.xml ํŒŒ์ผ์ด ์—†๋Š” ๊ฒฝ์šฐ ์ƒ์„ฑ

    <?xml version="1.0" encoding="UTF-8"?>
    <Context>
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
        <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
        <Resources cachingAllowed="true" cacheMaxSize="100000"/>
    </Context>
    cacheMaxSize๋Š” ๊ฐ์ž ์„œ๋ฒ„ ์ƒํ™ฉ์— ๋งž๊ฒŒ ์„ค์ •ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค์•„

     

    ์ด์ƒ ํ†ฐ์บฃ์˜ ์บ์‹œ ์„ค์ • ๋ฐฉ๋ฒ•์„ ์ •๋ฆฌํ–ˆ์Šต๋‹ˆ๋‹ค :)

     

     

    ์ฐธ๊ณ 

    ๋„ค์ด๋ฒ„๋ธ”๋กœ๊ทธ